Skip to main content

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

orbie-0.1.3.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

orbie-0.1.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file orbie-0.1.3.tar.gz.

File metadata

  • Download URL: orbie-0.1.3.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

Hashes for orbie-0.1.3.tar.gz
Algorithm Hash digest
SHA256 64ef703d5885af57bedea1694b7c09c7db3d234a616457bb353d5c7afcbc0a1b
MD5 7565b9990d8cb59d91a5ed3da5dae596
BLAKE2b-256 301002154127544166dca22e4520550b472b3ad7a36a653cac41359607dee54d

See more details on using hashes here.

File details

Details for the file orbie-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: orbie-0.1.3-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

Hashes for orbie-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f44992fe4ac70b572703749b1c8e81f1e12fa8a7891ee77ee3b538c3f5b86b2f
MD5 aae5debd104cf1f25df677c7a4140b42
BLAKE2b-256 530879d00fe40a34b6b4ec4c53ae5d214c01ca54af3197994fe8080891900216

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page