https://github.com/zmievsa/refaci
https://github.com/zmievsa/refaci
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/zmievsa/refaci
- Owner: zmievsa
- License: mit
- Created: 2023-05-27T11:29:31.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-28T15:29:06.000Z (over 2 years ago)
- Last Synced: 2025-02-07T15:45:25.432Z (over 1 year ago)
- Language: Python
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# refaci
A toolbox for changing imports in enormous codebases after a large refactoring.
---
## Installation
```bash
pip install refaci
```
## Guide
```python
import json
from pathlib import Path
from refaci.refactor import ContentsRegex, FilePathRegex, refactor
{
"moved": {
"old_package.worker": {
"DEAD_MESSAGE_TTL": { # Symbol that we changed
"path": "new_package.worker",
"alias": "DEAD_MESSAGE_TTL"
},
"RETRY_TIME": {
"path": "new_package.worker",
"alias": "NEW_RETRY_TIME_NAME"
}
},
},
"new": { # These imports will be added to all modules automatically
"b64_decode_url_params": "new_package.pagination",
"PaginationToken": "new_package.pagination"
}
}
replacements = {
FilePathRegex(r""): (
("internal_config=", "internal_settings="),
("= get_logger", "= getLogger"),
),
FilePathRegex(r"api/app.py"): [
("LogicError", "BusinessLogicError"),
],
ContentsRegex(r"class .+\(.+Controller\)"): (
("super().get(", "self.client.get("),
),
FilePathRegex(r"tests/"): [
["Response(", "make_response("],
],
}
refactor(Path(input("Path to your service:")), import_replacements["moved"], import_replacements["new"], replacements)
```