Skip to content

Commit aa06069

Browse files
committed
Use engine-managed modules in cwd scope
Signed-off-by: Guillaume de Rouville <guillaume@dagger.io>
1 parent f8137ee commit aa06069

3 files changed

Lines changed: 18 additions & 37 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Shared, language-agnostic operations — editing a module's dependencies or its
1010
required engine version — are owned by the core CLI (`dagger module deps`,
1111
`dagger module engine`) and are no longer part of this module's surface.
1212

13-
Backed by [`github.com/dagger/sdk-sdk/polyfill`](https://github.com/dagger/sdk-sdk/tree/main/polyfill).
13+
It uses the engine's native `Workspace` and `ModuleSource` APIs directly.
1414

1515
## Install
1616

‎docs/cwd-aware-discovery.md‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# CWD-aware module discovery
22

3-
The Python SDK delegates config discovery to `github.com/dagger/polyfill`, then
4-
intersects the discovered directories with `currentModule.asSDK.modules`. The
5-
engine's managed-module list remains authoritative while the caller's current
6-
directory determines scope.
3+
The Python SDK asks
4+
`currentModule.asSDK(workspace: ws).modulesInScope` for the registered modules
5+
relevant to the caller's current directory. The engine owns both membership and
6+
scope selection, so the SDK does not scan config files or reconstruct the cwd
7+
policy.
78

8-
Discovery returns modules at or below the cwd and, when the cwd has no module
9-
config, its nearest enclosing module. Both `dagger-module.toml` and legacy
10-
`dagger.json` are considered together, so the nearest config wins regardless of
11-
filename. Virtual environments and installed packages are excluded.
9+
Selection returns modules at or below the cwd and, when the cwd itself is not a
10+
registered module, its nearest registered ancestor.
1211

1312
```console
1413
dagger check -l
1514
dagger call e-2-e mixed-config-lookup-check
1615
dagger call e-2-e module-discovery-check
1716
```
1817

19-
The fixtures cover mixed nested config formats, modern and legacy configs,
20-
non-Python exclusion, root discovery, and discovery from inside a module.
18+
The fixtures cover mixed nested config formats, modern and legacy modules,
19+
non-Python exclusion, root selection, and selection from inside a module.

‎python-sdk.dang‎

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,16 @@ type PythonSdk {
1717
pub targetRuntime: String! { "python" }
1818

1919
"""
20-
Return every managed Python SDK module visible from the client's cwd: the
21-
nearest enclosing module plus modules at or below the cwd. Discovery uses the
22-
engine's Workspace.findConfigDirs and intersects its results with the SDK list on the passed
23-
workspace.
20+
Return every managed Python SDK module in the client's cwd scope: every module
21+
at or below the cwd, plus the nearest enclosing module when the cwd itself is
22+
not managed. The engine selects this directly from the workspace's registered
23+
SDK modules; no filesystem discovery is required.
2424
"""
2525
pub modules(ws: Workspace!): [Mod!]! {
26-
let managed = currentModule.asSDK(workspace: ws).modules.{{path}}
27-
let cwd = normalizePath(ws.cwd)
28-
ws
29-
.findConfigDirs(moduleConfigFilenames, exclude: ["**/.venv/**", "**/site-packages/**"])
30-
.map { dir => workspacePath(cwd, dir) }
31-
.uniq
32-
.filter { path => managed.filter { m => normalizePath(m.path) == path }.length > 0 }
33-
.map { path => Mod(rootPath: path, ws: ws, skipGenerateFilename: skipGenerateFilename) }
34-
}
35-
36-
let workspacePath(cwd: String!, path: String!): String! {
37-
let base = if (cwd == ".") { [] } else { cwd.split("/") }
38-
let segments = path.split("/").reduce(base) { acc, segment =>
39-
if (segment == "..") {
40-
acc.dropLast(1)
41-
} else if (segment == "." or segment == "") {
42-
acc
43-
} else {
44-
acc + [segment]
45-
}
46-
}
47-
if (segments.length == 0) { "." } else { segments.join("/") }
26+
currentModule
27+
.asSDK(workspace: ws)
28+
.modulesInScope.{{path}}
29+
.map { module => Mod(rootPath: module.path, ws: ws, skipGenerateFilename: skipGenerateFilename) }
4830
}
4931

5032
let normalizePath(path: String!): String! {

0 commit comments

Comments
 (0)