A checker to restrict the tangling of import interdependencies
Project description
Orbie
A checker to guide the web of Python code in strictly architected projects and restrict tangling up of code.
Orbie is named after the orb-weaver spider which can make complex web patterns.
Example Use Case
Imagine you have a single Python project with several subprojects being shipped as part of it but you want to have some level of isolation between the modules. (Yes, you could split it into several projects to enforce that but maybe you cannot for some reason). Or you want to strictly control the import mapping between the different parts of your project.
Why might you not want this? Having a tangled web of interdependencies may be undesireable as it increases the complexity of the project. By trimming and restricting these interdependencies, the complexity can be reduced and options open up such as optimising the ci-cd to test only the changed subprojects without fear of missing re-testing unrelated but affected components.
Take this Python project structure below as an example.
src/
└── example
├── example_a
│ ├── example_a.py
│ ├── __init__.py
│ ├── nephews
│ │ └── nephew.py
│ └── sibling.py
├── example_b
│ ├── example_b.py
│ └── __init__.py
├── example_c
│ ├── example_c.py
│ └── __init__.py
├── example_shared
│ ├── __init__.py
│ └── shared.py
└── __init__.py
We may not want example_a.py referencing anything from example_b.py or
example_c.py.
This can be enforced with some simple code review but that may fail if the reviewer does not have enough coffee. We need a more complicated solution for the sake of being programmers building tools for programmers.
Orbie is a tool that exists to enforce isolation (so it can be enforced via automation). It detects imports that reference other modules within the same project space but that are cousins or ancestors.
How It Works
Orbie uses importlab to statically
parse the imports dependency tree and filters external dependencies and nested
dependencies to find dependencies that pull from parent paths within the same
Python package/project. If the number of these exceed zero, the script will exit
with error code 1.
Installation
TODO.
Usage
$ pdm run orbie --help
usage: orbie [-h]
[--exception EXCEPTIONS]
[--no-ignore-siblings]
[--no-ignore-venv]
[--project-root PROJECT_ROOT]
[-V PYTHON_VERSION]
[-P PYTHONPATH]
input
positional arguments:
input Input file
options:
-h, --help show this help message and exit
--exception EXCEPTIONS
Adds an exception for a module path or directory path
--no-ignore-siblings Toggle to not ignore tangled files within the same
parent directory
--no-ignore-venv Toggle to not ignore tangled files found in .venv
--project-root PROJECT_ROOT
Base project path to find tangled files within (default:
./)
-V PYTHON_VERSION, --python_version PYTHON_VERSION
Python version of target code, e.g. "2.7"
-P PYTHONPATH, --pythonpath PYTHONPATH
Directories for reading dependencies - a list of paths
separated by ":".
Example:
cd example
pdm install
orbie src/example/example_one.py
Usage: Exceptions
Of course, restricting interdependencies to 0 typically makes no sense. The more realistic use case of Orbie is to only allow select interdependencies that meet the architecture of the project. One example might be only allowing modules in a specific shared space from being imported (thus creating a clear structure around the interdependencies).
These exceptional import paths can be specified with --exceptions.
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 orbie-0.1.2.tar.gz.
File metadata
- Download URL: orbie-0.1.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.15.4 CPython/3.11.0 Linux/6.9.8-200.fc40.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69972d78186ef6524294fd223ddc52962a834ea87be286b1b1137f714f0bb678
|
|
| MD5 |
c212ebb976cf96137bba92c5dcceea71
|
|
| BLAKE2b-256 |
9e8924fe3774275a99980ec9ddf00837a926f700d7b5b84ddda0c50497a9d386
|
File details
Details for the file orbie-0.1.2-py3-none-any.whl.
File metadata
- Download URL: orbie-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.15.4 CPython/3.11.0 Linux/6.9.8-200.fc40.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35a4af603bf3f3b149d50dc40fdfdbc33d7aa5ce782160b98cf9a4e54e8e259c
|
|
| MD5 |
430e19d4d6d95b88c133edc76f4cc00c
|
|
| BLAKE2b-256 |
54a1ca8b74f90d9bb7a6851e1e6f4dc1a1e04b6389ed7ebf4388870e81a11e5f
|