For shared rules, you can define them in a JSON file and load them using rules_from_config().
Supported rule types:
no_cyclesforbidden_dependencyforbidden_external_dependency
Example JSON structure:
{
"project_path": "src",
"rules": [
{
"name": "controllers must not use services directly",
"type": "forbidden_dependency",
"source": "**/controllers/**",
"target": "**/services/**"
},
{
"name": "source files have no cycles",
"type": "no_cycles"
}
]
}
from archunitpython import assert_passes, rules_from_config
def test_configured_architecture_rules():
for rule in rules_from_config("archunitpython.json"):
assert_passes(rule)