A tool to automatically replace relative imports with absolute ones.
Project description
absolufy-imports
A tool and pre-commit hook to automatically convert relative imports to absolute.
Installation
pip install absolufy-imports
Usage as a pre-commit hook
See pre-commit for instructions
Sample .pre-commit-config.yaml
:
- repo: https://github.com/MarcoGorelli/absolufy-imports
rev: v0.2.2
hooks:
- id: absolufy-imports
Command-line example
$ cat mypackage/myfile.py
from . import __version__
$ absolufy-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__
$ absolufy-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 absolufy_imports-0.2.2.tar.gz
.
File metadata
- Download URL: absolufy_imports-0.2.2.tar.gz
- Upload date:
- Size: 4.1 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 | 7c97d0f8ab9f7455b52b18827f357ba1141f89713ca045fc05b41d0394b8a7c0 |
|
MD5 | e88a6e8b9f73ec20903f6b95c4f3cc3b |
|
BLAKE2b-256 | ec492f6f9e16f1dbf7a192186b540457825e226d73fafea91d7e78e6319581ce |
File details
Details for the file absolufy_imports-0.2.2-py2.py3-none-any.whl
.
File metadata
- Download URL: absolufy_imports-0.2.2-py2.py3-none-any.whl
- Upload date:
- Size: 5.4 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 | 0e95c10943e3feaff9c34fa9c14ec31cec3c78207e0f21603665a6b5f0ba26e1 |
|
MD5 | 9a8804daca31f2ffe5753ee00ffd47f5 |
|
BLAKE2b-256 | 8548177f447eba04e9c9ab315450e7dcb8583e497ade37387daadc4ba5fc3a60 |