gauge-sh / tach

A Python tool to enforce dependencies, using modular architecture 🌎 Open source 🐍 Installable via pip πŸ”§ Able to be adopted incrementally - ⚑ Implemented with no runtime impact ♾️ Interoperable with your existing systems πŸ¦€ Written in rust
https://gauge.sh
MIT License
1k stars 35 forks source link

Support multiple source roots and namespace packages #208

Closed emdoyle closed 1 month ago

emdoyle commented 1 month ago

Fixing #203 and #192

NOTE: The base of this branch will be updated after #207 merges

This PR essentially changes source_root from a single path to a list of paths (source_roots). This change propagates through most of the codebase, but the semantic change is straightforward.

Tach will now search for project imports in all the configured source roots when translating module paths to filesystem paths (and vice versa).

This unlocks support for 'monorepo' use cases, since a user can now mark all applicable package source roots and validate the expected dependencies.

This PR also drops certain expectations around finding __init__.py in Python packages, which means namespace packages are also supported. This is particularly useful when building many subsidiary packages which are distributed under a common namespace.

Example: image

caelean commented 1 month ago

Looks great/working for me when I test! Some nice-to-haves would mainly be around the ergonomics of mod - unmarking modules that don't have a source root, not allowing nested source roots, not allowing modules with the same relative path under different source roots, etc.

Definitely all nonblocking tho; stoked to see this get out!

malcolmgreaves commented 1 month ago

This is awesome! Just tried this today on my own project and it worked so well! Thank you so much :) ❀️