Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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-module.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source = "dang"

[[dependencies]]
name = "sdk-helpers"
source = "github.com/dagger/sdk-helpers@v1.0.9"
source = "github.com/dagger/sdk-helpers@v1.0.10"

[[dependencies]]
name = "python-sdk-runtime"
Expand Down
2 changes: 2 additions & 0 deletions dagger.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Run `dagger lock update` to refresh the pinned versions.
[["version","2"]]
["","git-latest",["github.com/dagger/alpine"],"refs/heads/main"]
["","git-latest",["github.com/dagger/sdk-helpers",["version","v1.0.10"]],"refs/tags/v1.0.10"]
["","git-latest",["github.com/dagger/sdk-helpers",["version","v1.0.8"]],"refs/tags/v1.0.8"]
["","git-latest",["github.com/dagger/sdk-helpers",["version","v1.0.9"]],"refs/tags/v1.0.9"]
["","git-sha",["github.com/containernetworking/plugins","refs/tags/v1.9.0"],"9b3772e1a7abf93cbb7c6526a28bc0d27b830e02"]
["","git-sha",["github.com/dagger/alpine","main"],"ff6a5f4c28364912d92c00e682dd0bf19f524ef9"]
["","git-sha",["github.com/dagger/alpine","refs/heads/main"],"ff6a5f4c28364912d92c00e682dd0bf19f524ef9"]
["","git-sha",["github.com/dagger/sdk-helpers","refs/tags/v1.0.10"],"3d0cf3b4f6c901b288658421af8f2e3bbaebc663"]
["","git-sha",["github.com/dagger/sdk-helpers","refs/tags/v1.0.8"],"31dafd0c74d9a08faa00c09dce87a5af072e7a9d"]
["","git-sha",["github.com/dagger/sdk-helpers","refs/tags/v1.0.9"],"daffbc01a1b3f3df7b1c417a7d2c83cd06d1bd33"]
["","git-sha",["github.com/libfuse/sshfs","refs/tags/sshfs-3.7.6"],"7a2d988775446ebe7af9b01c99b3b8e86bddb05a"]
Expand Down
21 changes: 0 additions & 21 deletions helpers/pyproject/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ func run(args []string) error {
return runEditScope(path, data, args[2:])
case "set-global-client":
return runSetGlobalClient(path, data, args)
case "remove-table":
return runRemoveTable(path, data, args)
case "get-generated":
fmt.Print(generatedKind(data))
return nil
Expand Down Expand Up @@ -211,25 +209,6 @@ func (r *repeated) Set(v string) error {
return nil
}

// runRemoveTable cuts one table out of a file, and leaves the file alone
// when it has no such table.
//
// usage: pyproject remove-table <file> <table>
func runRemoveTable(path string, data []byte, args []string) error {
name, err := value(args)
if err != nil {
return err
}
out, err := removeTable(data, name)
if err != nil {
return err
}
if string(out) == string(data) {
return nil
}
return os.WriteFile(path, out, 0o644)
}

func value(args []string) (string, error) {
if len(args) < 3 {
return "", fmt.Errorf("%s requires a value", args[0])
Expand Down
15 changes: 0 additions & 15 deletions helpers/pyproject/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,3 @@ global-client = true
})
}
}

func TestRunRemoveTable(t *testing.T) {
src := "name = 'demo'\n\n[entrypoint]\nkind = \"module\"\nsource = \"../runtime\"\n\n[runtime]\nsource = \"python\"\n"
p := writeTemp(t, src)
if err := run([]string{"remove-table", p, "entrypoint"}); err != nil {
t.Fatalf("remove-table: %v", err)
}
want := "name = 'demo'\n\n[runtime]\nsource = \"python\"\n"
if data, _ := os.ReadFile(p); string(data) != want {
t.Errorf("got:\n%s\nwant:\n%s", data, want)
}
if err := run([]string{"remove-table", p}); err == nil {
t.Error("expected an error when the table is missing")
}
}
17 changes: 0 additions & 17 deletions helpers/pyproject/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,23 +491,6 @@ func (d *document) replace(start, end int, with string) {
d.text = d.text[:start] + with + d.text[end:]
}

// removeTable cuts one table, its header and body up to the next header, out
// of a file the user wrote, and keeps every other byte. The result is parsed
// back, so a layout the line model misreads fails here instead of reaching
// the caller as a different file.
func removeTable(src []byte, name string) ([]byte, error) {
d := &document{text: string(src)}
sec := d.section(name)
if sec == nil || sec.headerStart < 0 {
return src, nil
}
d.replace(sec.headerStart, sec.bodyEnd, "")
if _, err := load([]byte(d.text)); err != nil {
return nil, fmt.Errorf("removing [%s] leaves a file that is not TOML: %w", name, err)
}
return []byte(d.text), nil
}

func quote(s string) string {
return strconv.Quote(s)
}
Expand Down
34 changes: 0 additions & 34 deletions helpers/pyproject/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,37 +594,3 @@ dagger-io = { workspace = true }
t.Errorf("got:\n%s\nwant:\n%s", got, want)
}
}

func TestRemoveTableKeepsEveryOtherByte(t *testing.T) {
for name, tc := range map[string]struct {
src string
want string
}{
"between tables": {
"name = \"demo\" # the user's comment\nengineVersion = 'v1.0.0'\n\n[entrypoint]\nkind = \"module\"\nsource = \"../runtime\"\n\n[runtime]\nsource = \"python\"\n",
"name = \"demo\" # the user's comment\nengineVersion = 'v1.0.0'\n\n[runtime]\nsource = \"python\"\n",
},
"last, with a quoted header": {
"name = \"demo\"\n\n[ \"entrypoint\" ] # static\nkind = \"dang\"\nsource = \"./sdk/entrypoint\"\n",
"name = \"demo\"\n\n",
},
"a header inside a multiline string is no table": {
"name = \"demo\"\nnotes = \"\"\"\n[entrypoint]\nkind = \"dang\"\n\"\"\"\n\n[entrypoint]\nkind = \"module\"\n",
"name = \"demo\"\nnotes = \"\"\"\n[entrypoint]\nkind = \"dang\"\n\"\"\"\n\n",
},
"no such table": {
"name = \"demo\"\n\n[runtime]\nsource = \"python\"\n",
"name = \"demo\"\n\n[runtime]\nsource = \"python\"\n",
},
} {
t.Run(name, func(t *testing.T) {
got, err := removeTable([]byte(tc.src), "entrypoint")
if err != nil {
t.Fatal(err)
}
if string(got) != tc.want {
t.Errorf("got:\n%s\nwant:\n%s", got, tc.want)
}
})
}
}
3 changes: 1 addition & 2 deletions mod.dang
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ type Mod {
"""
let staging(target: Workspace!, outside: [String!]!): Workspace! {
if (hasEntrypointManifest) {
let staged = ManifestToml(ws.file("/" + manifestPath).contents).withoutEntrypoint
let loaded = sdkHelpers.moduleManifest(loadToml: staged)
let loaded = sdkHelpers.moduleManifest(loadToml: ws.file("/" + manifestPath)).withoutEntrypoint
# A static entrypoint manifest holds no runtime to fall back on.
let runnable = if (manifestConfig.fields.contains("runtime")) {
loaded
Expand Down
44 changes: 5 additions & 39 deletions python-sdk.dang
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,21 @@ type PythonSdk {
# SDK writes is not, nor one served from elsewhere, nor none at all.
let usersEntrypoint = toml.entrypointKind == "dang" and ours == false and isOwnEntrypointSource(ws, scope, toml.entrypointSource)
if (keepsItsRuntime(config)) {
sdkHelpers.moduleManifest(loadToml: withoutReplacedEntrypoint(ws, scope, manifest))
# checkOneRunner refuses an entrypoint beside this runtime, so none is loaded.
sdkHelpers.moduleManifest(loadToml: manifest)
} else if (legacyRuntime or (needsRuntimeSettings(config) and usersEntrypoint == false)) {
# Moved onto the runtime this SDK publishes, with the version the
# generator reads core in; what only a runtime can honour stays as
# written. Inline at each site: sdk-helpers' type names change with its
# own declared engineVersion (SdkHelpers… vs SDKHelpers… from the
# v1.0.0-beta.22 naming rules), so this module must not spell them.
sdkHelpers.moduleManifest(loadToml: withoutAnyEntrypoint(manifest))
sdkHelpers.moduleManifest(loadToml: manifest).withoutEntrypoint
.withLegacyRuntime(runtime: sdkRuntimeSource, engineVersion: sdkEngineVersion)
} else if (ours) {
# This SDK's entrypoint manifest holds nothing a loaded one keeps.
sdkHelpers.moduleManifest.withDangEntrypoint(source: staticEntrypointSource)
} else {
let loaded = sdkHelpers.moduleManifest(loadToml: withoutReplacedEntrypoint(ws, scope, manifest))
let loaded = sdkHelpers.moduleManifest(loadToml: manifest)
EntrypointManifest(config, "dagger-module.toml").checkEntrypointOnly
let entrypointed = if (usersEntrypoint) {
loaded
Expand Down Expand Up @@ -438,33 +439,6 @@ type PythonSdk {
null
}

"""
The manifest without any entrypoint table, for a module moving to a runtime:
the engine follows an entrypoint over a runtime, so one left behind would
take every call.
"""
let withoutAnyEntrypoint(manifest: File!): File! {
let toml = ManifestToml(manifest.contents)
if (toml.hasEntrypoint) { toml.withoutEntrypoint } else { manifest }
}

"""
Drop an entrypoint table generation replaces, before the manifest is read:
a module-kind one an earlier SDK wrote for its runtime module, which an
engine that loads manifest version 2 rejects, or a Dang one served from
elsewhere. sdk-helpers keeps every table it loads with no way to clear
one, so the table goes here instead. A Dang entrypoint in the user's files
is kept.
"""
let withoutReplacedEntrypoint(ws: Workspace!, scope: String!, manifest: File!): File! {
let toml = ManifestToml(manifest.contents)
if (toml.hasEntrypoint == false or (toml.entrypointKind == "dang" and isOwnEntrypointSource(ws, scope, toml.entrypointSource))) {
manifest
} else {
toml.withoutEntrypoint
}
}

"""
Whether an entrypoint source is a path in the module, as the engine's
classifySource reads one: a source that starts with "." or "/" is a path,
Expand Down Expand Up @@ -950,8 +924,7 @@ type PythonSdk {
A dagger-module.toml, read for its entrypoint table.

Values are read with a TOML parser, because the manifest is the user's
content: quoting, spacing and key order are theirs. The pyproject helper
removes the table and keeps every other byte as it was.
content: quoting, spacing and key order are theirs.
"""
type ManifestToml {
pub toml: String!
Expand All @@ -974,13 +947,6 @@ type ManifestToml {
entrypointValue("source")
}

"""The manifest with its entrypoint table removed."""
pub withoutEntrypoint: File! {
PyprojectHelper().withoutTable(directory.withNewFile(fileName, toml).file(fileName), "entrypoint")
}

let fileName: String! = "dagger-module.toml"

let config: JSONValue! {
json.withContents((JSON.encode(TOML.decode(toml)) :: Dagger.JSON!))
}
Expand Down
8 changes: 0 additions & 8 deletions scope.dang
Original file line number Diff line number Diff line change
Expand Up @@ -843,14 +843,6 @@ type PyprojectHelper {
if (value == "true") { true } else if (value == "false") { false } else { null }
}

"""
The file with one table cut out and every other byte kept.
"""
pub withoutTable(file: File!, table: String!): File! {
let at = "/work/" + file.name
tool.withFile(at, file).withExec(["pyproject", "remove-table", at, table]).file(at)
}

"""
Why a module directory asks for a Python older than this SDK runs on, or
empty when it does not.
Expand Down