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.01k stars 35 forks source link

tach report: ValueError: Encountered invalid filepath: "" #274

Closed h0uter closed 3 weeks ago

h0uter commented 3 weeks ago

Every folder I run tach report for I get this error.


❯ tach report src_repos/project-a
Traceback (most recent call last):
  File "/Users/wjmeijer/Repositories/spice/.venv/bin/tach", line 8, in <module>
    sys.exit(start())
             ^^^^^^^
  File "/Users/wjmeijer/Repositories/spice/.venv/lib/python3.12/site-packages/tach/start.py", line 10, in start
    main()
  File "/Users/wjmeijer/Repositories/spice/.venv/lib/python3.12/site-packages/tach/cli.py", line 941, in main
    tach_report(
  File "/Users/wjmeijer/Repositories/spice/.venv/lib/python3.12/site-packages/tach/cli.py", line 739, in tach_report
    report(
  File "/Users/wjmeijer/Repositories/spice/.venv/lib/python3.12/site-packages/tach/report.py", line 51, in report
    return create_dependency_report(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Encountered invalid filepath: ""

Workspace structure

.

├── .env
├── .gitignore
├── .tach
│   ├── .gitignore
│   ├── .latest-version
│   └── tach.info
├── .venv
│   └── ...
├── README.md
├── agent_app
│   ├── ...
│   └── compose.yml
├── central_app
│   ├── ...
│   ├── compose.yml
├── spice.code-workspace
├── src_repos
│   ├── project-a
│   │   ├── README.md
│   │   ├── pyproject.tool
│   │   └── src
│   │   │   └── project_a
│   ├── project-b
│   │   ├── README.md
│   │   ├── pyproject.toml
│   │   └── src
│   │   │   └── project_b
│   └── project-c
│   │   ├── README.md
│   │   ├── pyproject.toml
│   │   └── src
│   │   │   └── project_c
└── tach.toml
emdoyle commented 3 weeks ago

EDIT: It looks like this is actually an issue with running a report on a source root directory. This is not a supported usage of tach report. Instead, it accepts a path to a file or directory within any source root, and will tell you how that module is being used by the rest of the project.

I'll add a more informative error message for this case.

For your workspace, it seems like the source roots for Tach should be configured as the src directories within each of the src_repos. Then, you should be able to run tach report on the child directories (project_a, project_b, project_c) without issue. Please let me know if this works for you!

h0uter commented 3 weeks ago

I'd expected the "source root directory" would be where the pyproject.toml is located, not the src subfolder.

Probably related: note that I am using the "src layout" style of setting up my project. So that means that in my pyproject.toml's there is this line:

[tool.setuptools]
package-dir = { "" = "src" }

This line ensures we don't have to write from src.project_c import ... but that we can simply write from project_c import ....

In my experience, it would have been usefull to see a note in the docs for this on whether "src layout" is also supported and what the recommended setup is for that.

In summary: old: I had all "source root directory" set to the folders containing the pyproject.toml... Perhaps I expected tach would see the package-dir = { "" = "src" } line in pyproject.toml and figure out the modules are actually located in the src folders. But in this configuration tach sync also didn't work...

new: Now I took your advice and set all the "source root directory" to src in every project and tach sync appears to work correctly works. So for me it was an onboarding challenge related to using "src layout".