Code Monkey home page Code Monkey logo

smusali / tach Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gauge-sh/tach

0.0 0.0 0.0 20.59 MB

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

Home Page: https://gauge.sh

License: MIT License

Python 77.92% Rust 21.22% Makefile 0.86%

tach's Introduction

Tach

downloads version license python ci pyright ruff

a Python tool to enforce dependencies, written in Rust. Inspired by modular monolithic architecture.

Docs

Discord

gauge-logo

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

Here's an example:

tach_demo

If a module tries to import from another module that is not listed as a dependency, Tach can prevent it.

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 - 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 each module boundary with 'Enter'. You can mark all of your top-level Python source packages, or just a few which you want to isolate.

If your Python code lives below your project root, mark your Python source root using the 's' key.

This will create the config file for your project, tach.yml.

Once you've marked all the modules you want to enforce dependencies between, run:

tach sync

Dependencies that exist between each module you've marked will be written to tach.yml.

Check out what Tach has found!

cat tach.yml | less

Note: Your source root directory will implicitly be treated as a module boundary, and can show up as <root>.

Enforcement

Tach comes with a 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:

  1. Commenting out an item in a depends_on key in tach.yml
  2. 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:

❌ tach/check.py[L8]: Cannot import 'tach.filesystem'. Tag 'tach' cannot depend on 'tach.filesystem'. 

Each error indicates an import which violates your dependencies. If your terminal supports hyperlinks, click on the file path to go directly to the error.

When an error is detected, tach check will exit with a non-zero code. It can be easily integrated with CI/CD, Pre-commit hooks, and VS Code, and more!

Extras

Visualize your dependency graph.

tach show

Tach will generate a graph of your dependencies. Here's what this looks like for Tach itself:

tach show

Note that this graph is generated remotely based on the contents of your tach.yml.

You can view the dependencies and usages for a given path:

tach report my_package/
# OR
tach report my_module.py

e.g.:

> tach report python/tach/filesystem
[Dependencies of 'python/tach/filesystem']
python/tach/filesystem/install.py[L6]: Import 'tach.hooks.build_pre_commit_hook_content'
python/tach/filesystem/project.py[L5]: Import 'tach.constants.CONFIG_FILE_NAME'
...
-------------------------------
[Usages of 'python/tach/filesystem']
python/tach/cache/access.py[L8]: Import 'tach.filesystem.find_project_config_root'
python/tach/cache/setup.py[L7]: Import 'tach.filesystem.find_project_config_root'
...

Tach also supports:

More info in the docs. Tach logs anonymized usage statistics which can be 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!


Contributors

tach's People

Contributors

emdoyle avatar caelean avatar max-muoto avatar clin1234 avatar dhananjaypai08 avatar anmolm96 avatar dependabot[bot] avatar tiluckdave avatar nikhil5642 avatar ar090 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.