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.1.3
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-separate, e.g. --application-directories .,src
.
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.1.3.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for abs_imports-0.1.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee89e31bfef2881093893ff91732f06c55a6e8f09cadb9a966292b5721924c74 |
|
MD5 | 18cd1f5b12152e7a69cc64309ac26b3a |
|
BLAKE2b-256 | 8cd95a387b447259b1f435c6208aa2e883d03d55676aab01f2334a1e2653e14a |