Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abs2rel-1.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

abs2rel-1.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for abs2rel-1.1.0.tar.gz
Algorithm Hash digest
SHA256 62fba488bb495e373cf8884d70ea52469ba9106adc2052beee16a4356837dae3
MD5 a1fa3406bdf9814c6a1e6eaf9235b839
BLAKE2b-256 bbbda29951577d9cc64c5b3ea9424f7f400e8692c894c2761efd566c8c939823

See more details on using hashes here.

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

Hashes for abs2rel-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1df97db8152e896aa651ad82dc14d20688dbb1dd93cff76f29ef8448f5b83aa6
MD5 f7ef0f83b8102cf324e411f82bd77cae
BLAKE2b-256 ccb7fad554f7cd8285762be2972825bc93564b47cd6832a060e502576689c1da

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page