From 8abba2a3ddb2e4d8b7a4ed781daff3b18d3a4f95 Mon Sep 17 00:00:00 2001 From: Guillaume de Rouville Date: Thu, 13 Aug 2026 21:49:42 -0700 Subject: [PATCH] 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 --- README.md | 2 +- dagger.json | 11 ++------ dagger.lock | 1 - docs/cwd-aware-discovery.md | 19 +++++++------ mod-config.dang | 2 +- mod.dang | 7 ++--- python-sdk.dang | 53 ++++++++++--------------------------- 7 files changed, 29 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index b640b88..650ec08 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Shared, language-agnostic operations — editing a module's dependencies or its required engine version — are owned by the core CLI (`dagger module deps`, `dagger module engine`) and are no longer part of this module's surface. -Backed by [`github.com/dagger/sdk-sdk/polyfill`](https://github.com/dagger/sdk-sdk/tree/main/polyfill). +It uses the engine's native `Workspace` and `ModuleSource` APIs directly. ## Install diff --git a/dagger.json b/dagger.json index 8831c47..5bcfdef 100644 --- a/dagger.json +++ b/dagger.json @@ -1,14 +1,7 @@ { "name": "python-sdk", - "engineVersion": "v1.0.0-0", + "engineVersion": "v1.0.0-beta.10", "sdk": { "source": "dang" - }, - "dependencies": [ - { - "name": "polyfill", - "source": "github.com/dagger/polyfill@main", - "pin": "16627066d1852106320bdc0cfa0e5f901efe5970" - } - ] + } } diff --git a/dagger.lock b/dagger.lock index 7e5723d..122494c 100644 --- a/dagger.lock +++ b/dagger.lock @@ -1,3 +1,2 @@ [["version","1"]] ["","git.head",["https://github.com/dagger/sdk-sdk"],"e1747f4b6221fa24da080701e027243e0cc5fa33","float"] -["","git.ref",["https://github.com/dagger/polyfill","main"],"ec3ea84a2351b4beb06ecece951f2e5ef66509ff","float"] \ No newline at end of file diff --git a/docs/cwd-aware-discovery.md b/docs/cwd-aware-discovery.md index e342183..69f8bb0 100644 --- a/docs/cwd-aware-discovery.md +++ b/docs/cwd-aware-discovery.md @@ -1,14 +1,13 @@ # CWD-aware module discovery -The Python SDK delegates config discovery to `github.com/dagger/polyfill`, then -intersects the discovered directories with `currentModule.asSDK.modules`. The -engine's managed-module list remains authoritative while the caller's current -directory determines scope. +The Python SDK asks +`currentModule.asSDK(workspace: ws).modules` for the registered modules +relevant to the caller's current directory. The engine owns both membership and +scope selection, so the SDK does not scan config files or reconstruct the cwd +policy. -Discovery returns modules at or below the cwd and, when the cwd has no module -config, its nearest enclosing module. Both `dagger-module.toml` and legacy -`dagger.json` are considered together, so the nearest config wins regardless of -filename. Virtual environments and installed packages are excluded. +Selection returns modules at or below the cwd and, when the cwd itself is not a +registered module, its nearest registered ancestor. ```console dagger check -l @@ -16,5 +15,5 @@ dagger call e-2-e mixed-config-lookup-check dagger call e-2-e module-discovery-check ``` -The fixtures cover mixed nested config formats, modern and legacy configs, -non-Python exclusion, root discovery, and discovery from inside a module. +The fixtures cover mixed nested config formats, modern and legacy modules, +non-Python exclusion, root selection, and selection from inside a module. diff --git a/mod-config.dang b/mod-config.dang index 818ced5..f5203c9 100644 --- a/mod-config.dang +++ b/mod-config.dang @@ -83,7 +83,7 @@ type ModConfig { } let edited = withImage.file(toolPath).contents - polyfill.workspace(ws).fork.withNewFile(pyprojectPath, edited).changes + ws.withNewFile("/" + pyprojectPath, edited).changes(ws) } """ diff --git a/mod.dang b/mod.dang index eac112e..68d0508 100644 --- a/mod.dang +++ b/mod.dang @@ -56,12 +56,9 @@ type Mod { """ pub generate: Changeset! { if (skipGenerate) { - polyfill.workspace(ws).fork.changes + ws.changes(ws) } else { - # Stage the local dependency closure so this module's codegen sees - # up-to-date dependency bindings before generating it. - let stagedWs = ws.withChanges(polyfill.workspace(ws).moduleSource("/" + rootPath).core.generateLocalDependencies(ws)) - polyfill.workspace(stagedWs).moduleSource("/" + rootPath).generate.changes + ws.moduleSource("/" + rootPath).generate(ws).changes(ws) } } } diff --git a/python-sdk.dang b/python-sdk.dang index 100d94f..a84212d 100644 --- a/python-sdk.dang +++ b/python-sdk.dang @@ -17,34 +17,16 @@ type PythonSdk { pub targetRuntime: String! { "python" } """ - Return every managed Python SDK module visible from the client's cwd: the - nearest enclosing module plus modules at or below the cwd. Discovery uses the - shared polyfill and intersects its results with the SDK list on the passed - workspace. + Return every managed Python SDK module in the client's cwd scope: every module + at or below the cwd, plus the nearest enclosing module when the cwd itself is + not managed. The engine selects this directly from the workspace's registered + SDK modules; no filesystem discovery is required. """ pub modules(ws: Workspace!): [Mod!]! { - let managed = currentModule.asSDK(workspace: ws).modules.{{path}} - let cwd = normalizePath(ws.cwd) - polyfill.workspace(ws) - .findConfigDirs(moduleConfigFilenames, exclude: ["**/.venv/**", "**/site-packages/**"]) - .map { dir => workspacePath(cwd, dir) } - .uniq - .filter { path => managed.filter { m => normalizePath(m.path) == path }.length > 0 } - .map { path => Mod(rootPath: path, ws: ws, skipGenerateFilename: skipGenerateFilename) } - } - - let workspacePath(cwd: String!, path: String!): String! { - let base = if (cwd == ".") { [] } else { cwd.split("/") } - let segments = path.split("/").reduce(base) { acc, segment => - if (segment == "..") { - acc.dropLast(1) - } else if (segment == "." or segment == "") { - acc - } else { - acc + [segment] - } - } - if (segments.length == 0) { "." } else { segments.join("/") } + currentModule + .asSDK(workspace: ws) + .modules.{{path}} + .map { module => Mod(rootPath: module.path, ws: ws, skipGenerateFilename: skipGenerateFilename) } } let normalizePath(path: String!): String! { @@ -162,9 +144,9 @@ type PythonSdk { } else { let templateSource = configuredTemplate(renderedTemplate(name, selectedTemplate), pythonVersion, useUv, baseImage) - polyfill.workspace(ws).fork - .withDirectory(modPath, templateSource) - .changes + ws + .withNewDirectory("/" + modPath, templateSource) + .changes(ws) } } @@ -219,18 +201,11 @@ type PythonSdk { Modules with the generate skip marker are skipped. """ pub generateAll(ws: Workspace!): Changeset! @generate { - let pws = polyfill.workspace(ws) - modules(ws) .filter { mod => mod.skipGenerate == false } - .reduce(pws.fork) { fork, mod => - # Stage this module's local dependency closure first (leaf-first, possibly - # across SDKs) so its codegen sees up-to-date dependency bindings. The dep - # codegen is ephemeral: it appears in both the fork's before and after, so - # it cancels in the merge, leaving only each module's own changes. - let stagedWs = ws.withChanges(pws.moduleSource("/" + mod.rootPath).core.generateLocalDependencies(ws)) - fork.merge(polyfill.workspace(stagedWs).moduleSource("/" + mod.rootPath).generate) + .reduce(ws) { stagedWs, mod => + stagedWs.moduleSource("/" + mod.rootPath).generate(stagedWs) } - .changes + .changes(ws) } }