I've been searching for a library or tool to test my Django project architecture, check the dependencies, layers, etc. like Arch Unit for Java. But until now, I didn't find anything. I don't even know if it's viable doing these kinds of tests in Python/Django projects. I know that Django itself already checks for cyclic dependencies.
Check out what you can find under Python complexity metrics.
A tool called Wily may be of use. However, what counts as good practices will be very different for Java and Python.
If you are looking for something simple yet powerful then I would recommend to explore pytestarch
You can find the install instructions here: https://pypi.org/project/pytestarch/
Also the official documentation can be referred from here: https://zyskarch.github.io/pytestarch/1.5.0/features/general/
Hope this help!
The closest that I know of is https://github.com/seddonym/import-linter
It's capable only of linting - as the name suggests - imports between modules so it has far fewer capabilities than ArchUnit, but I used it with great success in several clean/hexagonal architecture projects.
To use it to the full extent you need to wisely split your projects into modules so that the import statements "follow" (or rather "match") your designated architecture.
Some example of the rules that I often use:
[importlinter:contract:8]
name = Modules .core cannot depend on shared infrastructure
type = forbidden
source_modules =
src.services.service1.modules.module1.core
src.services.service2.modules.module1.core
src.services.service2.modules.module2.core
forbidden_modules =
src.shared.infrastructure
[importlinter:contract:3]
name = modules inside services shall be independent
type = independence
modules =
src.services.service1.modules.module1
src.services.service2.modules.module1
src.services.service2.modules.module2
There is also pytest-archon. Its syntax is simpler than import-linter's and uses pytest instead of separate config files.
© 2022 - 2024 — McMap. All rights reserved.