https://github.com/simonmacor/hexagonal-dependencies-tracker
Python Hexagonal Architecture Compliance Checker
https://github.com/simonmacor/hexagonal-dependencies-tracker
hexagonal-architecture python
Last synced: 3 days ago
JSON representation
Python Hexagonal Architecture Compliance Checker
- Host: GitHub
- URL: https://github.com/simonmacor/hexagonal-dependencies-tracker
- Owner: simonmacor
- License: mit
- Created: 2024-08-20T22:35:36.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-29T01:28:41.000Z (almost 2 years ago)
- Last Synced: 2025-02-21T19:45:29.445Z (over 1 year ago)
- Topics: hexagonal-architecture, python
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/simonmacor/py_hexagonal_dependencies_tracker/actions/workflows/ci.yml)
# Python Hexagonal Architecture Compliance Checker
## Overview
Hexagonal Architecture Compliance Checker is a Python script designed to enforce and verify compliance with hexagonal architecture principles in your Python projects. It checks whether the imports in your code adhere to the specified layer dependencies defined in a configuration file. The script can also handle exceptions where certain imports are allowed under specific conditions, generating warnings with explanations.
## Features
- Layer Dependency Verification: Ensures that modules only import from allowed layers.
- Customizable Rules: Define allowed imports and exceptions in a YAML configuration file.
- Warning for Allowed Violations: Generate warnings for exceptions where imports are allowed.
## Installation
You can install the Hexagonal Architecture Compliance Checker as a package using setup.py. Follow these steps:
1. Clone the Repository (if applicable):
``` bash
git clone git@github.com:simonmacor/py_hexagonal_dependencies_tracker.git
cd py_hexagonal_dependencies_tracker
```
2. Install the Package:
Navigate to the directory containing setup.py and run the following command to install the package and its dependencies:
```bash
pip install .
```
## Configuration
Create a YAML configuration file named hexagonal.yml (or another name of your choice) in your project directory. The configuration file should define the layers, dependencies, and any allowed violations.
### Example hexagonal.yml
```yaml
layers:
domain:
- "my_project/domain"
application:
- "my_project/application"
adapters:
- "my_project/adapters"
- "my_project/infrastructure"
ui:
- "my_project/ui"
- "my_project/web"
dependencies:
domain: []
application:
- "domain"
adapters:
- "application"
- "domain"
ui:
- "application"
allowed_violations:
- module: "os"
file: "my_project/domain/special_case.py"
reason: "os module is allowed here due to specific system interactions."
```
## Usage
Run the script from the command line, specifying the path to your YAML configuration file:
### Default Configuration File
If your configuration file is named hexagonal.yml and located in the same directory as the script, use:
```bash
python verify_architecture.py
```
### Custom Configuration File
To specify a different configuration file, use the -c or --config option:
```bash
python verify_architecture.py -c path/to/your_config.yml
```
## Testing
To run tests on the script, make sure you have unittest available. You can execute the tests by running:
``` bash
python -m unittest tests/test_verify_architecture.py
```
## Contributing
If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request. Contributions are welcome!
## License
This project is licensed under the MIT License. See the LICENSE file for details.