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

Method WithInstall

sdk/python/runtime/main.go:496–543  ·  view source on GitHub ↗

Install the module's package and dependencies

()

Source from the content-addressed store, hash-verified

494
495// Install the module's package and dependencies
496func (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}

Callers 3

invokeFunction · 0.45
ModuleRuntimeMethod · 0.45
ModuleTypesExpMethod · 0.45

Calls 5

UseUvLockMethod · 0.95
UseUvMethod · 0.95
HasFileMethod · 0.80
WithEnvVariableMethod · 0.45
WithExecMethod · 0.45

Tested by

no test coverage detected