Skip to content

Tach - a Python framework for your modular monorepo - cli with bash and terminal support 🌎 Open-source 🐍 Installable via pip 🦀 Written in rust 🔒 Maintain code quality 🔧 Works through static parsing of your code ⚡ Maintain productivity  ♾️ git pre-commit and VS Code extension 👨‍💻 built by Gauge

License

Notifications You must be signed in to change notification settings

gauge-sh/tach-python-modular-monorepo-framework-tool

Repository files navigation

Tach

downloads version license python ci pyright ruff

a Python tool to enforce modular design, written in Rust.

Docs

gauge-logo

Tach lets you define and enforce dependencies between Python modules in your project.

This enforces a decoupled, modular architecture, which makes maintenance and development easier. If a module tries to import from another module that is not listed as a dependency, tach will report an error.

Here's an example:

tach_demo

Tach is:

  • 🌎 Open source
  • 🐍 Installable via pip
  • 🔧 Able to be adopted incrementally
  • ⚡ Implemented with no runtime impact
  • ♾️ Interoperable with your existing systems (cli, hooks, ci, etc.)

Getting Started

Installation

pip install tach

Setup

Tach allows you to configure where you want to place module boundaries in your project.

You can do this interactively! From the root of your python project, run:

 tach mod
# Up/Down: Navigate  Enter: Mark/unmark module  Right: Expand  Left: Collapse  Ctrl + Up: Jump to parent
# Ctrl + s: Exit and save  Ctrl + c: Exit without saving  Ctrl + a: Mark/unmark all

Mark and unmark each module boundary you want to create with 'Enter' (or 'Ctrl + a' to mark all sibling modules). Common choices would be to mark all of your top-level Python source packages, or just a few packages which you want to isolate.

Once you have marked all the modules you want to enforce constraints between, run:

tach sync

This will create the main configuration file for your project, tach.yml, with the dependencies that currently exist between each module you've marked.

You can then see what Tach has found by viewing the tach.yml's contents:

cat tach.yml

NOTE: Your 'project root' directory (the directory containing your tach.yml) will implicitly be treated as a module boundary, and may show up in your dependency constraints as ''.

Enforcement

Tach comes with a simple cli command to enforce the boundaries that you just set up! From the root of your Python project, run:

tach check

You will see:

✅ All module dependencies validated!

You can validate that Tach is working by either commenting out an item in a depends_on key in tach.yml, or by adding an import between modules that didn't previously import from each other.

Give both a try and run tach check again. This will generate an error:

❌ path/file.py[LNO]: Cannot import 'path.other'. Tags ['scope:other'] cannot depend on ['scope:file']. 

Extras

If an error is generated that is an intended dependency, you can sync your actual dependencies with tach.yml:

tach sync

After running this command, tach check will always pass.

If your configuration is in a bad state, from the root of your python project you can run:

tach clean

This will wipe all the configuration generated and enforced by Tach.

Tach also supports:

More info in the docs. Tach logs anonymized usage statistics which are easily opted out of. If you have any feedback, we'd love to talk!

If you have any questions or run into any issues, let us know by either reaching out on Discord or submitting a Github Issue!

About

Tach - a Python framework for your modular monorepo - cli with bash and terminal support 🌎 Open-source 🐍 Installable via pip 🦀 Written in rust 🔒 Maintain code quality 🔧 Works through static parsing of your code ⚡ Maintain productivity  ♾️ git pre-commit and VS Code extension 👨‍💻 built by Gauge

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published