Skip to content

Add native Python SDK configuration (python version, uv, base image)#1

Merged
eunomie merged 12 commits into
dagger:mainfrom
eunomie:python-customization
Jun 1, 2026
Merged

Add native Python SDK configuration (python version, uv, base image)#1
eunomie merged 12 commits into
dagger:mainfrom
eunomie:python-customization

Conversation

@eunomie
Copy link
Copy Markdown
Member

@eunomie eunomie commented May 27, 2026

Make Python module customization first-class in the python-sdk module, instead of requiring users to hand-edit pyproject.toml. Three settings are exposed: Python version, uv vs pip, and base image — both at creation time (via init flags) and afterward (via mod ... config commands). All settings persist to the module's pyproject.toml.

Configure at creation

dagger call python-sdk init --name my-module \
    --python-version 3.13 \
    --use-uv=false \
    --base-image python:3.13-slim

All flags are optional. Defaults leave the template untouched (template Python version, uv enabled, no base image override).

Configure an existing module

mod ... config exposes two functions: get and set.

Read the current configuration. Settings not explicitly written to pyproject.toml are reported as null rather than guessed:

dagger call python-sdk mod --path my-module config get

Select a single value:

dagger call python-sdk mod --path my-module config get python-version
dagger call python-sdk mod --path my-module config get use-uv
dagger call python-sdk mod --path my-module config get base-image

Change one or more values at once (returns a Changeset, prompting before writing). Each flag is optional; omitting one leaves that setting untouched:

dagger call python-sdk mod --path my-module config set \
    --python-version 3.13 \
    --use-uv=false \
    --base-image python:3.13-slim

Where it's stored

Setting Location in pyproject.toml
Python version [project].requires-python = ">=X.Y"
uv vs pip [tool.dagger].use-uv (written only when false; absent ⇒ uv)
Base image [tool.dagger].base-image (absent ⇒ SDK default)

How it works

A small TOML-aware Go helper (helpers/pyproject) reads/edits pyproject.toml, preserving unrelated keys and pruning empty tables. Both the init flags and the mod.config command surface drive that single helper, so there is one source of truth for reading and writing config.

Reads never guess: an absent use-uv is reported as unset rather than defaulting to true, so config get distinguishes "not configured" from an explicit choice.

Testing

  • Go unit tests for the helper (helpers/pyproject).
  • e2e checks configCheck and initConfigCheck cover config get (including unset-reported-as-null), config set (multi-value and partial/leave-untouched), single-file-scope edits, and init flag output.

eunomie added 6 commits May 27, 2026 18:03
Add a Go helper that reads and edits a module's pyproject.toml,
preserving unrelated keys. Covers python version (requires-python),
use-uv ([tool.dagger]), and base-image ([tool.dagger]).

Signed-off-by: Yves Brissaud <yves@dagger.io>
Add the command-line front end: get-* print values, set-*/unset-*
edit the file in place.

Signed-off-by: Yves Brissaud <yves@dagger.io>
Add ModConfig with typed readers (pythonVersion/useUv/baseImage) and
mutators (setPythonVersion/setUseUv/setBaseImage/unsetBaseImage),
backed by the pyproject helper. Wire it onto Mod as mod.config.

Signed-off-by: Yves Brissaud <yves@dagger.io>
init gains --python-version, --use-uv, and --base-image. Non-default
flags are applied to the rendered template's pyproject.toml via the
pyproject helper before writing; defaults leave the template untouched.

Signed-off-by: Yves Brissaud <yves@dagger.io>
Add config/app and config/configured fixtures plus configCheck and
initConfigCheck verifying readers, single-file edits, unset round-trip,
and init flag output.

Signed-off-by: Yves Brissaud <yves@dagger.io>
Document init config flags and the mod.config read/write commands.

Signed-off-by: Yves Brissaud <yves@dagger.io>
@eunomie eunomie requested a review from kpenfound May 27, 2026 16:18
@TomChv
Copy link
Copy Markdown
Member

TomChv commented May 27, 2026

Early approval, is that expected though if the module does not load?

@kpenfound
Copy link
Copy Markdown
Contributor

@TomChv if you're referring to the ci checks, yeah I think its expected that it only loads with the workspace build and not 0.21.0

eunomie added 6 commits May 30, 2026 10:34
get-use-uv now prints nothing when [tool.dagger].use-uv is absent so
callers can distinguish an unset value from an explicit choice instead of
guessing the uv default. getUseUv returns (value, ok) accordingly.

Drop the unset-base-image command: the config surface no longer supports
clearing a value back to unset.

Signed-off-by: Yves Brissaud <yves@dagger.io>
Replace the seven config functions (pythonVersion/useUv/baseImage readers
and setPythonVersion/setUseUv/setBaseImage/unsetBaseImage mutators) with
two: config.get and config.set.

config.get returns a ModConfigValues object whose fields are null when the
corresponding setting is not written to pyproject.toml, so unset values are
reported rather than guessed.

config.set takes optional pythonVersion, useUv and baseImage flags and
applies them in one call; omitting a flag leaves that setting untouched.

Signed-off-by: Yves Brissaud <yves@dagger.io>
Update configCheck for the new two-function surface: assert config.get
reports unset values as null, assert a multi-value config.set writes all
three settings, and assert a partial set leaves omitted settings untouched.

Signed-off-by: Yves Brissaud <yves@dagger.io>
Replace the per-field config read/write commands in the README with the
new config get and config set usage.

Signed-off-by: Yves Brissaud <yves@dagger.io>
Signed-off-by: Yves Brissaud <yves@dagger.io>
The pinned polyfill (d6ab640) stamped DAGGER_TRACE_URL=cloud.traceURL
into its workspace-snapshot helper container. Evaluating cloud.traceURL
hits the engine's Cloud.traceURL resolver, which hard-errors with
"no cloud organization configured" when no Dagger Cloud org is set.
This made init (and any changeset-producing call) fail unless the user
had run `dagger login`.

Upstream sdk-sdk e0304c6 ("Remove Dagger Cloud trace dependency from
test rails") dropped that env var. Bump the pin to main (09da957) so
local scaffolding works without a Dagger Cloud org.

Signed-off-by: Yves Brissaud <yves@dagger.io>
@eunomie eunomie merged commit 06b021e into dagger:main Jun 1, 2026
1 check failed
@eunomie eunomie deleted the python-customization branch June 1, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants