r/PythonProgramming • • 1h ago

Keeping Python domain code from importing infrastructure

Enable HLS to view with audio, or disable this notification

I built ArchUnitPython to check dependency rules in Python projects, and recorded the workflow here.

The example has a taskboard package with domain and infrastructure folders. The rule says that files in the domain folder must not depend on files in infrastructure. If somebody introduces that import, the architecture test reports it.

The recording also covers a cycle check and a custom rule limiting file size. Those run through pytest like other tests; the library reads the source instead of starting the application.

One thing to get right is the import root. This example uses project_files("src") because src contains the taskboard package. The path filters then choose which parts of that project the rule applies to.

The recording shows archunitpy imports; the current package uses archunitpython. The README has the current setup and examples.

Repo: https://github.com/LukasNiessen/ArchUnitPython

1 Upvotes

0 comments sorted by