Add the SDK package to the source directory This includes regenerating the client bindings for the current API schema (codegen).
(introspectionJSON *dagger.File)
| 388 | // This includes regenerating the client bindings for the current API schema |
| 389 | // (codegen). |
| 390 | func (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 |
| 442 | func (m *PythonSdk) WithSource() *PythonSdk { |
no test coverage detected