Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import resolution for monorepos #645

Merged
merged 6 commits into from
Feb 25, 2025
Merged

Conversation

emdoyle
Copy link
Member

@emdoyle emdoyle commented Feb 25, 2025

Fixes: #564

This PR significantly changes the semantics of check-external, and brings a much more explicit understanding of packages to Tach.

Before this PR:

  • anything in any of the source_roots was defined as a 'project import', or in other words an internal import, and would not be covered by check-external
  • only pyproject.toml was recognized as a package marker, and its parsed contents defined the actual source roots which would be checked (leading to strange behavior when it differed from Tach's source_roots)
  • error messages about unused dependencies did not point out which package contained the issue

After this PR:

  • source_roots are separate from 'packages', and will 'roll up' to the nearest package above them
  • packages are identified by the presence of pyproject.toml, requirements.txt, setup.py or the Tach project root [NOTE: setup.py is not supported, since it is not always possible to check statically]
  • in addition to 3rd party packages, check-external will check all imports which resolve to source code outside the current package - this covers local packages in a monorepo
  • error messages about unused dependencies show the package root which declares the unused dependencies

This PR also introduces additional examples and tests. One directory uses namespace packages, while the other is drawn from the docs on uv workspaces. In both cases, imports can be resolved to the other local packages, and checked with check-external.

Upcoming work:

  • glob patterns and exclusions in source_roots
  • external dependency controls for modules (e.g. depends_on equivalents for external dependencies)
  • dependency banning for modules
  • dependency groups
  • moving check-external into a flag for check

@emdoyle emdoyle marked this pull request as ready for review February 25, 2025 08:41
@emdoyle emdoyle merged commit 2cdf54c into main Feb 25, 2025
8 of 11 checks passed
@emdoyle emdoyle deleted the fix-monorepo-import-resolution branch February 25, 2025 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dependencies do not get parsed correctly in monorepo with multiple packages
1 participant