Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dagger/modules/e2e/dagger.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "e2e",
"engineVersion": "v1.0.0-0",
"engineVersion": "v1.0.0-beta.26",
"sdk": {
"source": "dang"
},
Expand Down
5 changes: 5 additions & 0 deletions .dagger/modules/e2e/fixtures/naming/app/dagger-module.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "naming-app"

[entrypoint]
kind = "dang"
source = "./sdk/entrypoint"
16 changes: 16 additions & 0 deletions .dagger/modules/e2e/fixtures/naming/app/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[project]
name = "naming-app"
version = "0.1.0"
requires-python = ">=3.14"
dependencies = ["dagger-io", "dagger-clients-core"]

[build-system]
requires = ["uv_build>=0.8.4,<0.14.0"]
build-backend = "uv_build"

[tool.uv.workspace]
members = ["sdk", "clients/core"]

[tool.uv.sources]
dagger-io = { workspace = true }
dagger-clients-core = { workspace = true }
51 changes: 51 additions & 0 deletions .dagger/modules/e2e/fixtures/naming/app/src/naming_app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Declarations the engine names differently on either side of the cut.

HttpFetcher is NamingAppHttpFetcher by the legacy strcase rules and
NamingAppHTTPFetcher by the engine's identifier naming rules, and the Arch
member Arm64 is ARM_64 by the first and ARM64 by the second. A call through
the interface selects the type by its name, so the runtime has to use the
name the engine gave it.

The interface takes no Arch: the engine refuses an own interface whose
function takes an own enum in the module's own session, so the module would
fail to load its schema (core/interface.go, "cannot accept arg ... of
external type from dependency module").
"""

import enum
import typing

import dagger
from dagger import enum_type, function, interface, object_type


@enum_type
class Arch(enum.Enum):
Arm64 = "arm64"


@interface
class HttpFetcher(typing.Protocol):
@function
async def get_url(self, path: str) -> str: ...


@object_type
class HttpClient:
base_url: str = dagger.field()

@function
async def get_url(self, path: str) -> str:
return f"{self.base_url}{path}"


@object_type
class NamingApp:
@function
def http_client(self, base_url: str) -> HttpClient:
return HttpClient(base_url=base_url)

@function
async def fetch(self, fetcher: HttpFetcher, path: str, arch: Arch) -> str:
"""Call through the module's own interface, by the engine's names."""
return f"{await fetcher.get_url(path)} {arch.value}"
5 changes: 5 additions & 0 deletions .dagger/modules/e2e/fixtures/naming/caller/dagger-module.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "naming-caller"

[entrypoint]
kind = "dang"
source = "./sdk/entrypoint"
16 changes: 16 additions & 0 deletions .dagger/modules/e2e/fixtures/naming/caller/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[project]
name = "naming-caller"
version = "0.1.0"
requires-python = ">=3.14"
dependencies = ["dagger-io", "dagger-clients-core"]

[build-system]
requires = ["uv_build>=0.8.4,<0.14.0"]
build-backend = "uv_build"

[tool.uv.workspace]
members = ["sdk", "clients/core"]

[tool.uv.sources]
dagger-io = { workspace = true }
dagger-clients-core = { workspace = true }
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Calls naming-app through its client, so its runtime calls its own interface."""

from dagger import check, function, object_type
from dagger_clients.naming_app import NamingAppArch, naming_app


@object_type
class NamingCaller:
@function
async def fetch(self) -> str:
client = naming_app().http_client(base_url="https://example.com")
# Whichever name the engine gave the member, the client has it.
(arch,) = list(NamingAppArch)
return await naming_app().fetch(fetcher=client, path="/x", arch=arch)

@function
@check
async def fetch_check(self) -> None:
got = await self.fetch()
if got != "https://example.com/x arm64":
msg = f"naming-app's call through its interface returned {got!r}"
raise ValueError(msg)
227 changes: 136 additions & 91 deletions .dagger/modules/e2e/main.dang

Large diffs are not rendered by default.

44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,30 @@ There are three answers, and a new module gets the first:
| `[entrypoint] source = <a path in the module>` | a Dang entrypoint of the user's own, kept as written |
| `[runtime] source = <a ref or path>` | a module runtime, which builds and runs the module itself |

This SDK needs an engine `v1.0.0-beta.26` or later: it reads a scope's
This SDK needs an engine `v1.0.0-beta.26` or later. It reads a scope's
settings through `WorkspaceSDK.scopeSetting`, which
[dagger/dagger#15084](https://github.com/dagger/dagger/pull/15084) adds in that
release. The entrypoint it generates into a module needs an engine
`v1.0.0-beta.18` or later, the first release that loads a module's files
through its entrypoint's `sources` member. An entrypoint runs a module on the
engine's own version, so an entrypoint manifest keeps no `engineVersion`.

On an engine without that field, `dagger module init` and `dagger generate`
fail while they load the SDK, before they write anything. A
generated entrypoint fails to load on an older engine with `field "types":
missing argument "workspace" required by interface`. To stay on an engine from
v1.0.0-beta.14 to v1.0.0-beta.17, pin `v1.1.1`, the last release that runs
there: `dagger module install github.com/dagger/python-sdk@v1.1.1`, and
`dagger.io/sdk/python/entrypoint@v1.1.1` for the shared entrypoint of that
release. An engine older than v1.0.0-beta.14 runs neither release, and needs
an upgrade.
release. It also needs the first release that names identifiers by its naming
rules and answers for them: generation asks it how to spell the Python names of
the schema's identifiers, and a module asks it what it named the module's own
declarations. An entrypoint manifest keeps no `engineVersion` (see "The Dagger
version of a generated entrypoint"). The final config and manifest are staged
before naming or main-object selection, so those answers describe the module
generation actually writes.

The SDK's modules declare `engineVersion` v1.0.0-beta.26. Engines compare
only the base version, so an engine from v1.0.0-beta.18 to v1.0.0-beta.25 does
not refuse them for it: `dagger module init` and `dagger generate` fail while
they load the SDK, before they write anything. To stay on such an engine, pin a
release from before this floor, such as `v1.8.0`:
`dagger module install github.com/dagger/python-sdk@v1.8.0`. To stay on an
engine from v1.0.0-beta.14 to v1.0.0-beta.17, pin `v1.1.1`, the last release
that runs there.

An entrypoint served from elsewhere, such as the shared one this repository
used to serve as `dagger.io/sdk/python/entrypoint@v1`, a pin of it or a fork,
is replaced by the generated entrypoint at the module's next
`dagger generate`. A module moved this way needs an engine `v1.0.0-beta.18` or
later to run, and generating it needs `v1.0.0-beta.26` or later.
`dagger generate`.

Generating a module that has a manifest already keeps the kind it names:

Expand Down Expand Up @@ -131,7 +132,7 @@ for and announces:

The scope setting `targetVersion`, under
`[sdks.python.scopes."<module path>".settings]` in `dagger.toml`, pins the
release, from `v1.0.0-beta.18` to the targeted release;
release, from `v1.0.0-beta.26` to the targeted release;
`dagger module init python --target-version <release>` writes it. Any other
value stops generation before it writes anything, with a message that names
the module and says why.
Expand Down Expand Up @@ -255,9 +256,10 @@ The two declarations reach an engine in different ways:
- `dang.toml`: [dagger/dagger#14902](https://github.com/dagger/dagger/pull/14902),
first released in v1.0.0-beta.26, makes an engine take the module's Dagger
version from the file. Engines up to v1.0.0-beta.25 do not read it. It also
refuses an entrypoint whose imports declare different Dagger versions, and
serves v1.0.0-beta.25 to an entrypoint whose `dang.toml` declares no Dagger
version.
refuses an entrypoint whose imports declare different Dagger versions, so
generation stops with that error, and serves v1.0.0-beta.25, the last release
before the identifier casing cut, to an entrypoint whose `dang.toml` declares
no Dagger version.
- `DAGGER_CLIENT_VERSION`: [dagger/dagger#14881](https://github.com/dagger/dagger/pull/14881),
first released in v1.0.0-beta.22, makes an engine serve that version's view to
the process. Engines up to v1.0.0-beta.21 do not read it.
Expand Down
2 changes: 2 additions & 0 deletions dang.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[imports.Dagger]
dagger = "v1.0.0-beta.26"
5 changes: 2 additions & 3 deletions docs/collections.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Collections

A collection is a set of objects that a module discovers at run time, each
with a unique key. Generating a module with this SDK needs an engine
v1.0.0-beta.26 or later, and the generated entrypoint runs on v1.0.0-beta.18 or
later. The engine serves collections from v1.0.0-beta.15
with a unique key. This SDK needs an engine v1.0.0-beta.26 or later. The
engine serves collections from v1.0.0-beta.15
([dagger/dagger#14221](https://github.com/dagger/dagger/pull/14221)), and
v1.0.0-beta.17 adds the projected types every `dagger call` into a collection
resolves ([dagger/dagger#14447](https://github.com/dagger/dagger/pull/14447))
Expand Down
2 changes: 1 addition & 1 deletion helpers/pyproject/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const pythonFloor = "3.11"

// lastReleaseBelowPythonFloor is the last release of this SDK, whose floor
// was lastReleasePythonFloor. A refusal offers it only to a Python that
// release runs on, as engineRefusal in python-sdk.dang does for engines.
// release runs on.
const (
lastReleaseBelowPythonFloor = "v1.2.0"
lastReleasePythonFloor = "3.10"
Expand Down
2 changes: 0 additions & 2 deletions helpers/render-template/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module render-template

go 1.25.0

require github.com/iancoleman/strcase v0.3.0
2 changes: 0 additions & 2 deletions helpers/render-template/go.sum

This file was deleted.

17 changes: 9 additions & 8 deletions helpers/render-template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"regexp"
"strings"
"text/template"

"github.com/iancoleman/strcase"
)

func main() {
Expand All @@ -28,19 +26,22 @@ func packageName(moduleName string) string {
return strings.ReplaceAll(project, "-", "_")
}

// run renders the template for a module. MODULE_TYPE names the main class:
// the module's type name as the engine will name the module, which the caller
// asks the engine for.
func run(args []string) error {
if len(args) != 3 {
return fmt.Errorf("usage: render-template MODULE_NAME TEMPLATE_DIR OUT_DIR")
if len(args) != 4 {
return fmt.Errorf("usage: render-template MODULE_NAME MODULE_TYPE TEMPLATE_DIR OUT_DIR")
}

moduleName := args[0]
templateDir := args[1]
outDir := args[2]
moduleType := args[1]
templateDir := args[2]
outDir := args[3]
data := map[string]string{
"ModuleName": moduleName,
"ModuleProject": strings.ToLower(moduleName),
"ModuleType": strcase.ToCamel(moduleName),
"ModuleImport": "dagger/" + strcase.ToKebab(moduleName),
"ModuleType": moduleType,
"ModulePackage": packageName(moduleName),
}

Expand Down
2 changes: 1 addition & 1 deletion helpers/render-template/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestRenderedPackageMatchesTheRuntime(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
out := t.TempDir()
if err := run([]string{tc.name, filepath.Join("..", "..", "templates", "default"), out}); err != nil {
if err := run([]string{tc.name, "Main", filepath.Join("..", "..", "templates", "default"), out}); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(filepath.Join(out, "src", tc.pkg, "__init__.py")); err != nil {
Expand Down
65 changes: 52 additions & 13 deletions mod.dang
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,9 @@ type Mod {
if (entrypointMode == "generated") {
let outside = PyprojectHelper().outsidePaths(scoped, rootPath)
checkResourcesLoad(scoped, outside)
let withEntrypoint = scoped.withDirectory("/" + rootPath + "/" + entrypointPath, entrypointDir(scoped, patterns(outside)))
let entrypointDirectory = withEntrypoint.withWorkdir(modulePath(entrypointPath))
let configured = sdkHelpers.loadDangConfig(entrypointDirectory)
.withVersion("2.1")
.withDaggerImport(name: "Dagger", version: targetVersion)
.generate(entrypointDirectory)
entrypointManifest(configured.withWorkdir("."), entrypointPath)
let configured = namedWorkspace(scoped, entrypointPath)
configured.withDirectory("/" + rootPath + "/" + entrypointPath,
entrypointDir(configured, patterns(outside), entrypointPath))
} else if (entrypointMode == "own") {
checkNoResources(PyprojectHelper().outsidePaths(scoped, rootPath))
scoped
Expand All @@ -152,9 +148,9 @@ type Mod {
"""
Refuse a module that asks for an older Python than the SDK runs on before
anything is written: uv would lock it to the SDK's Python, and the runtime
would still build it on the older one, where the install fails. Beside
checkEngine, which refuses the engine: this one reads the module, so only
generation runs it, and config set stays open to fix the module.
would still build it on the older one, where the install fails. It reads
the module, so only generation runs it, and config set stays open to fix
the module.
"""
let checkPython: Void {
let refusal = PyprojectHelper().pythonRefusal(ws.directory("/" + rootPath, include: ["pyproject.toml", ".python-version"]))
Expand Down Expand Up @@ -237,7 +233,9 @@ type Mod {
yet. So the runtime manifest points back at the module being built.
"""
let staging(target: Workspace!, outside: [String!]!): Workspace! {
if (hasEntrypointManifest) {
# The final entrypoint manifest is already staged for naming, even when
# the input module originally used a runtime or had no entrypoint.
if (hasEntrypointManifest or entrypointMode == "generated") {
let loaded = sdkHelpers.moduleManifest(loadToml: ws.file("/" + manifestPath)).withoutEntrypoint
# A static entrypoint manifest holds no runtime, and the engine refuses a
# manifest with neither. Dang, not Python: the engine loads the added
Expand All @@ -261,17 +259,58 @@ type Mod {
"""
The entrypoint the engine loads instead of calling a runtime: the module's
own container renders its types, and the container build travels with it.
The main object, the class that gets the constructor, is the one the engine
takes by its naming of the module the entrypoint serves (namedSource).
"""
let entrypointDir(generated: Workspace!, outside: [String!]!): Directory! {
let entrypointDir(generated: Workspace!, outside: [String!]!, entrypointPath: String!): Directory! {
pythonSdkRuntime
.moduleRuntime(modSource: staging(generated, outside).moduleSource("/" + rootPath), introspectionJson: null)
.installed(
modSource: staging(generated, outside).moduleSource("/" + rootPath),
naming: namedSource(generated, entrypointPath).naming,
)
.withExec(["python", "-m", "dagger.mod", "entrypoint", "--name", moduleName, "--client-version", targetVersion, "--output", entrypointOutput] +
outside.map { pattern => "--outside=" + pattern })
.directory(entrypointOutput)
.withNewFile("build.dang", buildDang)
.withNewFile("workspace_reader.py", currentModule.source.file("runtime/workspace_reader.py").contents)
}

"""
The engine's naming of this module as generation writes it: the source the
static entrypoint is named by (namedSource), or else the module as its
manifest has it.
"""
pub naming: ModuleNaming! {
if (entrypointMode == "generated") {
namedSource(ws, vendorDirName + "/" + entrypointDirName).naming
} else {
ws.moduleSource("/" + rootPath).naming
}
}

"""
The module the engine names once the entrypoint is generated: the manifest
this generation writes, with the entrypoint's directory in place, since the
dang.toml governing it decides the version the module is named by.
"""
let namedSource(target: Workspace!, entrypointPath: String!): ModuleSource! {
namedWorkspace(target, entrypointPath).moduleSource("/" + rootPath)
}

"""
The final manifest and config, before main-object selection or building the
entrypoint. Reuse this workspace in the output so naming never observes the
previous import while the generated module declares a different version.
"""
let namedWorkspace(target: Workspace!, entrypointPath: String!): Workspace! {
let dir = target.withDirectory("/" + modulePath(entrypointPath), directory).withWorkdir(modulePath(entrypointPath))
let configured = sdkHelpers.loadDangConfig(dir)
.withVersion("2.1")
.withDaggerImport(name: "Dagger", version: targetVersion)
.generate(dir)
entrypointManifest(configured.withWorkdir("."), entrypointPath)
}

"""
runtime/build.dang with its reads of this module's source inlined, so the
copy in a generated entrypoint needs nothing but itself and the workspace
Expand Down
Loading