CI tool to detect indirect import
Project description
pyproject-indirect-import-detector
: Indirect import detector
Motivation
Indirect import is bad.
- The biggest reason is requirements are not protected by semantic versioning.
- Tests cannot check import-problem correctly.
- Virtual environment is not strictly synced with
pyproject.toml
norpoetry.lock
bypoetry
, so far. It is possible that you delete a dependency but it still remains in the virtual environment. This means, tests can accidentally pass. - FYI, indirect import is not allowed in rust/cargo.
Limitation
Currently, this tool only suuport pyproject.toml
using poetry
.
PEP 631 support is planed if python community agree this motivation and use this tool.
How to use
Install
poetry add --dev pyproject-indirect-import-detector
Note that this tool is intended to use in the virtual environment created by poetry install
. See also: Why only works in venv?
Usage
poetry run pyproject-indirect-import-detector -v
See also CI config, especially the job check-indirect-import
.
Configuration
You can configure by pyproject.toml
as the following:
[tool.pyproject-indirect-import-detector]
exclude_modules = [
"dataclasses", # If you use compat trick like https://github.com/PyCQA/isort/blob/5.8.0/isort/_future/__init__.py#L3-L7 .
"tests", # If your test suite make `tests` module importable and use it like https://github.com/andreoliwa/nitpick/blob/v0.26.0/tests/test_json.py#L6 .
"dummy_module_for_test", # If you use dummy modules in tests like https://github.com/PyCQA/isort/blob/5.8.0/tests/unit/example_crlf_file.py#L1-L2 .
]
FAQ
It failes with not reasonable errors.
Report an issue and let me know your case. The core logic is not yet well-tested with real packages. We need edge cases.
Why only works in venv?
This tool makes a correspondence from package names to module names.
This use importlib
and requires an environment that has all packages installed.
This tool is designed to be used in CI. So, runnable under poetry run
is enough.
Why installable with python >= 3.6
and runnable only in python >= 3.9
?
See the comment in pyproject.toml. I tried to make it runnable in old pythons, but the cost is high. This tool is designed to be used in CI. So, this restriction is reasonable.
How to develop
How to release
- Bump version, PR and merge.
git tag <version>
thengit push origin <version>
.- CI will pubish the package to PyPI: https://pypi.org/project/pyproject-indirect-import-detector/
Project details
Release history Release notifications | RSS feed
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
Hashes for pyproject-indirect-import-detector-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 245c9264240786f556ff7652d5c519bbffc423c1c39059b780e5b55d512bf9be |
|
MD5 | 010b3800165bb72ef1986f767083bd8c |
|
BLAKE2b-256 | 5213fed472dd0eead625b436cc92bac4f5bc29c1c3bf7c114bd545cf2efa6388 |
Hashes for pyproject_indirect_import_detector-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d177299f0154d44e79106f715a0b3f8e716cbb9d4f93ba808570833fa5ba911c |
|
MD5 | c467c704e56c52b4ed9f1ba91d92c628 |
|
BLAKE2b-256 | 4dfa6b0e6fa5a3ff44cc687c61f2d66b4389d04b6a1ba0d705c77d432bfd1afe |