iabs2rel
pip install iabs2rel
A Python utility / library to convert absolute Python imports to relative
About
This package is purposed for conversion python code imports from absolute to relative. It is very useful in case of nested packages there it is preferable to use ..parent.file imports instead of root.package1.package2.package3.parent.file.
Advantages
- many parameters to control imports depth and code zones
- high performance
- detailed logging
- CLI allowed
Limitations
- only
from ... import ...imports are allowed; other imports will be not converted to relative - to use this package u need Python3.8 environment at least, but updating (target) code may be written in older Python
- u often need to specify proper
--python-pathpaths to resolve absolute imports
CLI
iabs2rel
usage: iabs2rel [-h] [--dry-run] [--python-path PYTHON_PATH [PYTHON_PATH ...]] [--allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...]] [--denied-paths DENIED_PATHS [DENIED_PATHS ...]]
[--loglevel {NO,ERROR,WARNING,INFO,DEBUG}] [--max-depth MAX_DEPTH]
sources [sources ...]
Replaces absolute file imports to relative in all sources
positional arguments:
sources paths to python files or directories with python files
optional arguments:
-h, --help show this help message and exit
--dry-run, -n Whether to run without performing file processing operations (default: False)
--python-path PYTHON_PATH [PYTHON_PATH ...], -p PYTHON_PATH [PYTHON_PATH ...]
PYTHONPATH elements to resolve absolute imports; if nothing set then only CWD will be used; absolute imports that cannot be resolved will not be converted to relative (default: )
--allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...], -a ALLOWED_PATHS [ALLOWED_PATHS ...]
allowed import destination files/folder; if nothing set then any destination is allowed; if absolute import points not to allowed location it will not be converted to relative (default: )
--denied-paths DENIED_PATHS [DENIED_PATHS ...], -e DENIED_PATHS [DENIED_PATHS ...]
forbidden import destination files/folder; if absolute import points to forbidden location (even allowed) it will not be converted to relative (default: )
--loglevel {NO,ERROR,WARNING,INFO,DEBUG}, -l {NO,ERROR,WARNING,INFO,DEBUG}
using loglevel (default: DEBUG)
--max-depth MAX_DEPTH, -d MAX_DEPTH
max relative import depth; 0 means only local imports to same package are allowed (start with 1 dot);1 means 0 + imports 1 level upper (start with 2 dots); higher values are available; values <0
disable any limits (default: 1)
iabs2rel-file
usage: iabs2rel-file [-h] [--destination DESTINATION] [--python-path PYTHON_PATH [PYTHON_PATH ...]] [--allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...]] [--denied-paths DENIED_PATHS [DENIED_PATHS ...]]
[--loglevel {NO,ERROR,WARNING,INFO,DEBUG}] [--max-depth MAX_DEPTH]
source
Replaces absolute file imports to relative
positional arguments:
source python file path to replace imports
optional arguments:
-h, --help show this help message and exit
--destination DESTINATION, -o DESTINATION
destination file; empty means to print to stdout (default: None)
--python-path PYTHON_PATH [PYTHON_PATH ...], -p PYTHON_PATH [PYTHON_PATH ...]
PYTHONPATH elements to resolve absolute imports; if nothing set then only CWD will be used; absolute imports that cannot be resolved will not be converted to relative (default: )
--allowed-paths ALLOWED_PATHS [ALLOWED_PATHS ...], -a ALLOWED_PATHS [ALLOWED_PATHS ...]
allowed import destination files/folder; if nothing set then any destination is allowed; if absolute import points not to allowed location it will not be converted to relative (default: )
--denied-paths DENIED_PATHS [DENIED_PATHS ...], -e DENIED_PATHS [DENIED_PATHS ...]
forbidden import destination files/folder; if absolute import points to forbidden location (even allowed) it will not be converted to relative (default: )
--loglevel {NO,ERROR,WARNING,INFO,DEBUG}, -l {NO,ERROR,WARNING,INFO,DEBUG}
using loglevel (default: DEBUG)
--max-depth MAX_DEPTH, -d MAX_DEPTH
max relative import depth; 0 means only local imports to same package are allowed (start with 1 dot);1 means 0 + imports 1 level upper (start with 2 dots); higher values are available; values <0
disable any limits (default: 1)
Metadata
Release files for iabs2rel 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iabs2rel-0.1.0.tar.gz | 11.8 kB | Without provenance | Details for iabs2rel-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iabs2rel-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for iabs2rel-0.1.0-py3-none-any.whl |
Total release size: 27.6 kB
Release files / iabs2rel-0.1.0.tar.gz
| Download URL | iabs2rel-0.1.0.tar.gz |
|---|---|
| Size | 11.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6f5486bb29b352e329a3926e28cedafee65d990641110df12d93bc02dca4c2a
|
|
BLAKE2b-256 checksum How to use checksums |
41ed62d4b25bc181aa855425ffe1bb7db0984809f1c2fc8d16630bb29b413b2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.8.17
|
Release files / iabs2rel-0.1.0-py3-none-any.whl
| Download URL | iabs2rel-0.1.0-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
039f1241415d33eeea16aa3e49db1dab450cac91feff236dbc246a12376f2ad2
|
|
BLAKE2b-256 checksum How to use checksums |
b450e5ad1b11d620fb20776b1dc3233932a6d765c79b3bce8c1b50f215ac813e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.8.17
|
Security for iabs2rel 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.