Skip to main content

A tool to enforce architectural patterns in python projects

Project description

Deply

Deply is a standalone Python tool for enforcing architectural patterns and dependencies in large python projects. By analyzing code structure and dependencies, this tool ensures that architectural rules are followed, promoting cleaner, more maintainable, and modular codebases.

Inspired by https://github.com/qossmic/deptrac

Features

  • Layer-Based Analysis: Define project layers and restrict their dependencies to enforce modularity.
  • Dynamic Layer Configuration: Easily configure collectors for each layer using file patterns and class inheritance.
  • Cross-Layer Dependency Rules (TODO): Specify rules to disallow certain layers from accessing others.
  • Extensible and Configurable: Customize layers and rules for any python project setup.

Installation

To install Deply, use pip:

pip install deply

Configuration

Before running the tool, create a configuration file (config.yaml or similar) that specifies the rules and target files to enforce.

Example Configuration (config.example.yaml)

layers:
  - name: models
    collectors:
      - type: class_inherits
        base_class: "django.db.models.Model"

  - name: services
    collectors:
      - type: file_regex
        regex: "^.*/providers.py$"

  - name: views
    collectors:
      - type: file_regex
        regex: ".*/views_api.py"

ruleset:
  views:
    disallow:
      - models  # Disallows direct access to models in views

Usage

Run the tool from the command line by specifying the project root directory and configuration file:

python deply.py --project_root='/path/to/your_project' --config=config.example.yaml

Arguments

  • --project_root: The path to the root of the project where apps are located.
  • --config: Path to the configuration file that defines the rules and target files.

Sample Output

If violations are found, the tool will output a summary of architectural violations grouped by app, along with details of each violation, such as the file, line number, and violation message.

/path/to/your_project/your_project/app1/views_api.py:74 - Layer 'views' is not allowed to depend on layer 'models'

Running Tests

To test the tool, use unittest:

python -m unittest discover tests

License

See the LICENSE file for details.

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

deply-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

deply-0.1.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file deply-0.1.0.tar.gz.

File metadata

  • Download URL: deply-0.1.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for deply-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e48166e32c0641fddecee19046200376123a196eb32b3c1d3f765173190307f4
MD5 c4ad112bb95d470881752bfbc7bb486f
BLAKE2b-256 bc86185b5d0f714874c53f13611a8388848616898c22bd56aca5f8af1a2ec175

See more details on using hashes here.

File details

Details for the file deply-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: deply-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for deply-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0efb72a91ef804f81a49d07316fe80b6c241535408a14ed39339466380795cd8
MD5 3e072b15e1981b9ba11ed7ec505aaf2c
BLAKE2b-256 daf029d4de2ed4994e3f8d005f96ab47494fba1eb30f71fbc4157214c1a56ace

See more details on using hashes here.

Supported by

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