feat: make Python module discovery cwd-aware#9
Conversation
53824e4 to
4d51d5d
Compare
TomChv
left a comment
There was a problem hiding this comment.
Approved, I fixed dagger/polyfill#2 so just update your polyfill dep and merge the PR.
I tested it and it worked as expected.
41b296b to
94548db
Compare
|
Resolved. The failing checks were exposing a workspace-context compatibility change, not a problem with the mixed-config fixture. Current dogfood/main engines include dagger/dagger#13229, which stops inheriting the caller's ambient workspace into module dependencies. The injected This is the same migration used by dagger/typescript-sdk#9. The local A/B reproduced the CI boundary:
The earlier pin-only isolation still failed on dogfood, proving the new fixture was not the cause. The mixed-format regression is therefore restored in Focused dogfood results: module discovery, generate all, mixed config lookup. |
739bd70 to
10a793c
Compare
Workspace inheritance into module dependencies is disabled on current engines. Reading currentModule.asSDK therefore depends on ambient state that is absent when this SDK runs from an @check function. Resolve the installed SDK from the explicit Workspace argument instead. Its module source is the same workspace-root-relative path previously exposed as the current module SDK path, so discovery semantics remain unchanged. Signed-off-by: Guillaume de Rouville <guillaume@dagger.io>
Polyfill previously selected the first config filename found while walking up, so mixed dagger.json and dagger-module.toml layouts could resolve to a farther module based on filename order. Pin the dagger/polyfill#4 fix and cover a managed Python module whose nearby dagger.json is nested below an ancestor dagger-module.toml. Discovery from two levels inside the module must select the nearby module and return "../..". Signed-off-by: Guillaume de Rouville <guillaume@dagger.io>
279e14f to
d644f30
Compare
Context
The Python SDK helper discovers modules by globbing every
dagger.jsonfrom the workspace root. That predates workspaces and creates three problems:dagger-module.tomlmodules are invisible;modules.python-sdk.as-sdk.moduleslist.This PR makes Python SDK discovery follow the cwd-aware convention from dagger/dagger#13688.
Behavior after this change
modules(ws)asks polyfill for config directories visible from the caller cwd, converts those cwd-relative paths to workspace paths, and intersects them withws.sdk(name: currentModule.name).modules.modules/generateAllBoth
dagger-module.tomland legacydagger.jsonparticipate in discovery. Virtual environments and installed packages are excluded.mod(ws, path)also learns both config formats. It compares bothfindUpresults and validates the nearest module's runtime, so filename order cannot select a farther config.Internally,
Mod.rootPathis workspace-root-relative and is used for generation and configuration. The publicMod.pathis relative to the caller cwd. Keeping the two coordinate systems explicit prevents clients from resolving a cwd-relative path as though it were rooted at the workspace.Workspace ownership
The injected
Workspace!argument is authoritative throughout discovery. Reading the managed module list throughws.sdk(...)is intentional: current engines no longer inherit an ambient workspace into module dependencies (dagger/dagger#13229), socurrentModule.asSDKfails from@checkexecution withworkspace not loaded.This preserves the previous data model:
WorkspaceModule.sourceis the same workspace-root-relative module path used for the intersection.Scope
generateAllscoping.modlookup.initClientCheckleft afterPythonSdk.initClientwas removed, allowing the rebased e2e module to load.Reviewer guide
The implementation is concentrated in:
python-sdk.dang: cwd discovery, path normalization, explicit workspace SDK lookup, andgenerateAll;mod.dang: separation ofrootPathfrom cwd-relativepath;.dagger/modules/e2e/fixtures/toml: explicit lookup where a nearer TOML must beat the repository's outer JSON;.dagger/modules/e2e/fixtures/mixed-discovery: shared discovery where a nearer JSON must beat an ancestor TOML;.dagger/modules/e2e/main.dang: focused lookup and discovery assertions.The reverse mixed-format fixture is:
The expected module is
app, with public path../..fromnested/deeper.Reproduce locally
Run the focused checks from the repository root:
dagger check e-2-e:mixed-config-lookup-check e-2-e:module-discovery-check e-2-e:generate-all-checkInspect cwd-relative output from inside a checked-in legacy module:
Expected output:
Verification
dagger check: 11/11 against a locally rebuilt main engine.dagger --x-release=v1.0.0-beta.7 check: 11/11.loadand all 11 checks pass.