MCPcopy Index your code
hub / github.com/dagger/dagger / WithSDK

Method WithSDK

sdk/python/runtime/main.go:390–439  ·  view source on GitHub ↗

Add the SDK package to the source directory This includes regenerating the client bindings for the current API schema (codegen).

(introspectionJSON *dagger.File)

Source from the content-addressed store, hash-verified

388// This includes regenerating the client bindings for the current API schema
389// (codegen).
390func (m *PythonSdk) WithSDK(introspectionJSON *dagger.File) *PythonSdk {
391 if m.VendorPath != "" {
392 src := m.SdkSourceDir
393 // If not vendoring we don't care to remove this
394 if m.Discovery.SdkHasFile("dist/") {
395 src = src.WithoutDirectory("dist")
396 }
397 m.AddDirectory(m.VendorPath, src)
398 }
399
400 // Allow empty introspection to facilitate debugging the container with a
401 // `dagger call module-runtime terminal` command.
402 if introspectionJSON != nil {
403 ctr := m.Container
404 cmd := []string{"codegen"}
405
406 // When not using the bundled codegen executable we can revert to executing directly
407 if m.Discovery.SdkHasFile("dist/codegen") {
408 ctr = ctr.
409 WithMountedCache("/root/.shiv", dag.CacheVolume("shiv")).
410 WithMountedFile("/usr/local/bin/codegen", m.SdkSourceDir.File("dist/codegen"))
411 } else {
412 ctr = ctr.
413 WithWorkdir("/sdk").
414 WithMountedDirectory("", m.SdkSourceDir)
415 cmd = []string{
416 "uv", "run", "--isolated", "--frozen", "--package", "codegen",
417 "python", "-m", "codegen",
418 }
419 }
420
421 genFile := ctr.
422 // mounted schema as late as possible because it varies more often
423 WithMountedFile(SchemaPath, introspectionJSON).
424 WithExec(append(cmd, "generate", "-i", SchemaPath, "-o", "/gen.py")).
425 File("/gen.py")
426
427 genPath := UserGenPath
428
429 // For now, patch vendored client library with generated bindings.
430 // TODO: Always generate outside library, even if vendored.
431 if m.VendorPath != "" {
432 genPath = path.Join(m.VendorPath, SDKGenPath)
433 }
434
435 m.AddFile(genPath, genFile)
436 }
437
438 return m
439}
440
441// Add the module's source code
442func (m *PythonSdk) WithSource() *PythonSdk {

Callers 2

CommonMethod · 0.95
invokeFunction · 0.45

Calls 11

AddDirectoryMethod · 0.95
AddFileMethod · 0.95
SdkHasFileMethod · 0.80
FileMethod · 0.65
WithoutDirectoryMethod · 0.45
WithMountedFileMethod · 0.45
WithMountedCacheMethod · 0.45
CacheVolumeMethod · 0.45
WithMountedDirectoryMethod · 0.45
WithWorkdirMethod · 0.45
WithExecMethod · 0.45

Tested by

no test coverage detected