diff --git a/sdks/python/container/boot.go b/sdks/python/container/boot.go index 847325d4f83c..1be1268a4465 100644 --- a/sdks/python/container/boot.go +++ b/sdks/python/container/boot.go @@ -155,6 +155,12 @@ func launchSDKProcess() error { logger.Fatalf(ctx, "Failed to convert pipeline options: %v", err) } + pipNoBuildIsolation = false + if strings.Contains(options, "pip_no_build_isolation") { + pipNoBuildIsolation = true + logger.Printf(ctx, "Disabled build isolation when installing packages with pip") + } + // (2) Retrieve and install the staged packages. // // No log.Fatalf() from here on, otherwise deferred cleanups will not be called! diff --git a/sdks/python/container/piputil.go b/sdks/python/container/piputil.go index d6250ad2fdcd..1faf8421a02d 100644 --- a/sdks/python/container/piputil.go +++ b/sdks/python/container/piputil.go @@ -32,6 +32,11 @@ import ( "github.com/apache/beam/sdks/v2/go/pkg/beam/util/execx" ) +var ( + // Whether to append "--no-build-isolation" flag to pip install command + pipNoBuildIsolation bool +) + const pipLogFlushInterval time.Duration = 15 * time.Second const unrecoverableURL string = "https://beam.apache.org/documentation/sdks/python-unrecoverable-errors/index.html#pip-dependency-resolution-failures" @@ -112,6 +117,9 @@ func pipInstallPackage(ctx context.Context, logger *tools.Logger, files []string // installed if necessary. This achieves our goal outlined above. args := []string{"-m", "pip", "install", "--no-cache-dir", "--disable-pip-version-check", "--upgrade", "--force-reinstall", "--no-deps", filepath.Join(dir, packageSpec)} + if pipNoBuildIsolation { + args = append(args, "--no-build-isolation") + } err := execx.ExecuteEnvWithIO(nil, os.Stdin, bufLogger, bufLogger, pythonVersion, args...) if err != nil { bufLogger.FlushAtError(ctx) @@ -120,6 +128,9 @@ func pipInstallPackage(ctx context.Context, logger *tools.Logger, files []string bufLogger.FlushAtDebug(ctx) } args = []string{"-m", "pip", "install", "--no-cache-dir", "--disable-pip-version-check", filepath.Join(dir, packageSpec)} + if pipNoBuildIsolation { + args = append(args, "--no-build-isolation") + } err = execx.ExecuteEnvWithIO(nil, os.Stdin, bufLogger, bufLogger, pythonVersion, args...) if err != nil { bufLogger.FlushAtError(ctx) @@ -131,6 +142,9 @@ func pipInstallPackage(ctx context.Context, logger *tools.Logger, files []string // Case when we do not perform a forced reinstall. args := []string{"-m", "pip", "install", "--no-cache-dir", "--disable-pip-version-check", filepath.Join(dir, packageSpec)} + if pipNoBuildIsolation { + args = append(args, "--no-build-isolation") + } err := execx.ExecuteEnvWithIO(nil, os.Stdin, bufLogger, bufLogger, pythonVersion, args...) if err != nil { bufLogger.FlushAtError(ctx)