From 09751bab73f76b9680a592878ce71726a7864030 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Tue, 27 Oct 2026 07:09:27 +0100 Subject: [PATCH 1/7] Compile dependency bytecode into the shared layer Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/main.dang | 14 ++++++++++++++ pyproject/main.dang | 2 ++ 2 files changed, 16 insertions(+) diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index 2ec565e..3e15731 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -841,6 +841,20 @@ type E2e { "the shared environment was rebuilt instead of reused", ) + let dependencyWs = ws.withNewFile( + passFixture + "/pyproject.toml", + ws.file("/" + passFixture + "/pyproject.toml").contents + "\ndependencies = [\"packaging==25.0\"]\n", + ) + project.dependencies(dependencyWs) + .withoutMount("/root/.cache/uv") + .withExec([".venv/bin/python", "-I", "-c", + "import importlib.util, pathlib, packaging\n" + + "pyc = pathlib.Path(importlib.util.cache_from_source(packaging.__file__))\n" + + "assert pyc.is_file(), 'dependency bytecode is missing'\n" + + "assert int.from_bytes(pyc.read_bytes()[4:8], 'little') == 3, 'bytecode is not checked-hash'\n", + ]) + .sync + # The project itself does not depend on packaging; the extra does. let bare = { project.env(ws).withExec(["uv", "run", "python", "-c", "import packaging"]).sync diff --git a/pyproject/main.dang b/pyproject/main.dang index d79877d..af18a8d 100644 --- a/pyproject/main.dang +++ b/pyproject/main.dang @@ -136,6 +136,8 @@ type Pyproject { # default hardlink install mode falls back to a copy with a warning. .withEnvVariable("UV_LINK_MODE", "copy") .withEnvVariable("UV_NO_PROGRESS", "1") + .withEnvVariable("UV_COMPILE_BYTECODE", "1") + .withEnvVariable("PYC_INVALIDATION_MODE", "CHECKED_HASH") .withDirectory("/usr/local/bin", uvBinary, include: ["uv", "uvx"]) } From 6c08a1578cbc58ee18378888eab277431bc32668 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Tue, 27 Oct 2026 07:10:18 +0100 Subject: [PATCH 2/7] Install tools into the constrained project environment Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/main.dang | 25 +++++++++++++++++++-- pyproject/main.dang | 42 +++++++++++++++++++++++------------ pytest/main.dang | 6 ++--- 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index 3e15731..d48182d 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -869,14 +869,35 @@ type E2e { let withExtra = project.env(ws, with: ["packaging"]) withExtra - .withExec(["uv", "run"] + project.withFlags(["packaging"]) - + ["python", "-c", "import packaging"]) + .withoutMount("/root/.cache/uv") + .withExec(project.uvRun(["packaging"]) + + ["python", "-I", "-c", "import packaging, sys; assert packaging.__file__.startswith(sys.prefix + '/')"]) .sync + let lockedWs = dependencyWs.withNewFile( + passFixture + "/uv.lock", + project.dependencies(dependencyWs).file("uv.lock").contents, + ) + [dependencyWs, lockedWs].each { input => + let failure = { + project.dependencies(input, with: ["packaging==24.2"]).sync + "built" + } rescue { err: Error => err.message } + assert( + failure.contains("environment failed (uv pip install") and failure.contains("packaging"), + "a tool replaced a constrained dependency: " + failure, + ) + } + # Dependencies install from the files uv reads, before any source is # mounted, so a source edit leaves that layer cached. let edited = ws.withNewFile(passFixture + "/greeting.py", "GREETING = 'edited'\n") let editedProject = lib.project(edited, passFixture) + assert( + project.dependencies(ws, with: ["packaging"]).rootfs.digest + == editedProject.dependencies(edited, with: ["packaging"]).rootfs.digest, + "a source edit changed the installed tools", + ) assert( project.installInputs(ws).glob("**") == editedProject.installInputs(edited).glob("**"), "a source edit changed the dependency layer's inputs", diff --git a/pyproject/main.dang b/pyproject/main.dang index af18a8d..45c005d 100644 --- a/pyproject/main.dang +++ b/pyproject/main.dang @@ -875,9 +875,9 @@ type PythonProject { itself or its local path dependencies, from `installInputs` alone. `with` names extra packages the caller needs on top of the project's own. - They are resolved against the project's environment here, not installed - over the top of a finished one, so a conflict fails here, while building the - environment. `mount` is placed at `mountPath` for an extra package named + They are installed into its environment under constraints from the lockfile, + or the installed dependencies when there is no lock, so a conflict fails + while building the environment. `mount` is placed at `mountPath` for an extra package named by path, after the dependency sync, so every tool shares that layer. """ dependencies( @@ -895,13 +895,28 @@ type PythonProject { ["uv", "sync"] + syncFlags(ws) + ["--no-install-workspace", "--no-install-local"], "environment", ) - let mounted = if (mount == null) { synced } else { - synced.withDirectory(mountPath, mount) - } if (with.isEmpty) { - mounted + if (mount == null) { synced } else { synced.withDirectory(mountPath, mount) } } else { - step(mounted, uvRun(with) + ["python", "-c", ""], "environment") + let constraints = "/tmp/dagger-python-constraints.txt" + let constrained = step( + synced, + if (hasFile(ws, "uv.lock")) { + ["uv", "export", "--frozen", "--no-hashes", "--no-emit-project", + "--no-emit-workspace", "--no-emit-local", "--output-file", constraints] + } else { + ["sh", "-c", "uv pip freeze --python .venv/bin/python > " + constraints] + }, + "environment", + ) + let mounted = if (mount == null) { constrained } else { + constrained.withDirectory(mountPath, mount) + } + step( + mounted, + ["uv", "pip", "install", "--python", ".venv/bin/python", "--constraint", constraints] + with, + "environment", + ) } } @@ -936,9 +951,9 @@ type PythonProject { .withDirectory(".", source(ws)) .withWorkdir(path) if (installProject) { - step(sourced, ["uv", "sync"] + syncFlags(ws), "environment") + step(sourced, ["uv", "sync"] + syncFlags(ws) + ["--inexact"], "environment") } else if (hasLocalDependencies(ws)) { - step(sourced, ["uv", "sync"] + syncFlags(ws) + ["--no-install-project"], "environment") + step(sourced, ["uv", "sync"] + syncFlags(ws) + ["--inexact", "--no-install-project"], "environment") } else { sourced } @@ -946,10 +961,10 @@ type PythonProject { """ The start of a `uv run` command for a tool in `env`: no re-sync, and the - extra packages `env` already resolved. + extra packages `env` already installed. """ uvRun(packages: [String!]!): [String!]! { - ["uv", "run", "--no-sync"] + withFlags(packages) + ["uv", "run", "--no-sync"] } """ @@ -982,8 +997,7 @@ type PythonProject { """ `--with` flags naming extra packages for a uv invocation. - A caller runs its own command with the same flags, against the resolution - `env` already made and cached. + Tools installed by `env` need only `uvRun`. """ withFlags(packages: [String!]!): [String!]! { packages.reduce([]) { flags, package => flags + ["--with", package] } diff --git a/pytest/main.dang b/pytest/main.dang index 6bc0abc..7c611db 100644 --- a/pytest/main.dang +++ b/pytest/main.dang @@ -8,9 +8,9 @@ test run is the same layer mypy and ty get. There is no runner probing and no pip path here: this module is uv-based, and a caller who needs something else supplies its own base image. -dagger-pytest-otel, the bundled OpenTelemetry plugin, is resolved alongside -pytest and the project's own dependencies in one uv pass. Installing it over the -top of a finished environment resolves nothing, so a conflict passes unnoticed. +dagger-pytest-otel, the bundled OpenTelemetry plugin, is installed with pytest +under the project's dependency constraints, so a conflict fails while building +the environment. https://dagger.io https://pytest.org From bc1b2b5317da79f84a1e04d5d490538083439d60 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Tue, 27 Oct 2026 07:16:05 +0100 Subject: [PATCH 3/7] Batch project metadata for Python tool checks Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/main.dang | 45 +++++++++++++++++++++++ mypy/main.dang | 67 +++++++++++++++++++++++++---------- pyproject/main.dang | 67 +++++++++++++++++++++++++++++++++++ pytest/main.dang | 34 +++++++++++++----- ty/main.dang | 16 ++++----- uv/main.dang | 40 ++++++++++++++------- 6 files changed, 220 insertions(+), 49 deletions(-) diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index d48182d..7caf684 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -604,6 +604,14 @@ type E2e { A tool runs the version the project pins, and its own default otherwise. """ toolPinCheck(ws: Workspace!): Void @check { + assert( + lib.at(pinnedFixture).checkInputs(ws, "mypy").version == "1.11.2", + "the combined project inputs did not take the locked tool version", + ) + assert( + lib.at(passFixture).checkInputs(ws, "mypy").version == null, + "the combined project inputs invented a tool version", + ) assert( mypy.versionFor(ws, pinnedFixture) == "1.11.2", "mypy did not take the version pinned in uv.lock: " @@ -963,6 +971,20 @@ type E2e { file below the project root, and both checkers take extra arguments. """ typeCheckConfigCheck(ws: Workspace!): Void @check { + let inputs = lib.at(metacharFixture).checkInputs(ws, "mypy", excludeRegex: true) + assert(inputs.hasSources and inputs.skip == false, "the combined inputs lost the project's sources") + assert( + inputs.excludeNestedFlags == ["--exclude", "^sub\\.v2/"], + "the combined inputs did not escape the nested project: " + inputs.excludeNestedFlags.join(" "), + ) + assert( + lib.at(deepFixture).checkInputs(ws, "mypy").hasSources == false, + "the combined inputs found sources in an empty project", + ) + assert( + lib.at(passFixture).checkInputs(ws, "mypy", scope: ["!" + passFixture]).skip, + "the combined inputs ignored the project selection", + ) let configured = mypy.project(ws, mypyFilesFixture) assert(configured.configuresFiles(ws), "mypy did not see the configured files") assert( @@ -972,6 +994,29 @@ type E2e { # scripts/ holds a type error outside the configured files. run(configured.typeCheck(ws)) + let hiddenIni = ws.withNewFile(mypyFilesFixture + "/.mypy.ini", "[mypy]\nignore_missing_imports = true\n") + assert( + mypy.project(hiddenIni, mypyFilesFixture).configuresFiles(hiddenIni) == false, + ".mypy.ini did not take precedence over pyproject.toml", + ) + let ini = hiddenIni.withNewFile(mypyFilesFixture + "/mypy.ini", "[mypy]\nfiles = src\n") + assert( + mypy.project(ini, mypyFilesFixture).configuresFiles(ini), + "mypy.ini did not take precedence over .mypy.ini", + ) + let setup = ws + .withNewFile(mypyFilesFixture + "/pyproject.toml", "[project]\nname = \"configured\"\nversion = \"0.1.0\"\n") + .withNewFile(mypyFilesFixture + "/setup.cfg", "[mypy]\nfiles = src\n") + assert( + mypy.project(setup, mypyFilesFixture).configuresFiles(setup), + "setup.cfg was not read when pyproject.toml had no mypy section", + ) + let emptySection = setup.withNewFile(mypyFilesFixture + "/pyproject.toml", "[tool.mypy]\n") + assert( + mypy.project(emptySection, mypyFilesFixture).configuresFiles(emptySection) == false, + "a mypy section without files fell through to setup.cfg", + ) + let strict = failureOf( mypy(args: ["--strict"]).project(ws, mypyFilesFixture).typeCheck(ws), ) diff --git a/mypy/main.dang b/mypy/main.dang index 432c6bb..c49bba3 100644 --- a/mypy/main.dang +++ b/mypy/main.dang @@ -93,9 +93,7 @@ type Mypy { MypyProjects( paths: lib .rootsOwning(ws, ["*.py"]) - .map { root => mypyProject(root) }.{{path, skip}} - .filter { project => includeSkipped or project.skip == false } - .map { project => project.path }, + .filter { root => includeSkipped or mypyProject(root).skip == false }, tool: self, ) } @@ -207,10 +205,19 @@ type MypyProject { outside the configured scope, or holds no Python source of its own. """ let typeCheckFailure(ws: Workspace!): String { - if (skip or hasSources(ws) == false) { + let inputs = checkInputs(ws, tool.scope) + if (inputs.skip or inputs.hasSources == false) { null } else { - { typeCheckExec(ws).sync; null } rescue { + { + typeCheckExec( + ws, + inputs.version ?? tool.defaultVersion, + filesConfigured(inputs.configKeys.{{exists, hasSection, setsKey}}), + inputs.excludeNestedFlags, + ).sync + null + } rescue { err: Error => err.message.replace(old: "evaluating receiver: ", new: "").replace( old: "reduce function: ", new: "", @@ -219,20 +226,24 @@ type MypyProject { } } - let typeCheckExec(ws: Workspace!): Container! { + let typeCheckExec( + ws: Workspace!, + version: String!, + configured: Boolean!, + excludes: [String!]!, + ): Container! { let project = tool.lib.at(path) - let packages = ["mypy==" + version(ws)] + let packages = ["mypy==" + version] # A project whose config names its files is checked as configured: a path # on the command line would override `files` and check everything else. - let targets = if (configuresFiles(ws)) { [] } else { ["."] } + let targets = if (configured) { [] } else { ["."] } # The environment comes from the library, so the dependency layer # underneath is the same one pytest and the other checker get. # The project itself is not installed: the checker reads first-party code # from the source, so it needs no build backend or compiler. project.step( project.env(ws, with: packages, installProject: false), - project.uvRun(packages) + ["mypy"] + tool.args + targets - + project.excludeNestedFlags(ws, "--exclude", regex: true), + project.uvRun(packages) + ["mypy"] + tool.args + targets + excludes, "mypy", ) } @@ -243,15 +254,35 @@ type MypyProject { and setup.cfg ([mypy]) that configures it, and so does this. """ configuresFiles(ws: Workspace!): Boolean! { - let project = tool.lib.at(path) - if (project.hasFile(ws, "mypy.ini")) { - project.setsKey(ws, "mypy.ini", "mypy", "files") - } else if (project.hasFile(ws, ".mypy.ini")) { - project.setsKey(ws, ".mypy.ini", "mypy", "files") - } else if (project.fileContents(ws, "pyproject.toml").contains("[tool.mypy]")) { - project.setsKey(ws, "pyproject.toml", "tool.mypy", "files") + filesConfigured(checkInputs(ws).configKeys.{{exists, hasSection, setsKey}}) + } + + let filesConfigured( + probes: [{{exists: Boolean!, hasSection: Boolean!, setsKey: Boolean!}}!]!, + ): Boolean! { + if (probes[0].exists == true) { + probes[0].setsKey ?? false + } else if (probes[1].exists == true) { + probes[1].setsKey ?? false + } else if (probes[2].hasSection == true) { + probes[2].setsKey ?? false } else { - project.setsKey(ws, "setup.cfg", "mypy", "files") + probes[3].setsKey ?? false } } + + let checkInputs(ws: Workspace!, scope: [String!]! = ["**"]): PyprojectCheckInputs! { + tool.lib.at(path).checkInputs( + ws, + "mypy", + scope: scope, + configKeys: [ + ["mypy.ini", "mypy", "files"], + [".mypy.ini", "mypy", "files"], + ["pyproject.toml", "tool.mypy", "files"], + ["setup.cfg", "mypy", "files"], + ], + excludeRegex: true, + ) + } } diff --git a/pyproject/main.dang b/pyproject/main.dang index 45c005d..29bddec 100644 --- a/pyproject/main.dang +++ b/pyproject/main.dang @@ -776,6 +776,51 @@ type PythonProject { ws.glob(subpath(relativePath)).isEmpty == false } + """ + Project metadata for a tool run, returned together to avoid a module call + for each source, version, configuration and exclusion probe. Each configKeys + entry names a file, section and key, in that order. + """ + pub checkInputs( + ws: Workspace!, + tool: String!, + scope: [String!]! = ["**"], + sourceGlobs: [String!]! = ["*.py"], + sourcePattern: String! = "", + configKeys: [[String!]!]! = [], + excludeFlag: String! = "--exclude", + excludeRegex: Boolean! = false, + ): CheckInputs! { + let skip = selected(scope) == false + CheckInputs( + skip: skip, + hasSources: if (skip or sourceGlobs.isEmpty) { false } else { + hasOwnFiles(ws, sourceGlobs, pattern: sourcePattern) + }, + version: if (skip) { null } else { toolVersion(ws, tool) }, + configKeys: if (skip) { [] } else { + configKeys.map { probe => + if (probe.length != 3) { + raise "a config key probe must name a file, section and key" + } + let file = probe[0] ?? "" + let section = probe[1] ?? "" + let key = probe[2] ?? "" + ConfigKeyResult( + exists: hasFile(ws, file), + hasSection: fileContents(ws, file).contains("[" + section + "]"), + setsKey: setsKey(ws, file, section, key), + ) + } + }, + hasLockfile: if (skip) { false } else { hasFile(ws, "uv.lock") }, + nestedProjects: if (skip) { [] } else { nestedProjects(ws) }, + excludeNestedFlags: if (skip or excludeFlag == "") { [] } else { + excludeNestedFlags(ws, excludeFlag, regex: excludeRegex) + }, + ) + } + """ Built-in workspace include patterns for this project's own tree. @@ -1214,3 +1259,25 @@ type PythonProject { } } } + +""" +Values a tool needs to select, configure and run a project. +""" +type CheckInputs { + skip: Boolean! + hasSources: Boolean! + version: String + configKeys: [ConfigKeyResult!]! + hasLockfile: Boolean! + nestedProjects: [String!]! + excludeNestedFlags: [String!]! +} + +""" +The presence of a configuration file, section and key. +""" +type ConfigKeyResult { + exists: Boolean! + hasSection: Boolean! + setsKey: Boolean! +} diff --git a/pytest/main.dang b/pytest/main.dang index 7c611db..4f7e396 100644 --- a/pytest/main.dang +++ b/pytest/main.dang @@ -152,9 +152,7 @@ type Pytest { PytestProjects( paths: roots .filter { root => owns(roots, root, dirs) } - .map { root => pytestProject(root, null) }.{{path, skip}} - .filter { project => includeSkipped or project.skip == false } - .map { project => project.path }, + .filter { root => includeSkipped or pytestProject(root, null).skip == false }, testFiles: files, roots: roots, tool: self, @@ -332,10 +330,11 @@ type PytestProject { project is outside the configured scope, or it has no test files of its own. """ let testFailure(ws: Workspace!): String { - if (skip or hasTests(ws) == false) { + let inputs = checkInputs(ws) + if (inputs.skip or inputs.hasSources == false) { null } else { - { testExec(ws, []).sync; null } rescue { + { testExec(ws, [], inputs.version ?? tool.defaultVersion, inputs.nestedProjects).sync; null } rescue { err: Error => err.message.replace(old: "evaluating receiver: ", new: "").replace( old: "reduce function: ", new: "", @@ -349,7 +348,8 @@ type PytestProject { they fail. """ let runFiles(ws: Workspace!, files: [String!]!): Void { - testExec(ws, files).sync rescue { + let inputs = checkInputs(ws) + testExec(ws, files, inputs.version ?? tool.defaultVersion, inputs.nestedProjects).sync rescue { err: Error => raise "pytest failed:\n- " + path + ": " + err .message .replace(old: "evaluating receiver: ", new: "") @@ -362,7 +362,12 @@ type PytestProject { Container that has run pytest in this project: over the named project-relative files, or over the whole project when none are named. """ - let testExec(ws: Workspace!, files: [String!]!): Container! { + let testExec( + ws: Workspace!, + files: [String!]!, + version: String!, + nested: [String!]!, + ): Container! { let project = tool.lib.at(path) # dagger-pytest-otel is mounted and named by path rather than fetched from @@ -370,8 +375,8 @@ type PytestProject { # resolves it with pytest against the project's dependencies while the # environment is built, before any source is mounted. let plugin = if (tool.tracing) { ["/opt/dagger_pytest_otel"] } else { [] } - let packages = ["pytest==" + version(ws)] + plugin - let ignoreNested = project.nestedProjects(ws).map { nested => "--ignore=" + nested } + let packages = ["pytest==" + version] + plugin + let ignoreNested = nested.map { path => "--ignore=" + path } project.step( project.env(ws, with: packages, mount: tool.pytestOtel, mountPath: "/opt/dagger_pytest_otel"), @@ -380,6 +385,17 @@ type PytestProject { nesting: tool.nesting, ) } + + let checkInputs(ws: Workspace!): PyprojectCheckInputs! { + tool.lib.at(path).checkInputs( + ws, + "pytest", + scope: tool.scope, + sourceGlobs: tool.testGlobs, + sourcePattern: tool.testLine, + excludeFlag: "", + ) + } } """ diff --git a/ty/main.dang b/ty/main.dang index ec4f326..cd91d08 100644 --- a/ty/main.dang +++ b/ty/main.dang @@ -95,9 +95,7 @@ type Ty { TyProjects( paths: lib .rootsOwning(ws, ["*.py"]) - .map { root => tyProject(root) }.{{path, skip}} - .filter { project => includeSkipped or project.skip == false } - .map { project => project.path }, + .filter { root => includeSkipped or tyProject(root).skip == false }, tool: self, ) } @@ -209,10 +207,11 @@ type TyProject { outside the configured scope, or holds no Python source of its own. """ let typeCheckFailure(ws: Workspace!): String { - if (skip or hasSources(ws) == false) { + let inputs = tool.lib.at(path).checkInputs(ws, "ty", scope: tool.scope) + if (inputs.skip or inputs.hasSources == false) { null } else { - { typeCheckExec(ws).sync; null } rescue { + { typeCheckExec(ws, inputs.version ?? tool.defaultVersion, inputs.excludeNestedFlags).sync; null } rescue { err: Error => err.message.replace(old: "evaluating receiver: ", new: "").replace( old: "reduce function: ", new: "", @@ -221,17 +220,16 @@ type TyProject { } } - let typeCheckExec(ws: Workspace!): Container! { + let typeCheckExec(ws: Workspace!, version: String!, excludes: [String!]!): Container! { let project = tool.lib.at(path) - let packages = ["ty==" + version(ws)] + let packages = ["ty==" + version] # The environment comes from the library, so the dependency layer # underneath is the same one pytest and the other checker get. # The project itself is not installed: the checker reads first-party code # from the source, so it needs no build backend or compiler. project.step( project.env(ws, with: packages, installProject: false), - project.uvRun(packages) + ["ty", "check"] + tool.args - + project.excludeNestedFlags(ws, "--exclude", regex: false), + project.uvRun(packages) + ["ty", "check"] + tool.args + excludes, "ty", ) } diff --git a/uv/main.dang b/uv/main.dang index ece5d7f..726082a 100644 --- a/uv/main.dang +++ b/uv/main.dang @@ -98,11 +98,9 @@ type Uv { UvProjects( paths: lib .rootsWith(ws, "uv.lock") - .map { root => uvProject(root) }.{{path, skipLock, skipAudit}} - .filter { project => - includeSkipped or project.skipLock == false or project.skipAudit == false - } - .map { project => project.path }, + .filter { root => + includeSkipped or uvProject(root).skipLock == false or uvProject(root).skipAudit == false + }, tool: self, ) } @@ -194,9 +192,7 @@ type UvProjects @collection { Refresh the selected projects' uv.lock. """ lock(ws: Workspace!): Changeset! @generate { - let roots = paths.map { p => project(p) }.{{path, skipLock, locked: hasLockfile(ws)}} - .filter { p => p.skipLock == false and p.locked } - .map { p => p.path } + let roots = paths.filter { p => project(p).shouldLock(ws) } tool.lockChanges(ws, roots) } @@ -258,10 +254,17 @@ type UvProject { outside the configured audit selection. """ let auditFailure(ws: Workspace!): String { - if (skipAudit) { + let inputs = tool.lib.at(path).checkInputs( + ws, + "uv", + scope: tool.audit, + sourceGlobs: [], + excludeFlag: "", + ) + if (inputs.skip) { null } else { - { auditExec(ws).sync; null } rescue { + { auditExec(ws, inputs.hasLockfile).sync; null } rescue { err: Error => err.message.replace(old: "evaluating receiver: ", new: "").replace( old: "reduce function: ", new: "", @@ -274,7 +277,7 @@ type UvProject { Refresh this project's uv.lock. """ lock(ws: Workspace!): Changeset! @generate { - if (skipLock or hasLockfile(ws) == false) { + if (shouldLock(ws) == false) { directory.changes(directory) } else { tool.lockChanges(ws, [path]) @@ -293,13 +296,24 @@ type UvProject { project.step(project.container(ws), ["uv", "lock"], "uv lock") } + let shouldLock(ws: Workspace!): Boolean! { + let inputs = tool.lib.at(path).checkInputs( + ws, + "uv", + scope: tool.lock, + sourceGlobs: [], + excludeFlag: "", + ) + inputs.skip == false and inputs.hasLockfile + } + # Auditing reads the lockfile alone, so it mounts only what `uv sync` reads # and a source edit leaves it cached. - let auditExec(ws: Workspace!): Container! { + let auditExec(ws: Workspace!, locked: Boolean!): Container! { let project = tool.lib.at(path) project.step( tool.lib.base.withWorkdir("/ws").withDirectory(".", project.installInputs(ws)).withWorkdir(path), - ["uv", "audit"] + project.syncFlags(ws) + tool.auditArgs, + ["uv", "audit"] + (if (locked) { ["--locked"] } else { [] }) + tool.auditArgs, "uv audit", ) } From 9d3a91c856bcc6a16df78f44b95070bc6a5dddf5 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Tue, 27 Oct 2026 07:33:51 +0100 Subject: [PATCH 4/7] Avoid recompiling dependencies during project sync Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/main.dang | 27 ++++++++++++++++++++------- pyproject/main.dang | 3 +++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index 7caf684..8bf04f1 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -853,14 +853,27 @@ type E2e { passFixture + "/pyproject.toml", ws.file("/" + passFixture + "/pyproject.toml").contents + "\ndependencies = [\"packaging==25.0\"]\n", ) - project.dependencies(dependencyWs) + let bytecodeCheck = "import importlib.util, pathlib, packaging\n" + + "pyc = pathlib.Path(importlib.util.cache_from_source(packaging.__file__))\n" + + "assert pyc.is_file(), 'dependency bytecode is missing'\n" + + "assert int.from_bytes(pyc.read_bytes()[4:8], 'little') == 3, 'bytecode is not checked-hash'\n" + [project.dependencies(dependencyWs), project.env(dependencyWs)].each { env => + env + .withoutMount("/root/.cache/uv") + .withExec([".venv/bin/python", "-I", "-B", "-c", bytecodeCheck]) + .sync + } + + let editedBuild = ws.withNewFile( + buildFixture + "/src/project_build/__init__.py", + "def packaged() -> str:\n return 'edited'\n", + ) + lib + .project(editedBuild, buildFixture) + .env(editedBuild, with: ["packaging==25.0"]) .withoutMount("/root/.cache/uv") - .withExec([".venv/bin/python", "-I", "-c", - "import importlib.util, pathlib, packaging\n" + - "pyc = pathlib.Path(importlib.util.cache_from_source(packaging.__file__))\n" + - "assert pyc.is_file(), 'dependency bytecode is missing'\n" + - "assert int.from_bytes(pyc.read_bytes()[4:8], 'little') == 3, 'bytecode is not checked-hash'\n", - ]) + .withExec([".venv/bin/python", "-I", "-B", "-c", bytecodeCheck + + "import project_build\nassert project_build.packaged() == 'edited'\n"]) .sync # The project itself does not depend on packaging; the extra does. diff --git a/pyproject/main.dang b/pyproject/main.dang index 29bddec..d3c929f 100644 --- a/pyproject/main.dang +++ b/pyproject/main.dang @@ -991,7 +991,10 @@ type PythonProject { mountPath: String! = "/opt/extra", installProject: Boolean! = true, ): Container! { + # uv sync recompiles all site-packages, including unchanged dependencies. + # Their bytecode is already cached; project code can compile on import. let sourced = dependencies(ws, with: with, mount: mount, mountPath: mountPath) + .withEnvVariable("UV_COMPILE_BYTECODE", "0") .withWorkdir("/ws") .withDirectory(".", source(ws)) .withWorkdir(path) From 5e4ee30ebd1d476526576c2c7c0d5a6d3e56cccc Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Tue, 27 Oct 2026 07:52:33 +0100 Subject: [PATCH 5/7] Respect configured project environments for tools Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/main.dang | 7 +++++++ pyproject/main.dang | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index 8bf04f1..9ef8ce9 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -908,6 +908,13 @@ type E2e { failure.contains("environment failed (uv pip install") and failure.contains("packaging"), "a tool replaced a constrained dependency: " + failure, ) + pyproject(markers: ["pyproject.toml"], base: lib.base.withEnvVariable("UV_PROJECT_ENVIRONMENT", "/opt/venv")) + .project(input, passFixture) + .env(input, with: ["packaging==25.0"]) + .withoutMount("/root/.cache/uv") + .withExec(["/opt/venv/bin/python", "-I", "-B", "-c", bytecodeCheck + + "import sys\nassert sys.prefix == '/opt/venv'\n"]) + .sync } # Dependencies install from the files uv reads, before any source is diff --git a/pyproject/main.dang b/pyproject/main.dang index d3c929f..4445c63 100644 --- a/pyproject/main.dang +++ b/pyproject/main.dang @@ -915,6 +915,10 @@ type PythonProject { if (hasFile(ws, "uv.lock")) { ["--locked"] } else { [] } } + let environmentPython: String! { + (baseImage.envVariable("UV_PROJECT_ENVIRONMENT") ?? ".venv") + "/bin/python" + } + """ Container with this project's dependencies installed, but not the project itself or its local path dependencies, from `installInputs` alone. @@ -950,7 +954,7 @@ type PythonProject { ["uv", "export", "--frozen", "--no-hashes", "--no-emit-project", "--no-emit-workspace", "--no-emit-local", "--output-file", constraints] } else { - ["sh", "-c", "uv pip freeze --python .venv/bin/python > " + constraints] + ["sh", "-c", "uv pip freeze --python \"$1\" > \"$2\"", "sh", environmentPython, constraints] }, "environment", ) @@ -959,7 +963,7 @@ type PythonProject { } step( mounted, - ["uv", "pip", "install", "--python", ".venv/bin/python", "--constraint", constraints] + with, + ["uv", "pip", "install", "--python", environmentPython, "--constraint", constraints] + with, "environment", ) } From 47bde80849bdb7a4380a63a1c180a34f90024a09 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Tue, 27 Oct 2026 07:52:48 +0100 Subject: [PATCH 6/7] Reuse pytest collection discovery during checks Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/main.dang | 12 ++++++++++++ pytest/main.dang | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index 9ef8ce9..7410612 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -1568,6 +1568,18 @@ type E2e { assert(keys.contains(deepFixture) == false, "a project without test files is a key") assert(projects.get(key: passFixture).path == passFixture, "get did not return the project at its key") + let changed = ws.withNewFile(passFixture + "/tests/test_greeting.py", + "raise RuntimeError('previously discovered test executed')\n") + let discoveredFailure = { + projects.get(key: passFixture).test(changed) + "passed" + } rescue { err: Error => err.message } + assert( + discoveredFailure.contains("previously discovered test executed"), + "a collection project searched for its tests again: " + discoveredFailure, + ) + pytest.project(changed, passFixture).test(changed) + projects.subset(keys: [passFixture, nestedFixture, skipFixture]).batch.test(ws) let failures = { projects.subset(keys: [passFixture, testFailFixture, nestedChildFixture]).batch.test(ws) diff --git a/pytest/main.dang b/pytest/main.dang index 4f7e396..4443e1c 100644 --- a/pytest/main.dang +++ b/pytest/main.dang @@ -331,7 +331,8 @@ type PytestProject { """ let testFailure(ws: Workspace!): String { let inputs = checkInputs(ws) - if (inputs.skip or inputs.hasSources == false) { + let sources = if (discovered == null) { inputs.hasSources } else { hasTests(ws) } + if (inputs.skip or sources == false) { null } else { { testExec(ws, [], inputs.version ?? tool.defaultVersion, inputs.nestedProjects).sync; null } rescue { @@ -391,7 +392,7 @@ type PytestProject { ws, "pytest", scope: tool.scope, - sourceGlobs: tool.testGlobs, + sourceGlobs: if (discovered == null) { tool.testGlobs } else { [] }, sourcePattern: tool.testLine, excludeFlag: "", ) From 48e734ddb97f153c8135e73ba65f8a4088660f01 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Tue, 27 Oct 2026 07:52:48 +0100 Subject: [PATCH 7/7] Validate tool requirements after project sync Signed-off-by: Yves Brissaud --- .dagger/modules/e2e/main.dang | 196 +++++++++++++++++++++++++++++ .dagger/modules/e2e/tool_wheels.py | 18 +++ pyproject/check_environment.py | 28 +++++ pyproject/main.dang | 15 ++- 4 files changed, 255 insertions(+), 2 deletions(-) create mode 100644 .dagger/modules/e2e/tool_wheels.py create mode 100644 pyproject/check_environment.py diff --git a/.dagger/modules/e2e/main.dang b/.dagger/modules/e2e/main.dang index 7410612..34be779 100644 --- a/.dagger/modules/e2e/main.dang +++ b/.dagger/modules/e2e/main.dang @@ -917,6 +917,202 @@ type E2e { .sync } + let buildConfig = ws.file("/" + buildFixture + "/pyproject.toml").contents + let conflictingTool = directory + .withNewFile("pyproject.toml", buildConfig + .replace(old: "project-build", new: "conflicting-tool") + .replace(old: "[build-system]", new: "dependencies = [\"packaging<25\"]\n\n[build-system]")) + .withNewFile("src/conflicting_tool/__init__.py", "") + let transitiveTool = directory + .withNewFile("pyproject.toml", buildConfig + .replace(old: "project-build", new: "outer-tool") + .replace(old: "[build-system]", new: "dependencies = [\"conflicting-tool @ file:///opt/extra/inner\"]\n\n[build-system]")) + .withNewFile("src/outer_tool/__init__.py", "") + .withDirectory("inner", conflictingTool) + let compatibleTool = conflictingTool.withNewFile("pyproject.toml", buildConfig + .replace(old: "project-build", new: "conflicting-tool") + .replace(old: "[build-system]", new: "dependencies = [\"packaging>=1\"]\n\n[build-system]")) + [ + "[tool.uv.sources]\npackaging = { path = \"local\" }\n", + "[tool.uv.workspace]\nmembers = [\"local\"]\n\n[tool.uv.sources]\npackaging = { workspace = true }\n", + ].each { sourceConfig => + let localWs = ws + .withNewFile(passFixture + "/pyproject.toml", + ws.file("/" + passFixture + "/pyproject.toml").contents + + "\ndependencies = [\"packaging\"]\n\n" + sourceConfig) + .withNewFile(passFixture + "/local/pyproject.toml", buildConfig + .replace(old: "project-build", new: "packaging") + .replace(old: "0.2.0", new: "25.0")) + .withNewFile(passFixture + "/local/src/packaging/__init__.py", "") + let lockedLocal = localWs.withNewFile( + passFixture + "/uv.lock", + project.dependencies(localWs).file("uv.lock").contents, + ) + let compatibleWs = localWs.withNewFile(passFixture + "/local/pyproject.toml", buildConfig + .replace(old: "project-build", new: "packaging") + .replace(old: "0.2.0", new: "999.0")) + let lockedCompatible = compatibleWs.withNewFile(passFixture + "/uv.lock", + project.dependencies(compatibleWs).file("uv.lock").contents) + [compatibleWs, lockedCompatible].each { input => + project.env(input, with: ["/opt/compatible"], mount: compatibleTool, mountPath: "/opt/compatible") + .withExec([".venv/bin/python", "-I", "-c", + "import importlib.metadata as m\nassert m.version('packaging') == '999.0'\n"]) + .sync + } + [localWs, lockedLocal].each { input => + [true, false].each { installProject => + [conflictingTool, transitiveTool].each { tool => + let failure = { + project.env(input, + with: ["/opt/extra"], mount: tool, + installProject: installProject).sync + "built" + } rescue { err: Error => err.message } + assert( + failure.contains("environment failed (") + and failure.contains("The package `conflicting-tool` requires `packaging<25`"), + "a tool conflicted with an installed local package: " + failure, + ) + } + } + } + } + + let rootWs = ws + .withNewFile(passFixture + "/pyproject.toml", buildConfig + .replace(old: "project-build", new: "packaging") + .replace(old: "0.2.0", new: "25.0")) + .withNewFile(passFixture + "/src/packaging/__init__.py", "") + let lockedRoot = rootWs.withNewFile( + passFixture + "/uv.lock", project.dependencies(rootWs).file("uv.lock").contents, + ) + let wheels = lib.base + .withFile("/tmp/tool_wheels.py", ws.file("/.dagger/modules/e2e/tool_wheels.py")) + .withExec(["python", "/tmp/tool_wheels.py"]) + let wheelName = "conflicting_tool-0.2.0-py3-none-any.whl" + let wheelHash = wheels.withExec(["sha256sum", "/wheels/" + wheelName]).stdout.split(" ").takeFirst(1).join("") + [rootWs, lockedRoot].each { input => + let failure = { + project.env(input, with: ["/opt/extra"], mount: conflictingTool).sync + "built" + } rescue { err: Error => err.message } + assert( + failure.contains("environment failed (") + and failure.contains("The package `conflicting-tool` requires `packaging<25`"), + "installing the root replaced a tool dependency: " + failure, + ) + let pinFailure = { + project.env(input, with: ["packaging==24.2"]).sync + "built" + } rescue { err: Error => err.message } + assert( + pinFailure.contains("environment failed (") + and pinFailure.contains("The requested tools require `packaging==24.2`, but `25.0` is installed"), + "the root silently replaced the requested tool version: " + pinFailure, + ) + let urlFailure = { + project.env(input, + with: ["conflicting-tool @ file:///opt/extra/" + wheelName + "#sha256=" + wheelHash], + mount: wheels.directory("/wheels")).sync + "built" + } rescue { err: Error => err.message } + assert( + urlFailure.contains("environment failed (") + and urlFailure.contains("The package `conflicting-tool` requires `packaging<25`"), + "a hashed wheel URL lost dependency validation: " + urlFailure, + ) + } + + let urlCheck = lib.base + .withEnvVariable("UV_OFFLINE", "1") + .withEnvVariable("UV_NO_INDEX", "1") + .withEnvVariable("UV_PYTHON_DOWNLOADS", "never") + .withDirectory("/wheels", wheels.directory("/wheels")) + .withExec(["uv", "venv", "/tmp/env", "--python", "python3"]) + .withExec(["uv", "pip", "install", "--python", "/tmp/env/bin/python", "--no-deps", + "/wheels/" + wheelName, "/wheels/packaging-25.0-py3-none-any.whl"]) + .withFile("/tmp/check_environment.py", ws.file("/pyproject/check_environment.py")) + .withExec(["/tmp/env/bin/python", "-I", "-B", "/tmp/check_environment.py", + "https://example.invalid/" + wheelName + "#sha256=" + wheelHash], expect: ReturnType.ANY) + assert(urlCheck.exitCode == 1 and urlCheck.stderr.contains( + "The package `conflicting-tool` requires `packaging<25`"), + "a bare hashed wheel URL lost dependency validation: " + urlCheck.stderr) + assert(urlCheck.directory("/tmp/env").glob("**/dagger_tools_*").isEmpty, + "validation left temporary distribution metadata behind") + let missingDependency = urlCheck + .withExec(["uv", "pip", "uninstall", "--python", "/tmp/env/bin/python", "packaging"]) + .withExec(["/tmp/env/bin/python", "-I", "-B", "/tmp/check_environment.py", + "https://example.invalid/" + wheelName + "#sha256=" + wheelHash]) + .withExec(["uv", "--color", "never", "pip", "check", "--python", "/tmp/env/bin/python"], + expect: ReturnType.ANY) + assert(missingDependency.exitCode == 1 and missingDependency.stderr.contains( + "The package `conflicting-tool` requires `packaging<25`, but it's not installed"), + "the missing-package control did not produce uv's expected diagnostic: " + missingDependency.stderr) + + let compatibleRoot = rootWs.withNewFile(passFixture + "/pyproject.toml", buildConfig + .replace(old: "project-build", new: "packaging") + .replace(old: "0.2.0", new: "999.0")) + let lockedCompatibleRoot = compatibleRoot.withNewFile(passFixture + "/uv.lock", + project.dependencies(compatibleRoot).file("uv.lock").contents) + [compatibleRoot, lockedCompatibleRoot].each { input => + project.env(input, with: ["/opt/extra"], mount: compatibleTool) + .withExec([".venv/bin/python", "-I", "-c", + "import importlib.metadata as m\nassert m.version('packaging') == '999.0'\n"]) + .sync + } + + [ + "[tool.uv.sources]\nreviewer-group = { path = \"group\" }\n", + "[tool.uv.workspace]\nmembers = [\"group\"]\n\n[tool.uv.sources]\nreviewer-group = { workspace = true }\n", + ].each { sourceConfig => + let virtualWs = ws + .withNewFile(passFixture + "/pyproject.toml", buildConfig + .replace(old: "[build-system]", new: "dependencies = [\"reviewer-group\"]\n\n[build-system]") + + "\n" + sourceConfig) + .withNewFile(passFixture + "/src/project_build/__init__.py", "VALUE = 'source'\n") + .withNewFile(passFixture + "/group/pyproject.toml", + "[project]\nname = \"reviewer-group\"\nversion = \"1.0\"\n" + + "dependencies = [\"packaging==25.0\"]\n\n[tool.uv]\npackage = false\n") + let lockedVirtual = virtualWs.withNewFile(passFixture + "/uv.lock", + project.dependencies(virtualWs).file("uv.lock").contents) + [virtualWs, lockedVirtual].each { input => + let checked = project.env(input, with: ["packaging==25.0"]) + .withExec([".venv/bin/python", "-I", "-B", "-c", + "import project_build, packaging\nassert project_build.VALUE == 'source'\n"]) + .withExec(["uv", "--color", "never", "pip", "check"], expect: ReturnType.ANY) + assert(checked.exitCode == 1 and checked.stderr.contains( + "The package `project-build` requires `reviewer-group`, but it's not installed"), + "a virtual dependency was not omitted by sync: " + checked.stderr) + } + } + + let pluginWs = ws + .withNewFile(passFixture + "/pyproject.toml", buildConfig + .replace(old: "project-build", new: "Root.App") + + "\n[dependency-groups]\ndev = [\"local-plugin\"]\n\n[tool.uv.sources]\nlocal-plugin = { path = \"plugin\" }\n") + .withNewFile(passFixture + "/root_app.py", "VALUE = 'source'\n") + .withNewFile(passFixture + "/plugin/pyproject.toml", buildConfig + .replace(old: "project-build", new: "local-plugin") + .replace(old: "[build-system]", new: "dependencies = [\"root_app==0.2.0\"]\n\n[build-system]")) + .withNewFile(passFixture + "/plugin/src/local_plugin/__init__.py", "from root_app import VALUE\n") + let lockedPlugin = pluginWs.withNewFile( + passFixture + "/uv.lock", project.dependencies(pluginWs).file("uv.lock").contents, + ) + let quotedPlugin = pluginWs.withNewFile(passFixture + "/pyproject.toml", + pluginWs.file("/" + passFixture + "/pyproject.toml").contents.replace(old: "[project]", new: "[\"project\"]")) + let lockedQuotedPlugin = quotedPlugin.withNewFile(passFixture + "/uv.lock", + project.dependencies(quotedPlugin).file("uv.lock").contents) + [pluginWs, lockedPlugin, quotedPlugin, lockedQuotedPlugin].each { input => + project.env(input, with: ["packaging==25.0"], installProject: false) + .withExec(project.uvRun(["packaging==25.0"]) + ["python", "-c", + "import importlib.metadata as m, re, root_app, local_plugin, packaging\n" + + "assert root_app.VALUE == local_plugin.VALUE == 'source'\n" + + "assert 'root-app' not in {re.sub(r'[-_.]+', '-', d.metadata['Name']).lower() for d in m.distributions()}\n"]) + .sync + run(mypy.project(input, passFixture).typeCheck(input)) + run(ty.project(input, passFixture).typeCheck(input)) + } + # Dependencies install from the files uv reads, before any source is # mounted, so a source edit leaves that layer cached. let edited = ws.withNewFile(passFixture + "/greeting.py", "GREETING = 'edited'\n") diff --git a/.dagger/modules/e2e/tool_wheels.py b/.dagger/modules/e2e/tool_wheels.py new file mode 100644 index 0000000..ffff922 --- /dev/null +++ b/.dagger/modules/e2e/tool_wheels.py @@ -0,0 +1,18 @@ +from pathlib import Path +from zipfile import ZipFile, ZipInfo + +Path('/wheels').mkdir() +for name, version, requirements in [ + ('conflicting_tool', '0.2.0', ['packaging<25']), + ('packaging', '25.0', []), +]: + info = f'{name}-{version}.dist-info' + files = { + f'{info}/METADATA': f'Metadata-Version: 2.1\nName: {name}\nVersion: {version}\n' + + ''.join(f'Requires-Dist: {req}\n' for req in requirements), + f'{info}/WHEEL': 'Wheel-Version: 1.0\nRoot-Is-Purelib: true\nTag: py3-none-any\n', + f'{info}/RECORD': '', + } + with ZipFile(f'/wheels/{name}-{version}-py3-none-any.whl', 'w') as wheel: + for path, contents in files.items(): + wheel.writestr(ZipInfo(path), contents) diff --git a/pyproject/check_environment.py b/pyproject/check_environment.py new file mode 100644 index 0000000..2214800 --- /dev/null +++ b/pyproject/check_environment.py @@ -0,0 +1,28 @@ +from pathlib import Path +import re +import subprocess +import sys +import sysconfig +import tempfile + +requirements = [req for req in sys.argv[1:] if re.match( + r'^[A-Za-z0-9][A-Za-z0-9._-]*\s*(?:\[[^\]]+\]\s*)?(?:\(\s*)?[<>=!~]', req.strip())] +with tempfile.TemporaryDirectory(prefix='dagger_tools_', suffix='x-0.dist-info', dir=sysconfig.get_path('purelib')) as info: + name = re.sub(r'[-_.]+', '-', Path(info).name[:-len('-0.dist-info')]).lower() + Path(info, 'METADATA').write_text('Metadata-Version: 2.1\nName: '+name+'\nVersion: 0\n'+ + ''.join('Requires-Dist: '+req+'\n' for req in requirements)) + Path(info, 'WHEEL').write_text('Wheel-Version: 1.0\nRoot-Is-Purelib: true\nTag: py3-none-any\n') + Path(info, 'RECORD').touch() + check = subprocess.run(['uv', '--color', 'never', 'pip', 'check', '--python', sys.executable], + capture_output=True, text=True) +if check.returncode not in (0, 1): + sys.exit(check.stdout + check.stderr) +problems = [] +for line in (check.stdout + check.stderr).splitlines(): + if not line.startswith('The package '): + continue + requested = line.startswith('The package `'+name+'`') + if requested or re.search(r', but `[^`]+` is installed$', line): + problems.append(line.replace('The package `'+name+'` requires', 'The requested tools require')) +if problems: + sys.exit('\n'.join(problems)) diff --git a/pyproject/main.dang b/pyproject/main.dang index 4445c63..80926b5 100644 --- a/pyproject/main.dang +++ b/pyproject/main.dang @@ -987,6 +987,8 @@ type PythonProject { project's build backend nor a compiler for a native extension, and a source edit rebuilds nothing. Its uv workspace members and path sources are still installed, when it has any, since its imports of them resolve there. + + Installing the project must leave the extra tools' dependencies compatible. """ env( ws: Workspace!, @@ -1002,13 +1004,22 @@ type PythonProject { .withWorkdir("/ws") .withDirectory(".", source(ws)) .withWorkdir(path) - if (installProject) { + let local = hasLocalDependencies(ws) + let installed = if (installProject) { step(sourced, ["uv", "sync"] + syncFlags(ws) + ["--inexact"], "environment") - } else if (hasLocalDependencies(ws)) { + } else if (local) { step(sourced, ["uv", "sync"] + syncFlags(ws) + ["--inexact", "--no-install-project"], "environment") } else { sourced } + if (with.isEmpty == false) { + # Missing dependencies are ignored because sync omits packages deliberately; + # extras-only conflicts are undetected, and requested-version checks skip URLs/paths. + step(installed.withFile("/tmp/check_environment.py", currentModule.source.file("check_environment.py")), + [environmentPython, "-I", "-B", "/tmp/check_environment.py"] + with, "environment") + } else { + installed + } } """