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
1.16k stars 36 forks source link

Add 'visibility' configuration #337

Closed emdoyle closed 2 months ago

emdoyle commented 2 months ago

Ref: #119

This adds visibility as a configuration option for modules. This value will determine which modules are allowed to depend on a given module (the inverse of depends_on). By default, this is set to ['*'], which means 'this module can be depended on by any other module'.

[[modules]]
path = 'tach.core'
depends_on = []
// DEFAULT: globally visible
visibility = ['*'] 

[[modules]]
path = 'tach.core'
depends_on = []
// ISOLATED: no other module may depend on this module
visibility = [] 

[[modules]]
path = 'tach.core'
depends_on = []
// PARTIALLY ISOLATED: only modules with paths starting with `tach.` may depend on this module
visibility = ['tach.*'] 

[[modules]]
path = 'tach.core'
depends_on = []
// PARTIALLY ISOLATED: only modules with paths starting with `tach.` or matching `utils` may depend on this module
visibility = ['tach.*', 'utils'] 

Errors are given when running tach check. Running tach sync will ignore the visibility settings, and sync depends_on as usual. Errors look like this:

❌ Module configuration error: 'tach.cli' cannot depend on 'tach.constants' because 'tach.cli' does not match its visibility: [].
Adjust 'visibility' for 'tach.constants' to include 'tach.cli', or remove the dependency.

❌ Module configuration error: 'tach.filesystem' cannot depend on 'tach.constants' because 'tach.filesystem' does not match its visibility: [].
Adjust 'visibility' for 'tach.constants' to include 'tach.filesystem', or remove the dependency.

❌ Module configuration error: 'tach.hooks' cannot depend on 'tach.constants' because 'tach.hooks' does not match its visibility: [].
Adjust 'visibility' for 'tach.constants' to include 'tach.hooks', or remove the dependency.