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
absolufy_imports-0.2.2.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for absolufy_imports-0.2.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e95c10943e3feaff9c34fa9c14ec31cec3c78207e0f21603665a6b5f0ba26e1 |
|
MD5 | 9a8804daca31f2ffe5753ee00ffd47f5 |
|
BLAKE2b-256 | 8548177f447eba04e9c9ab315450e7dcb8583e497ade37387daadc4ba5fc3a60 |