Skip to main content

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.

Metadata

Release files for abs2rel 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for abs2rel 1.1.0
File Size Uploaded
abs2rel-1.1.0.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for abs2rel 1.1.0
File Interpreter ABI Platform
abs2rel-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / abs2rel-1.1.0.tar.gz

Download URL abs2rel-1.1.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
62fba488bb495e373cf8884d70ea52469ba9106adc2052beee16a4356837dae3
BLAKE2b-256 checksum
How to use checksums
bbbda29951577d9cc64c5b3ea9424f7f400e8692c894c2761efd566c8c939823
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / abs2rel-1.1.0-py3-none-any.whl

Download URL abs2rel-1.1.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1df97db8152e896aa651ad82dc14d20688dbb1dd93cff76f29ef8448f5b83aa6
BLAKE2b-256 checksum
How to use checksums
ccb7fad554f7cd8285762be2972825bc93564b47cd6832a060e502576689c1da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page