directly import everything from where it is defined
Project description
Managing imports is difficult when the project grows in size. Functions and classes gets moved or renamed.
canonical-imports follows your imports and finds out where the things you are importing are actually defined.
It can change your imports which makes your code cleaner and maybe even faster.
Installation
This project is currently only available for insiders, which mean that you can get access to it if you sponsor me. You should then have access to this repository.
You can install it with pip and the github url.
pip install git+ssh://git@github.com/15r10nk-insiders/canonical-imports.git@insider
Key Features
- follow imports to their definition and replace them.
- options to prevent the following of some types of imports (from public to private modules).
I will show you what it does with the following example:
# m/a.py
from ._core import helper
# m/_core.py
from ._utils import helper
# m/_utils.py
def helper():
print("some help")
helper was moved from _core to _utils
canonical-imports -w m/a.py
changes m/a.py to:
# m/a.py
from ._utils import helper
Usage
You can use canonical-imports from the command line to fix some files.
canonical-imports my_package/something.py
Use canonical-imports --help for more options.
Options
canonical-imports follows all imports by default. --no can be used to prevent certain types of import changes.
--no public-privateprevents changing public imports into private imports like in the following:-from package.module import Thing +from package.module._submodule import Thing
--no into-initprevents following imports into__init__.pyfiles. Example:# m/__init__.py ... # m/a.py from .b import f # <-- change to: from .q import f # m/b.py from .q import f # prevent changing to: from .q.c import f # m/q/__init__.py from .c import f # m/q/c.py def f(): pass
This rule does nothing if the import chain leaves the packagem.qagain (iffwould be defined another packagem.xfor example). This option might be useful if you do not use private module paths (with leading_).
Issues
If you encounter any problems, please report an issue along with a detailed description.
License
Distributed under the terms of the MIT license, "canonical-imports" is free and open source software.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file canonical_imports-0.4.0.tar.gz.
File metadata
- Download URL: canonical_imports-0.4.0.tar.gz
- Upload date:
- Size: 74.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69b4374bd5f3035572790bda1d9849152677b20070d19ff1667981fefa61b253
|
|
| MD5 |
5aaeeb154dcc412107997ec1bd13dd86
|
|
| BLAKE2b-256 |
500289329d3112f6398b439ef4b7e90c63838a013c2578ff7d710a07bf48841e
|
File details
Details for the file canonical_imports-0.4.0-py3-none-any.whl.
File metadata
- Download URL: canonical_imports-0.4.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17908c0012338d0d291d7f7bcb4aa27102eeaa0a9bfa6bd8ae2f029766b978bf
|
|
| MD5 |
b25c80714f74c6a50fa61883a12e0a2e
|
|
| BLAKE2b-256 |
4cfa2015d947ba987a3b8ec44da5582842615d27edb5132e60d42dcdf8174098
|