Tools: I built a small CLI tool to convert relative imports to absolute imports during a large refactoring
Source: Dev.to
While refactoring a large Python project, I ran into an issue — the project had a lot of deeply nested relative imports (from ..module import x). The team decided to standardize everything to absolute imports, and here was the issue: manually updating them was very tedious, especially across many levels of relative imports.
So I wrote a small CLI tool that converts relative imports to absolute ones. The tool: It’s lightweight and dependency-free. Nothing fancy — just a utility that solved a real problem for me and I thought it might be useful for some people.
If anyone is going through a similar refactor, feel free to check it out on github:
github
and you can install it using pip also.
I know it's very minimal, but I would appreciate feedback or suggestions. Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse - Traverses the project directory
- Detects relative imports of type (from ..A import B)
- Converts them to absolute imports based on a given root package