Β Β Β Β
An utility for adding new import paths to make your relative
import
work without hassle.
pip install importmonkey
Here is your repository:
ββ src
β ββ project
β ββ __init__.py
β ββ module.py
ββ test
ββ test.py
test.py can't find module.py:
ModuleNotFoundError: No module named 'module'
ImportError: attempted relative import with no known parent package
SystemError: Parent module '' not loaded, cannot perform relative import
importmonkey will fix that:
import importmonkey # In test.py
importmonkey.add_path("../src")
import project
Expand
help(importmonkey.add_path) # Or look at the source.
To protest the copyright landscape, I chose The Unlicense. If you need a different license, just ask.
- Install for dev stuff:
importmonkey$ pip install -e ".[dev]" # In a venv
- Linting:
importmonkey$ python -m ruff check .
- Testing:
importmonkey$ python test/run_test_suite.py
- Releasing:
# Remember: increment __version__ in __init__.py
# Remember: .pypirc file is needed.
# Remember: run tests
# Remember: run ruff
importmonkey$ python -m build --wheel
importmonkey$ rm -rf build/ && rm -rf src/importmonkey.egg-info/
importmonkey$ python -m twine check dist/*
importmonkey$ python -m twine upload dist/*
importmonkey$ rm -rf dist/