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
30 changes: 29 additions & 1 deletion .dagger/modules/e2e/main.dang
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ type E2e {
let coreInitPath: String! = "clients/core/src/dagger_clients/core/__init__.py"
let clientDepMember: String! = "clients/client-dep"
let clientDepTargetPath: String! = clientDepMember + "/src/dagger_clients/client_dep/_target.py"
let ruffSkip: String! = "extend-exclude = [\"*\"]"
let globalPackage: String! = "dagger_global"

"""
The tree every generated scope has, module or not: the SDK files with no
generated code in them, and core, each a member marked as the SDK's.
generated code in them, and core, each a member marked as the SDK's and
skipped by ruff.
"""
let assertScopeTree(generated: Workspace!, scope: String!): Void {
let root = generated.directory("/" + scope)
Expand All @@ -46,6 +48,8 @@ type E2e {
assert(root.exists(legacyBindingsPath) == false, scope + ": sdk/ still holds generated bindings")
assertContains(root.file(coreMemberFile).contents, "generated = \"core\"", scope + ": clients/core is not marked as core")
assertContains(root.file(coreInitPath).contents, generatedMarkerContents, scope + ": core was not generated")
assertContains(root.file("sdk/ruff.toml").contents, ruffSkip, scope + ": ruff does not skip sdk/")
assertContains(root.file("clients/core/ruff.toml").contents, ruffSkip, scope + ": ruff does not skip clients/core")
let scopeFile = root.file("pyproject.toml").contents
assertContainsAll(scopeFile, [
"[tool.uv.workspace]",
Expand Down Expand Up @@ -191,6 +195,7 @@ type E2e {
let scoped = ws
.withNewDirectory("/" + scope, directory)
.withNewFile("/" + scope + "/keep.txt", "keep\n")
.withNewFile("/" + scope + "/ruff.toml", "line-length = 100\n")
.withWorkdir(scope)
let generated = pythonSdk.generateScope(scoped, isModule: true, name: "scope-init", clients: [])
let changes = generated.withWorkdir(".").changes(scoped.withWorkdir("."))
Expand All @@ -203,6 +208,7 @@ type E2e {
assertAdded(changes, scope + "/" + sdkMemberFile)
assertAdded(changes, scope + "/" + coreInitPath)
assertScopeTree(generated.withWorkdir("."), scope)
assert(generated.file("/" + scope + "/ruff.toml").contents == "line-length = 100\n", "generating a module replaced its ruff.toml")
assert(changes.modifiedPaths.length == 0, "initializing a scope modified existing files: " + changes.modifiedPaths.join(", "))
assert(changes.removedPaths.length == 0, "initializing a scope removed existing files: " + changes.removedPaths.join(", "))
let manifest = changes.layer.file(scope + "/dagger-module.toml").contents
Expand Down Expand Up @@ -402,6 +408,7 @@ type E2e {
"CORE_DIGEST = \"" + coreDigestOf(with, tomlGenerateModulePath) + "\"",
])
assertContains(with.file(member + "/src/dagger_clients/client_dep/__init__.py").contents, "def client_dep(", "the client has no entry function")
assertContains(with.file(member + "/ruff.toml").contents, ruffSkip, "ruff does not skip the client's member")

let scopeDiff = with.file(scopeFilePath).contents
assertContainsAll(scopeDiff, [
Expand All @@ -418,6 +425,27 @@ type E2e {
null
}

"""
ruff, run from the root of a generated module, checks the module's own code
and none of the generated members.
"""
pub generatedRuffSkipCheck(ws: Workspace!): Void @check {
let scope = outputRoot + "/generated-ruff-skip"
let generated = pythonSdk.generateScope(ws.withNewDirectory("/" + scope, directory).withWorkdir(scope), isModule: true, name: "generated-ruff-skip", clients: [])
let files = sdkContainer(ws)
.withDirectory("/mod", generated.directory("/" + scope))
.withWorkdir("/mod")
.withExec(["uv", "run", "--frozen", "--project", "/sdk", "ruff", "check", "--show-files", "."])
.stdout
.split("\n")
.filter { line => line != "" }
.map { line => line.trimPrefix("/mod/") }
let generatedFiles = files.filter { file => file.hasPrefix("sdk/") or file.hasPrefix("clients/") }
assert(generatedFiles.length == 0, "ruff checks generated files: " + generatedFiles.join(", "))
assert(files.filter { file => file.hasPrefix("src/") }.length > 0, "ruff checks no file of src/: " + files.join(", "))
null
}

"""
A local client whose manifest is a symlink generates without importing the
manifest's target into the metadata probe.
Expand Down
2 changes: 2 additions & 0 deletions .dagger/modules/engine-e2e/main.dang
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ type EngineE2e {

pub generateScopeClientsCheck(ws: Workspace!): Void @check { onFloor(ws, "generate-scope-clients-check") }

pub generatedRuffSkipCheck(ws: Workspace!): Void @check { onFloor(ws, "generated-ruff-skip-check") }

pub linkedClientManifestCheck(ws: Workspace!): Void @check { onFloor(ws, "linked-client-manifest-check") }

pub generateScopeStaleTargetCheck(ws: Workspace!): Void @check { onFloor(ws, "generate-scope-stale-target-check") }
Expand Down
14 changes: 9 additions & 5 deletions scope.dang
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ type Scope {

"""
The workspace with the scope generated: sdk/, clients/core and one member
per client written whole, a client that is no longer declared deleted, and
the SDK-owned entries of the scope file set. Everything else is left as it
is.
per client written whole, each with a ruff.toml that keeps ruff out of it,
a client that is no longer declared deleted, and the SDK-owned entries of
the scope file set. Everything else is left as it is.
"""
pub generated: Workspace! {
let existing = ws.directory(root, gitignore: true)
Expand Down Expand Up @@ -209,14 +209,18 @@ type Scope {

"""
A member is written whole, so nothing of an earlier generation survives in
it; merging would keep a file the generator no longer writes.
it; merging would keep a file the generator no longer writes. Its ruff.toml
goes in the member, not the module root, so the author's ruff config stays
untouched.
"""
let replaced(target: Workspace!, rel: String!, files: Directory!): Workspace! {
let abs = memberPath(rel)
let cleared = if (ws.directory(root, gitignore: true).exists(rel)) { target.withoutDirectory(abs) } else { target }
cleared.withDirectory(abs, files)
cleared.withDirectory(abs, files.withNewFile("ruff.toml", generatedRuffConfig))
}

let generatedRuffConfig: String! = "# Rewritten on every generation: do not edit.\nextend-exclude = [\"*\"]\n"

"""
A directory where a member goes, that is not a member, is the user's: the
SDK refuses to write over it. sdk/ from the previous layout has no marker
Expand Down