Install the module's package and dependencies
()
| 494 | |
| 495 | // Install the module's package and dependencies |
| 496 | func (m *PythonSdk) WithInstall() *PythonSdk { |
| 497 | // NB: Only enable bytecode compilation in `dagger call` |
| 498 | // (not `dagger init/develop`), to avoid having to remove the .pyc files |
| 499 | // before exporting the module back to the host. |
| 500 | ctr := m.Container.WithEnvVariable("UV_COMPILE_BYTECODE", "1") |
| 501 | |
| 502 | // Support uv.lock for simple and fast project management workflow. |
| 503 | if m.UseUvLock() { |
| 504 | // While best practice is to sync dependencies first with only pyproject.toml and |
| 505 | // uv.lock, user projects can have more required files for a minimally successful |
| 506 | // `uv sync --no-install-project --no-dev`. |
| 507 | // Besides, uv is fast enough that's not too bad to skip this optimization. |
| 508 | m.Container = ctr. |
| 509 | WithExec([]string{"uv", "sync", "--no-dev"}). |
| 510 | // Activate virtualenv to avoid having to prepend `uv run` to the entrypoint. |
| 511 | WithEnvVariable("VIRTUAL_ENV", "$UV_PROJECT_ENVIRONMENT", dagger.ContainerWithEnvVariableOpts{ |
| 512 | Expand: true, |
| 513 | }). |
| 514 | WithEnvVariable("PATH", "$VIRTUAL_ENV/bin:$PATH", dagger.ContainerWithEnvVariableOpts{ |
| 515 | Expand: true, |
| 516 | }) |
| 517 | return m |
| 518 | } |
| 519 | |
| 520 | // Fallback to pip-compile workflow (legacy). |
| 521 | install := []string{"pip", "install", "-e", "./sdk", "-e", "."} |
| 522 | check := []string{"pip", "check"} |
| 523 | |
| 524 | // uv has a compatible API with pip |
| 525 | if m.UseUv() { |
| 526 | // Support requirements.lock. |
| 527 | if m.Discovery.HasFile(PipCompileLock) { |
| 528 | // If there's a lock file, we assume that all the dependencies are |
| 529 | // included in it so we can avoid resolving for them to get a faster |
| 530 | // install. |
| 531 | install = append(install, "--no-deps", "-r", PipCompileLock) |
| 532 | } |
| 533 | // pip compiles by default, but not uv |
| 534 | install = append([]string{"uv"}, install...) |
| 535 | check = append([]string{"uv"}, check...) |
| 536 | } |
| 537 | |
| 538 | m.Container = ctr. |
| 539 | WithExec(install). |
| 540 | WithExec(check) |
| 541 | |
| 542 | return m |
| 543 | } |
no test coverage detected