Registry / devops / absolufy-imports

absolufy-imports

JSON →
library0.3.1pypypiunverified

A Python tool and pre-commit hook designed to automatically convert relative imports to absolute imports within a codebase. While functional, its author has indicated it is superseded by the more comprehensive `reorder-python-imports` library. Its current version is `0.3.1`, last released in January 2022.

pip install absolufy-imports
INSTALL
IMPORT
SIG · ABSOLUFY-IMPORTS
A
absolufy-imports
devopspythonv0.3.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

To use `absolufy-imports` via the command line, simply point it to the file(s) you wish to modify. It will perform the conversion in place.

# Example file: mypackage/myfile.py # from . import __version__ # from .submodule import some_function # To convert relative imports in a file: # Create a dummy file for demonstration with open('mypackage/myfile.py', 'w') as f: f.write('from . import __version__\n') f.write('from .submodule import some_function\n') import os import subprocess # Run absolufy-imports on the file print('Before conversion:') with open('mypackage/myfile.py', 'r') as f: print(f.read()) # Assuming 'mypackage' is at the root for absolute imports # The tool modifies the file in place subprocess.run(['absolufy-imports', 'mypackage/myfile.py'], check=True) print('\nAfter conversion:') with open('mypackage/myfile.py', 'r') as f: print(f.read()) # Clean up dummy file and directory os.remove('mypackage/myfile.py') os.rmdir('mypackage')
absolufy-imports --version
Debug
Known issues
deprecatedThe author of `absolufy-imports` states that it is superseded by `reorder-python-imports` (also by the same author) and recommends using the latter instead. `absolufy-imports` is functional but is not actively maintained for new features.
fix
Consider migrating to `reorder-python-imports` for broader import management capabilities.
affects: 0.3.1 and earlier
gotchaWhen using `absolufy-imports` (especially with a pre-commit hook), ensure you configure `--application-directories` correctly if your project uses non-standard layouts (e.g., a `src` directory). This helps the tool correctly identify the root of your package for absolute import resolution.
fix
For a project with a `src` directory, use `absolufy-imports --application-directories .:src` or configure your pre-commit hook accordingly.
affects: All versions
gotchaThis tool modifies files in-place. Always ensure you have appropriate version control or backups before running it across your codebase to prevent unintended changes.
fix
Commit your changes before running `absolufy-imports` or verify changes using a diff tool afterward. Using it as a pre-commit hook helps manage this within your workflow.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'absolufy_imports'
This error occurs when the 'absolufy-imports' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install absolufy-imports'.
absolufy-imports: command not found
This error occurs when the 'absolufy-imports' command-line tool is not available, possibly due to the package not being installed or the installation path not being in the system's PATH.
fix
Ensure the package is installed and the installation path is included in the system's PATH.
ImportError: cannot import name 'absolufy_imports' from 'absolufy_imports'
This error occurs when attempting to import 'absolufy_imports' incorrectly, possibly due to a circular import or incorrect module structure.
fix
Ensure that the import statement is correct and there are no circular imports in the codebase.
absolufy-imports not converting imports
The tool might not be correctly configured to identify your application's source directories, or the files it's processing don't match the expected package structure.
fix
Specify your application directories using the `--application-directories` flag (e.g., `absolufy-imports . --application-directories .:src`), ensuring it includes all relevant package roots. Also, verify that the files are part of a valid Python package (i.e., contain `__init__.py`).
pre-commit hook absolufy-imports failed
This generic pre-commit error indicates that the `absolufy-imports` hook exited with a non-zero status. This can be due to syntax errors in the Python files, an unsupported file structure, or an incorrect `rev` in your `.pre-commit-config.yaml`.
fix
First, fix any underlying Python syntax errors in your staged files. Then, check your `.pre-commit-config.yaml` to ensure the `rev` for `absolufy-imports` is correct (e.g., `v0.3.1`) and that the `id` is properly set. Run `pre-commit autoupdate` to get the latest working revision.
Upgrade
Version history
0.3.1latest on PyPI · released Jan 20, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
67 hits · last 30 days
node
50
OpenAI (training)
1
Resources
absolufy-imports — pip install absolufy-imports · libregistry