Skip to content

Commit 8abba2a

Browse files
committed
Remove the polyfill dependency
The Python SDK used dagger/polyfill for managed module discovery, module generation, and config edits. Those behaviors now live in Workspace and ModuleSource. Read managed modules from currentModule.asSDK(workspace).modules, thread the Workspace through generation, and compare the final workspace with the workspace the SDK received. Remove the polyfill and bump the engine requirement in the same change so existing staged edits are not returned twice. Signed-off-by: Guillaume de Rouville <guillaume@dagger.io>
1 parent 6dca4e9 commit 8abba2a

7 files changed

Lines changed: 29 additions & 66 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

‎dagger.json‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
{
22
"name": "python-sdk",
3-
"engineVersion": "v1.0.0-0",
3+
"engineVersion": "v1.0.0-beta.10",
44
"sdk": {
55
"source": "dang"
6-
},
7-
"dependencies": [
8-
{
9-
"name": "polyfill",
10-
"source": "github.com/dagger/polyfill@main",
11-
"pin": "16627066d1852106320bdc0cfa0e5f901efe5970"
12-
}
13-
]
6+
}
147
}

‎dagger.lock‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
[["version","1"]]
22
["","git.head",["https://github.com/dagger/sdk-sdk"],"e1747f4b6221fa24da080701e027243e0cc5fa33","float"]
3-
["","git.ref",["https://github.com/dagger/polyfill","main"],"ec3ea84a2351b4beb06ecece951f2e5ef66509ff","float"]

‎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).modules` 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.

‎mod-config.dang‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type ModConfig {
8383
}
8484

8585
let edited = withImage.file(toolPath).contents
86-
polyfill.workspace(ws).fork.withNewFile(pyprojectPath, edited).changes
86+
ws.withNewFile("/" + pyprojectPath, edited).changes(ws)
8787
}
8888

8989
"""

‎mod.dang‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@ type Mod {
5656
"""
5757
pub generate: Changeset! {
5858
if (skipGenerate) {
59-
polyfill.workspace(ws).fork.changes
59+
ws.changes(ws)
6060
} else {
61-
# Stage the local dependency closure so this module's codegen sees
62-
# up-to-date dependency bindings before generating it.
63-
let stagedWs = ws.withChanges(polyfill.workspace(ws).moduleSource("/" + rootPath).core.generateLocalDependencies(ws))
64-
polyfill.workspace(stagedWs).moduleSource("/" + rootPath).generate.changes
61+
ws.moduleSource("/" + rootPath).generate(ws).changes(ws)
6562
}
6663
}
6764
}

‎python-sdk.dang‎

Lines changed: 14 additions & 39 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-
shared polyfill 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-
polyfill.workspace(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+
.modules.{{path}}
29+
.map { module => Mod(rootPath: module.path, ws: ws, skipGenerateFilename: skipGenerateFilename) }
4830
}
4931

5032
let normalizePath(path: String!): String! {
@@ -162,9 +144,9 @@ type PythonSdk {
162144
} else {
163145
let templateSource = configuredTemplate(renderedTemplate(name, selectedTemplate), pythonVersion, useUv, baseImage)
164146

165-
polyfill.workspace(ws).fork
166-
.withDirectory(modPath, templateSource)
167-
.changes
147+
ws
148+
.withNewDirectory("/" + modPath, templateSource)
149+
.changes(ws)
168150
}
169151
}
170152

@@ -219,18 +201,11 @@ type PythonSdk {
219201
Modules with the generate skip marker are skipped.
220202
"""
221203
pub generateAll(ws: Workspace!): Changeset! @generate {
222-
let pws = polyfill.workspace(ws)
223-
224204
modules(ws)
225205
.filter { mod => mod.skipGenerate == false }
226-
.reduce(pws.fork) { fork, mod =>
227-
# Stage this module's local dependency closure first (leaf-first, possibly
228-
# across SDKs) so its codegen sees up-to-date dependency bindings. The dep
229-
# codegen is ephemeral: it appears in both the fork's before and after, so
230-
# it cancels in the merge, leaving only each module's own changes.
231-
let stagedWs = ws.withChanges(pws.moduleSource("/" + mod.rootPath).core.generateLocalDependencies(ws))
232-
fork.merge(polyfill.workspace(stagedWs).moduleSource("/" + mod.rootPath).generate)
206+
.reduce(ws) { stagedWs, mod =>
207+
stagedWs.moduleSource("/" + mod.rootPath).generate(stagedWs)
233208
}
234-
.changes
209+
.changes(ws)
235210
}
236211
}

0 commit comments

Comments
 (0)