Skip to content

sdk/python: name identifiers via the engine - #14677

Closed
vito wants to merge 4 commits into
naming/5a-go-codegenfrom
naming/5c-python-codegen
Closed

vito wants to merge 4 commits into
naming/5a-go-codegenfrom
naming/5c-python-codegen

Conversation

@vito

@vito vito commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Part 5c/N of the stack splitting #14501 (identifier casing). Plan: #14501 (comment)

Refs #13668

Stacked on #14673.

What it does

The Python SDK now uses the engine's names (Query.formatIdentifiers) instead of guessing word boundaries locally, in three places:

where how it gets names gate
client codegen (gen.py) the codegen introspect --names-out sidecar from #14673 (generate -n names.json, SNAKE:UPPERCASE), mounted by python-client-dev from engine-dev's IntrospectionNames the schema has Query.formatIdentifiers
module codegen (in the runtime) the runtime formats the module schema's names with formatIdentifiers (version: the schema's __schemaVersion) and passes them to codegen as the same names file the schema has Query.formatIdentifiers
module runtime (calls through a module's own interfaces, its enum members) mod/_naming.py asks formatIdentifiers, in batches, before invoking a function of a module that declares interfaces the module's session has formatIdentifiers, i.e. the module is on v1

On schemas without formatIdentifiers, and for names missing from the map, codegen falls back to the old converter. Older schemas therefore generate the same code as before.

What changes in generated code

  • Methods: these get the engine's snake_case name: experimental_with_all_gpus, prerequisite_shas. When the old converter gave a different name (experimental_with_all_gp_us, prerequisite_sh_as), that name stays as a deprecated method that warns and forwards. Most names don't change.
  • Core enums: these are now ValueEnums with SCREAMING_SNAKE members:
    • Each member holds the schema value and is sent by value.
    • The schema's other spellings stay as deprecated aliases, so existing code keeps working: ImageMediaTypes.OCIMediaTypes is an alias of OCI, and FunctionCachePolicy.PerSession is an alias of PER_SESSION.
    • Enum argument defaults use the canonical member, e.g. media_types=ImageMediaTypes.OCI.
  • Dependency module enums keep their member values (f28c41e in the final tree, deferred here from core: name modules with engine/naming from v1.0.0-beta.21 #14669):
    • An enum whose @enumValue holds the module's own values ("ACTIVE value") is generated as before: a plain Enum with members named by schema value, holding the module's value, sent by name. str(DepStatus.ACTIVE) doesn't change, and TypeSuite/TestCustomEnumType covers it.
    • Only core enums (whose @enumValue only ever names another schema value) become ValueEnum.

The runtime moves to v1

sdk/python/runtime moves from engineVersion v0.21.9 to v1.0.0. This gives its session the v1 view, which has formatIdentifiers.

  • Bindings: they are hand-edited to match, as in the final tree:
    • formatIdentifiers with the Casing/AcronymStyle enums;
    • nullable object getters returning (ctx) (*T, error), so Load resolves ModuleSource.SDK before reading Debug;
    • the module's own v1 names.
  • WithSDK: it now takes a context and can fail. Its GraphQL signature is unchanged.
  • Ordering: per ordering constraint 2, this must ship with core: name modules with engine/naming from v1.0.0-beta.21 #14669's engine module naming or after it, never before. An engine that has the API but still uses legacy module naming would make the runtime predict names that don't exist.

Breaking changes (for Python SDK users)

These are for the maintainers to decide on:

  1. Hard break: a core enum's .name changes. A member looked up through a deprecated alias resolves to the canonical member, so ImageMediaTypes.OCIMediaTypes.name == "OCI" and FunctionCachePolicy.PerSession.name == "PER_SESSION". Code that compares or serializes .name sees the new spelling. .value and what goes over the wire don't change.
  2. Core enum classes now extend ValueEnum (a subclass in dagger.client.base) instead of Enum. This only matters to code that inspects the class hierarchy.
  3. Soft (deprecated, still works): the old method names (experimental_with_all_gp_us, prerequisite_sh_as) and enum member spellings (OCIMediaTypes, Gzip, PerSession, ...) emit DeprecationWarning. The plan proposes keeping them through 1.0.
  4. The runtime module's own GraphQL names: PythonSdk → PythonSDK, pythonSdk → pythonSDK, withSdk → withSDK, extraIndexUrl → extraIndexURL, introspectionJson → introspectionJSON. These only affect modules that extend the Python SDK (like the ext-python-sdk fixture, updated here to dagger.PythonSDK). Old spellings still resolve through core: name modules with engine/naming from v1.0.0-beta.21 #14669's module aliases. A Python module that annotates with the old class name (dagger.PythonSdk) has to rename it.

Not in it

  • PR 6 material: the core renames (callID, shortSHA, FunctionCachePolicy DEFAULT/...) and Python's "old schema names" table (codegen/renamed.py, 07a07f7 in the final tree). The client here still selects shortSha, callId, etc. FunctionCachePolicy's wire values stay Default/PerSession/Never, with new DEFAULT/PER_SESSION/NEVER members next to them.
  • The abandoned designs, which aren't ported: identifier words in the schema JSON, the Python word formatter, and __formatIdentifiers.

Testing

  • Checks:
    • python-client/format, lint, python-310/unit, python-313/unit (309 tests, including the new tests/codegen and tests/mod/test_naming.py);
    • python-client/client-library/stale (the regenerated gen.py matches the engine built from this branch).
  • Runtime: go vet and the names_test.go tests. TestPackageNameNormalization fails, but it tests python.go, which this PR doesn't touch, so it looks like it was already failing.
  • Integration tests:
    • TestPython/(TestAltRuntime|TestEnumDefaultValue|TestWithOtherModuleTypes|TestNameOverrides)
    • TestModuleNaming/TestPythonAcronyms
    • TestType/(TestEnumType|TestCustomEnumType)
    • TestInterface/(TestIfaceBasic|TestIfaceCall)/python
  • Not run: the full TestPython suite.

vito added 4 commits October 14, 2026 03:04
Client codegen reads the names the engine formatted from the `codegen
introspect --names-out` sidecar (`generate -n names.json`, SNAKE:UPPERCASE),
and python-client-dev mounts engine-dev's IntrospectionNames for it. Schemas
without Query.formatIdentifiers, and names missing from the map, keep the
legacy converter, so older schemas generate the same code.

With engine-formatted names:

- A method whose legacy-converted name differs (experimental_with_all_gp_us,
  prerequisite_sh_as) keeps that name as a deprecated alias.
- Core enum members are named SCREAMING_SNAKE (ImageMediaTypes.OCI,
  FunctionCachePolicy.PER_SESSION) and hold the schema value. The schema's
  other spellings (OCIMediaTypes, PerSession) stay as deprecated aliases,
  and enum argument defaults use the canonical member.
- Such enums extend the new ValueEnum, which the converter sends by value
  rather than by member name.
- A dependency module's enum whose @enumValue holds the module's own values
  is generated as before (plain Enum, members named by schema value, holding
  the module's value), so str(DepStatus.ACTIVE) keeps its value.

Signed-off-by: Alex Suraci <[email protected]>
Core enums become ValueEnum with SCREAMING_SNAKE members and deprecated
aliases for their legacy spellings; renamed methods keep deprecated aliases
(experimental_with_all_gp_us, prerequisite_sh_as).

Signed-off-by: Alex Suraci <[email protected]>
Calls through a module's own interfaces are built by the runtime, which
predicted the schema names of the interface type, its functions, their
arguments and the module's enum members with a plain case conversion. From
engine version v1.0.0 the engine names module declarations with its naming
rules (get_url is getURL, Ready is READY), so those calls failed.

Before invoking a function of a module that declares interfaces, ask the
engine to format those names (Query.formatIdentifiers, in batches) and use
them for the interface bindings. The API's presence is the gate: the
runtime's session is served at the module's engine version, so older modules
keep the conversion they had.

Interface arguments are now also bound by their Python name, so one renamed
for registration (from_ registers as from) no longer fails.

Signed-off-by: Alex Suraci <[email protected]>
The runtime module moves from engineVersion v0.21.9 to v1.0.0. Its session
gets the v1 view, so module codegen can format the module schema's names:
when that schema has Query.formatIdentifiers, the runtime formats its names
(casing SNAKE, version: the schema's __schemaVersion) and passes them to
codegen as a names file (`-n /names.json`). Older schemas get no names file
and keep the legacy conversion. WithSDK now takes a context and can fail;
its GraphQL signature is unchanged.

Under v1 the module itself is named by engine/naming (PythonSDK, pythonSDK,
withSDK, extraIndexURL, introspectionJSON) and Go codegen returns nullable
objects as (ctx) (*T, error), so Load resolves ModuleSource.SDK before
reading Debug. The bindings are hand-edited to match. The ext-python-sdk
fixture refers to the dependency's class as dagger.PythonSDK.

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Closing: the in-repo SDKs are now legacy. This work will be redone as a PR against github.com/dagger/python-sdk (identifier-casing branch) once the engine side (view-gated naming at v1.0.0-beta.20) lands. The branch is kept for reference.

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.

1 participant