A python script that traverses a whole package turning local absolute imports into relative ones.
Project description
abs2rel
A python script that traverses a whole package turning local absolute imports into relative ones.
It can reduce substantialy the time needed to convert local absolute imports from a Python package into local relative imports. Additionally, because the conversion is automated, it is less error-prone than having someone make the changes manually.
This command only recognizes local absolute imports which are in the from ... import ...
format, where the from
and import
keywords are on the same line.
This script was originally tested on the nodezator app at commit be4c17f, managing to convert all 1685 existing absolute local imports across 270 python files into relative imports successfully, without needing any additional manual work.
If you want to try this yourself, just clone nodezator, checkout the mentioned commit and, inside the nodezator/nodezator folder, execute the abs2rel
command. Then, go up one folder level and launch the app with python -m nodezator
and you'll see that the local relative imports work properly, launching the app without problems.
Installation
pip install abs2rel
Usage
After installing, just go to your package top-level directory and execute the abs2rel
command. Before actually changing the files, the script presents the number of imports and files that are about to be changed and asks the user to confirm in order to proceed. Remember to make a backup of your package before executing this script, just in case.
License
abs2rel is dedicated to the public domain with The Unlicense.
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
File details
Details for the file abs2rel-1.1.0.tar.gz
.
File metadata
- Download URL: abs2rel-1.1.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62fba488bb495e373cf8884d70ea52469ba9106adc2052beee16a4356837dae3 |
|
MD5 | a1fa3406bdf9814c6a1e6eaf9235b839 |
|
BLAKE2b-256 | bbbda29951577d9cc64c5b3ea9424f7f400e8692c894c2761efd566c8c939823 |
File details
Details for the file abs2rel-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: abs2rel-1.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1df97db8152e896aa651ad82dc14d20688dbb1dd93cff76f29ef8448f5b83aa6 |
|
MD5 | f7ef0f83b8102cf324e411f82bd77cae |
|
BLAKE2b-256 | ccb7fad554f7cd8285762be2972825bc93564b47cd6832a060e502576689c1da |