Skip to main content

relativize-imports

badge

Automatically convert python absolute imports to relative.

Inspired and adapted from MarcoGorelli/absolufy-imports.

Installation

$ pip install --upgrade relativize-imports

Usage as a pre-commit hook

See pre-commit for instructions

Sample .pre-commit-config.yaml:

-   repo: https://github.com/reallyliri/relativize-imports
    rev: v0.0.6
    hooks:
    -   id: relativize-imports

Or with args:

-   repo: https://github.com/reallyliri/relativize-imports
    rev: v0.0.6
    hooks:
    -   id: relativize-imports
        args:
          - svc/src
          - automation/tests/source

Usage

relativize-imports [path/to/dir/or/file.py ...]

Provide zero or more paths to relativize.

Files are assumed to be relative to the cwd. Directories are assumed as relativization root and the tool will format all python files under them, in any depth.

If no args are provided, the tool will run in the cwd and address it as the relativization root.

Config

The tool will read any config set in tox.ini in a root directory.

If you want to exclude any files from relativization (i.e entrypoints), you can add them to config:

[relativize-imports]
ignore = src/main.py,test

Command-line example

$ relativize-imports
$ relativize-imports src
$ relativize-imports mypackage/myfile.py
- from mypackage import __version__
+ from . import __version__

Build and Publish

rm -rf dist
python setup.py bdist_wheel 
twine upload dist/*

Metadata

Release files for relativize-imports 0.0.6

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

Built distribution (wheel)

Table of built distributions (wheels) for relativize-imports 0.0.6
File Interpreter ABI Platform Actions
relativize_imports-0.0.6-py2.py3-none-any.whl Python 2, Python 3 none any Details for relativize_imports-0.0.6-py2.py3-none-any.whl

Release files / relativize_imports-0.0.6-py2.py3-none-any.whl

Download URL relativize_imports-0.0.6-py2.py3-none-any.whl
Size 4.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7ee0e37d05ab5b4d0f201416ba9d4c8c49f481b01c3b5f09573f83a772d9b7cb
BLAKE2b-256 checksum
How to use checksums
0066038ea91972b450e5c2b1cd8dccdf7b53beaebe65cd9f39a2974e48bdbb99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.9

Security for relativize-imports 0.0.6

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.

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