A tool to automatically replace relative imports with absolute ones.
Project description
abs-imports
A pre-commit hook to automatically convert relative imports to absolute.
Installation
pip install abs-imports
Usage as a pre-commit hook
See pre-commit for instructions
Sample .pre-commit-config.yaml
:
- repo: https://github.com/MarcoGorelli/abs-imports
rev: v0.2.1
hooks:
- id: abs-imports
Command-line example
$ cat mypackage/myfile.py
from . import __version__
$ abs-imports mypackage/myfile.py
$ cat mypackage/myfile.py
from mypackage import __version__
If your package follows the popular ./src
layout, you can pass your application directories via --application-directories
, e.g.
$ cat src/mypackage/myfile.py
from . import __version__
$ abs-imports src/mypackage/myfile.py --application-directories src
$ cat src/mypackage/myfile.py
from mypackage import __version__
Multiple application directories should be comma-separated, e.g. --application-directories .:src
. This is the same as in reorder-python-imports.
See also
Check out pyupgrade, which I learned a lot from when writing this.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
abs_imports-0.2.1.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for abs_imports-0.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ded7a124df334c78b784c30fae8ad13147cd9c833c633b8ba163cdffe79e434b |
|
MD5 | 382e9b9830779e1d375c5cbf4d16b674 |
|
BLAKE2b-256 | 71b942b6d51be39ce3bdde99864a8afa07dd22fc4cac745b6fe1f8f8bd86c3f0 |