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
Built Distribution
File details
Details for the file abs_imports-0.2.1.tar.gz
.
File metadata
- Download URL: abs_imports-0.2.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa44cfe1d84c008ab1052cece54b912f12cdd5234ea502993ae4741dae1d435b |
|
MD5 | 30f3b58cc940a82f682dee241ef65339 |
|
BLAKE2b-256 | 1a534871898128bed1556ea73cc23baf32ee70368d937fc999651154546e1383 |
Provenance
File details
Details for the file abs_imports-0.2.1-py2.py3-none-any.whl
.
File metadata
- Download URL: abs_imports-0.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ded7a124df334c78b784c30fae8ad13147cd9c833c633b8ba163cdffe79e434b |
|
MD5 | 382e9b9830779e1d375c5cbf4d16b674 |
|
BLAKE2b-256 | 71b942b6d51be39ce3bdde99864a8afa07dd22fc4cac745b6fe1f8f8bd86c3f0 |