seddonym / import-linter

Import Linter allows you to define and enforce rules for the internal and external imports within your Python project.
https://import-linter.readthedocs.io/
BSD 2-Clause "Simplified" License
664 stars 45 forks source link

Modular contracts #221

Open sbrugman opened 6 months ago

sbrugman commented 6 months ago

Closes https://github.com/seddonym/import-linter/issues/133

The implementation makes use of the multiple sibling modules checks of the layers contract.

For each submodule of the provided module, we squash the (copy of) the graph.

For every dependency that would be illegal by find_illegal_dependencies_for_layers, we check if there is a path in the reverse direction by find_shortest_chains. If so, then this violates the modular contract.

Implementation deviates from the issue as it considers the full depth of the tree (the user can provide submodules). Does this make sense?

Uses functionality from https://github.com/seddonym/import-linter/pull/220 that we can import if merged.

seddonym commented 6 months ago

Checking in on this. It's looking possible that my workplace will need something along these lines so I'm likely to have capacity to work on it if time is tight for you.

Something that came up in discussion, the term 'modular' is perhaps overloaded. I'm considering calling this kind of contract 'acyclic' instead. Any thoughts?

sbrugman commented 6 months ago

Feel free to take any of the PRs and continue. Time is tight, and it would be amazing to have these as collaborative features.