From 8abba2a3ddb2e4d8b7a4ed781daff3b18d3a4f95 Mon Sep 17 00:00:00 2001 From: Guillaume de Rouville Date: Thu, 13 Aug 2026 21:49:42 -0700 Subject: [PATCH 1/7] 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 b640b88a..650ec083 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 8831c471..5bcfdef9 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 7e5723d5..122494c1 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 e3421837..69f8bb01 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 818ced50..f5203c92 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 eac112e0..68d05089 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 100d94fc..a84212d4 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) } } From 05af0b2ae7b0679eb7c7532ebf0c095c94283b79 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Fri, 21 Aug 2026 10:39:18 +0200 Subject: [PATCH 2/7] chore: update sdk-sdk to the polyfill-free harness sdk-sdk reached dagger/polyfill through the module-source type its harness returned, and its checks drove a CLI release older than the engine this module now requires. Either one takes seven of this repository's checks down. dagger/sdk-sdk#14 replaced the module-source type and dagger/sdk-sdk#20 taught every check group to honor daggerCliVersion; this records that version. The workspace floats sdk-sdk to its default branch, so the lock file is a record rather than a constraint. It moves to format 2 as a side effect of being rewritten by the current CLI, and loses the polyfill entry along with the dependency. Signed-off-by: Yves Brissaud --- dagger.lock | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dagger.lock b/dagger.lock index 122494c1..677b7c39 100644 --- a/dagger.lock +++ b/dagger.lock @@ -1,2 +1,4 @@ -[["version","1"]] -["","git.head",["https://github.com/dagger/sdk-sdk"],"e1747f4b6221fa24da080701e027243e0cc5fa33","float"] +[["version","2"]] +["","container.from",["docker.io/library/alpine:3.22","linux/amd64"],"sha256:14358309a308569c32bdc37e2e0e9694be33a9d99e68afb0f5ff33cc1f695dce"] +["","container.from",["docker.io/library/golang:1.25-alpine","linux/amd64"],"sha256:1ae0735f00daffa3aaf1363a5184c0d2dc55c78e3db4ec70241cdac97bf84b59"] +["","git.ref",["https://github.com/dagger/sdk-sdk","HEAD"],{"ref":"refs/heads/main","sha":"00bb06748bcf22d724ed467f2298d31f1fb49be0"}] \ No newline at end of file From fa175688d598041716b121cbe6fd68f01fb7344e Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Fri, 21 Aug 2026 10:39:22 +0200 Subject: [PATCH 3/7] python-sdk: drop the config filename list the polyfill needed moduleConfigFilenames existed to tell the polyfill's findConfigDirs walk which files marked a module root. The engine now reports registered modules directly, so nothing reads the list. Signed-off-by: Yves Brissaud --- python-sdk.dang | 1 - 1 file changed, 1 deletion(-) diff --git a/python-sdk.dang b/python-sdk.dang index a84212d4..fdedaf59 100644 --- a/python-sdk.dang +++ b/python-sdk.dang @@ -4,7 +4,6 @@ Manage Dagger modules that use the Python SDK. type PythonSdk { let legacyConfigPattern = "\"sdk\"\\s*:\\s*\\{[^}]*\"source\"\\s*:\\s*\"python\"" let tomlConfigPattern = "\\[runtime\\][^\\[]*source\\s*=\\s*\"python\"" - let moduleConfigFilenames: [String!]! = ["dagger-module.toml", "dagger.json"] """ Marker filename that skips generate when found at or above a Python SDK module root. From fdc02da2adfb4e62a7d3faf656b5685ce66a931a Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Fri, 21 Aug 2026 10:49:23 +0200 Subject: [PATCH 4/7] docs: describe discovery as the engine now does it The note under "Discover modules in a workspace" still described the legacy dagger.json scan, and called the engine's as-sdk list the thing that would supersede it. That happened here. Signed-off-by: Yves Brissaud --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 650ec083..6a026b1a 100644 --- a/README.md +++ b/README.md @@ -120,10 +120,9 @@ dagger call python-sdk modules path ``` > [!NOTE] -> `modules` and `generate-all` discover modules by scanning legacy -> `dagger.json` files for `sdk.source == "python"`. This is obsolete for -> workspace-managed modules, where the engine owns the -> `modules..as-sdk.modules` source of truth. +> `modules` and `generate-all` read the modules registered under +> `modules..as-sdk.modules`, which the engine owns and narrows to the +> caller's cwd. Nothing scans module config files. See [`python-sdk.dang`](./python-sdk.dang) for the full type surface. From 737bd549f1be051a819b43706862c1479b971ebf Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Fri, 21 Aug 2026 11:10:03 +0200 Subject: [PATCH 5/7] python-sdk: keep a user's files when init runs over them Workspace.withNewDirectory replaces the directory it writes. The polyfill's fork.withDirectory layered onto what was already there, so swapping one for the other turned `dagger module init` into a delete: running it against a directory that already held files reported them all as removed, including the module's own engine-owned dagger.json. Layer the template onto the existing directory instead, and check it. The sdk-sdk contract suite already asserts init removes nothing, but it only ever inits into a fresh path, so it cannot see this. Found by the dagger/go-sdk#30 sibling, which hit the same substitution. Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/main.dang | 26 ++++++++++++++++++++++++++ python-sdk.dang | 17 ++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index b92ce59c..9434f9b7 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -168,6 +168,32 @@ type E2e { null } + """ + Init into a directory that already holds files should layer the template onto + it, never replace it: a user running init inside an existing project keeps + their files. + """ + pub initOverExistingCheck(ws: Workspace!): Void @check { + let changes = pythonSdk.initModule(ws, name: "init-over-existing", path: lookupModulePath) + + assert( + changes.removedPaths.length == 0, + "init removed existing files: " + changes.removedPaths.join(", "), + ) + assertContains( + changes.after.file(lookupModulePath + "/src/lookup_app/__init__.py").contents, + "class LookupApp:", + "init must leave the existing module source in place", + ) + assertContains( + changes.after.file(lookupModulePath + "/src/init_over_existing/__init__.py").contents, + "class InitOverExisting:", + "init did not render the template into the existing directory", + ) + + null + } + """ The default template should render a working module that reads source from the workspace and returns a ready-to-build container. The empty template diff --git a/python-sdk.dang b/python-sdk.dang index fdedaf59..3877decc 100644 --- a/python-sdk.dang +++ b/python-sdk.dang @@ -143,12 +143,27 @@ type PythonSdk { } else { let templateSource = configuredTemplate(renderedTemplate(name, selectedTemplate), pythonVersion, useUv, baseImage) + # withNewDirectory replaces the directory it writes, so layer the + # template onto what is already there: init must never remove a user's + # files. ws - .withNewDirectory("/" + modPath, templateSource) + .withNewDirectory("/" + modPath, existingDir(ws, modPath).withDirectory(".", templateSource)) .changes(ws) } } + """ + Existing contents of a workspace directory, empty when it does not exist yet. + """ + let existingDir(ws: Workspace!, path: String!): Directory! { + let filtered = ws.directory("/", include: [path + "/**"]) + if (filtered.exists(path)) { + filtered.directory(path) + } else { + directory + } + } + """ Render a Python template with the requested module name. """ From c151e71285f8a726615fbffc8f07897170f5efda Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Fri, 21 Aug 2026 11:32:30 +0200 Subject: [PATCH 6/7] python-sdk: resolve mod lookup from the engine's module list mod(findUp:) walked the workspace for a dagger-module.toml or dagger.json, took whichever sat deepest, then regex-matched the file's contents to decide whether the module was Python. modules() had already stopped doing any of that, so the two disagreed about what makes a module ours: one trusted registration, the other trusted config text. Ask the engine instead. Re-anchoring the workspace at the requested path scopes its SDK module list to that directory, which is the same selection modules() reads, so the nearest enclosing entry is the answer. The two config regexes, configDir and validateConfig go with the walk. A module that is not registered is no longer found. That is the point, and it is now checked: lookup of a module this SDK does not manage raises rather than handing back a Mod. The config fixtures were relying on the old config-text path and are registered like every other fixture. Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/main.dang | 12 +++++++ dagger.toml | 6 ++++ docs/cwd-aware-discovery.md | 6 ++++ python-sdk.dang | 61 ++++++++++++++++++----------------- 4 files changed, 55 insertions(+), 30 deletions(-) diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index 9434f9b7..214c0cc9 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -109,6 +109,18 @@ type E2e { null } + """ + Lookup should refuse a module this SDK does not manage, rather than handing + back a Mod for someone else's module. + """ + pub unmanagedLookupCheck(ws: Workspace!): Void @check { + let found = pythonSdk.mod(ws, path: nonPythonModulePath).rootPath rescue "raised" + + assert(found == "raised", "lookup returned a module this SDK does not manage: " + found) + + null + } + """ Lookup must choose the nearest module config even when its filename differs from an ancestor config, and modern TOML modules must be supported. diff --git a/dagger.toml b/dagger.toml index 93cbd544..7036eb56 100644 --- a/dagger.toml +++ b/dagger.toml @@ -36,3 +36,9 @@ path = ".dagger/modules/e2e/fixtures/toml/app" [[modules.python-sdk.as-sdk.modules]] path = ".dagger/modules/e2e/fixtures/mixed-discovery/ancestor/work/app" + +[[modules.python-sdk.as-sdk.modules]] +path = ".dagger/modules/e2e/fixtures/config/app" + +[[modules.python-sdk.as-sdk.modules]] +path = ".dagger/modules/e2e/fixtures/config/configured" diff --git a/docs/cwd-aware-discovery.md b/docs/cwd-aware-discovery.md index 69f8bb01..ac7527bb 100644 --- a/docs/cwd-aware-discovery.md +++ b/docs/cwd-aware-discovery.md @@ -9,10 +9,16 @@ policy. Selection returns modules at or below the cwd and, when the cwd itself is not a registered module, its nearest registered ancestor. +`mod` resolves a single module from the same list, re-anchoring the workspace at +the requested path so the engine scopes the selection there. A path that no +registered module contains is an error rather than a module this SDK does not +manage. + ```console dagger check -l dagger call e-2-e mixed-config-lookup-check dagger call e-2-e module-discovery-check +dagger call e-2-e unmanaged-lookup-check ``` The fixtures cover mixed nested config formats, modern and legacy modules, diff --git a/python-sdk.dang b/python-sdk.dang index 3877decc..5278837f 100644 --- a/python-sdk.dang +++ b/python-sdk.dang @@ -2,9 +2,6 @@ Manage Dagger modules that use the Python SDK. """ type PythonSdk { - let legacyConfigPattern = "\"sdk\"\\s*:\\s*\\{[^}]*\"source\"\\s*:\\s*\"python\"" - let tomlConfigPattern = "\\[runtime\\][^\\[]*source\\s*=\\s*\"python\"" - """ Marker filename that skips generate when found at or above a Python SDK module root. """ @@ -37,8 +34,8 @@ type PythonSdk { if (path == null) { -1 } else if (path == ".") { 0 } else { path.split("/").length } } - let configDir(path: String!, filename: String!): String! { - normalizePath(path.trimPrefix("/").trimSuffix(filename)) + let pathContains(root: String!, path: String!): Boolean! { + root == "." or path == root or path.trimPrefix(root + "/") != path } """ @@ -68,26 +65,15 @@ type PythonSdk { } """ - Return the Python SDK module at or above a workspace path. + Return the managed Python SDK module at or above a workspace path. - When `findUp` is true, `path` may point inside the module. + When `findUp` is true, `path` may point inside the module; the nearest + enclosing module wins. When it is false, `path` is taken as the module root + as given, without asking whether this SDK manages it. """ pub mod(ws: Workspace!, path: String! = ".", findUp: Boolean! = true): Mod! { let modPath = if (findUp) { - let foundToml = ws.findUp("dagger-module.toml", path) - let foundJson = ws.findUp("dagger.json", path) - let tomlBase = if (foundToml == null) { null } else { configDir(foundToml, "dagger-module.toml") } - let jsonBase = if (foundJson == null) { null } else { configDir(foundJson, "dagger.json") } - - if (tomlBase == null and jsonBase == null) { - raise "no Dagger module found containing path: " + path - } else if (tomlBase != null and pathDepth(tomlBase) > pathDepth(jsonBase)) { - validateConfig(ws, tomlBase, "dagger-module.toml", tomlConfigPattern, path) - } else if (jsonBase != null) { - validateConfig(ws, jsonBase, "dagger.json", legacyConfigPattern, path) - } else { - raise "no Dagger module found containing path: " + path - } + managedModuleAtOrAbove(ws, path) } else { normalizePath(path) } @@ -99,15 +85,30 @@ type PythonSdk { ) } - let validateConfig(ws: Workspace!, base: String!, filename: String!, pattern: String!, requestedPath: String!): String! { - let configPath = if (base == ".") { filename } else { base + "/" + filename } - let matches = ws - .directory("/", include: [configPath]) - .file(configPath) - .search(pattern: pattern, multiline: true, dotall: true, limit: 1) - .{{id}} - .length > 0 - if (matches) { base } else { raise "Dagger module does not use the Python SDK: " + requestedPath } + """ + Root of the nearest managed Python SDK module containing `path`. + + Re-anchoring the workspace at `path` makes the engine scope its SDK module + list to that directory, which is the same selection `modules` reads. Nothing + here parses module config: registration is what makes a module ours. + """ + let managedModuleAtOrAbove(ws: Workspace!, path: String!): String! { + let scopedWs = ws.withWorkdir(path) + let requested = normalizePath(scopedWs.cwd) + let found = currentModule + .asSDK(workspace: scopedWs) + .modules.{{path}} + .map { module => normalizePath(module.path) } + .filter { root => pathContains(root, requested) } + .reduce(null) { best, root => + if (pathDepth(root) > pathDepth(best)) { root } else { best } + } + + if (found == null) { + raise "no managed Python SDK module found containing path: " + path + } else { + found + } } """ From 72d7c1690a9608d27fe6cd5f54ce1295725f7140 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Fri, 21 Aug 2026 11:32:33 +0200 Subject: [PATCH 7/7] docs: name the init templates that actually exist The README has offered a `minimal` template since the CLI 1.0 init contract landed. There is no such template: templates/ holds default, empty and legacy, and initModule defaults to default. Passing --template minimal fails. Signed-off-by: Yves Brissaud --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6a026b1a..2fc064de 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,9 @@ dagger module init python my-module \ --base-image python:3.13-slim ``` -`--template` picks a starter template (`minimal` is the default; `legacy` gives -you a container-echo example). The three `pyproject.toml` flags are optional; by +`--template` picks a starter template: `default` (a small working module) when +you pass nothing, `empty` for a bare object class, or `legacy` for a +container-echo example. The three `pyproject.toml` flags are optional; by default the template's Python version is used, uv is enabled, and no base image override is written.