Repository navigation
feat(pyproject): add a project and workspace discovery module - #126
Merged
Merged
Conversation
A shared discovery layer for the Python modules. It exposes two collections: - `projects`: every directory holding a `pyproject.toml`. - `workspaces`: every directory holding a workspace marker (`uv.lock` and `pylock.toml` by default, configurable with `workspaceMarkers`). Every file belongs to the deepest project containing it. Each item loads only the source it needs through the Workspace API: its own tree plus its local path/workspace dependencies (transitively, including ones outside the workspace root), less nested projects nothing needs. A workspace also exposes `manifests`, just the resolver inputs, so a dependency layer built from it survives source edits. Manifests are parsed with tomllib, so dotted keys, marker-split sources and single quotes work. uv workspace membership follows `[tool.uv.workspace]` members/exclude globs, and members inherit the root's sources. Missing path sources load nothing instead of failing.
Workspace.find_roots walks gitignored directories on git-backed and synthetic workspaces alike, so a gitignored copy of the repository (e.g. an agent worktree under .claude/worktrees) showed up as a second set of projects. Discovery now reads the workspace's .gitignore files (found with the same pruned find_roots walk) and drops roots whose marker they ignore.
uv applies a [tool.uv.sources] entry only to a package the project declares as a dependency. Discovery followed every entry, so a project depending on one member of a large uv workspace inherited the root's sources for every member and loaded all of them: Infra's tools/cluster-secret pulled in ~40 pulumi members through one path dependency. Sources now apply only to names declared in [project].dependencies, optional dependencies, dependency groups or the legacy tool.uv.dev-dependencies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A new
pyprojectmodule: the shared discovery layer for our Python modules (uv,ruff,deptry, and later pytest/pyrefly). It runs no tools itself and exposes two collections:projects: every directory holding apyproject.toml. Fields:name,workspace(the workspace that installs it as a member),nested,local_dependencies. Functions:source(ws),pyproject(ws).workspaces: every directory holding a workspace marker,uv.lockandpylock.tomlby default (configurable with theworkspaceMarkerssetting). Fields:lockfiles,members,local_dependencies. Functions:projects(),source(ws),manifests(ws).Both are keyed by path relative to the workspace root and take an
excludeglob setting.Why
These fix problems found in
dagger/python's sharedpyprojectlibrary and in our own modules:../lib) aren't mounted, souv syncbreakssourceloads the project's tree plus its transitive path/workspace sources, wherever they livetomllibpathlibfull_match;**crosses directories, and a trailing/**also matches the directory itselfworkspace.manifests(ws)holds only resolver inputs (markers,uv.toml, members' and local deps'pyproject.toml/.python-version)Directoryinput: any edit busts everythinguv semantics come from
pyproject.toml, the same source uv itself uses, not the lockfile:[tool.uv.workspace]members/exclude, and the deepest workspace wins.[tool.uv.sources], overridden per package.{ workspace = true }resolves by normalized name.partial-workspacecase).