A minimal library for smart Python imports with automatic path resolution
Project description
aimport
A minimal library for python: Adding support for smart imports with automatic path resolution.
Usage
import aimport
This automatically adds relevant directories to sys.path based on __aimport__ anchor files found in the directory tree.
Features
- Smart path resolution: Automatically discovers project roots using
__aimport__anchor files - Anchor file content support:
__aimport__files can contain paths that will be used instead of the file location - Fallback support: Falls back to
__init__.pyfiles when no__aimport__files are found - Priority ordering: BREAKING CHANGE v2.0.0: New paths are now prepended to
sys.pathinstead of appended, giving them higher import priority - Duplicate prevention: Avoids adding duplicate paths to
sys.path - Automatic execution: Works immediately upon import
Breaking Changes in v2.0.0
⚠️ Import Priority Change: Starting with v2.0.0, discovered paths are prepended to sys.path instead of appended. This means modules in aimport-discovered directories will take precedence over existing sys.path entries. This change ensures that project-local modules are found before system or virtual environment modules.
How It Works
- Anchor File Discovery: Searches upward from the starting directory for
__aimport__files - Content Processing: If an
__aimport__file contains a valid path, that path is used; otherwise the file's directory is used - Fallback Mechanism: If no
__aimport__files are found, falls back to searching for__init__.pyfiles - Path Priority: All discovered paths are added to the beginning of
sys.pathfor higher import priority
Testing
The project includes comprehensive unit tests using pytest:
# Install development dependencies
uv sync --dev
# Run all tests
./test.sh
# Or run pytest directly
uv run pytest tests/ -v
Test Coverage
- 23 comprehensive test cases
- Full coverage of all functions and edge cases
- Integration tests for complex directory structures
- Behavior-focused testing (not implementation details)
Development
# Build distribution
python setup.py sdist
# Upload to PyPI
twine upload dist/*
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aimport-2.0.0.tar.gz.
File metadata
- Download URL: aimport-2.0.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8199eb5ea117a73820191d2b6f080afa9a4116fa73ff7c01938af17b54fae055
|
|
| MD5 |
7c08a2dbe767f8752153267a592a78f5
|
|
| BLAKE2b-256 |
085120644c973527474ba294a890cbdd875dd14c012091008344f4b1ef85b915
|
File details
Details for the file aimport-2.0.0-py3-none-any.whl.
File metadata
- Download URL: aimport-2.0.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9376a168966d8f91f85e3a7e695a357132a5d95bfc9b019c0fad0588fa99332b
|
|
| MD5 |
9b6ba4a3482d2c3839364bf50b8875c8
|
|
| BLAKE2b-256 |
33daee7dad5e1283b00d69825ccbf3ef6b94881b9ae58bb88fc7c4b384eb63fe
|