Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions sdks/python/container/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"os/signal"
"path/filepath"
"regexp"
"slices"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -116,6 +117,37 @@ func main() {
}
}

// The json string of pipeline options is in the following format.
// We only focus on experiments here.
//
// {
// "display_data": [
// {...},
// ],
// "options": {
// ...
// "experiments": [
// ...
// ],
// }
// }
type PipelineOptionsData struct {
Options OptionsData `json:"options"`
}

type OptionsData struct {
Experiments []string `json:"experiments"`
}

func getExperiments(options string) []string {
var opts PipelineOptionsData
err := json.Unmarshal([]byte(options), &opts)
if err != nil {
return nil
}
return opts.Options.Experiments
}

func launchSDKProcess() error {
ctx := grpcx.WriteWorkerID(context.Background(), *id)

Expand Down Expand Up @@ -155,6 +187,13 @@ func launchSDKProcess() error {
logger.Fatalf(ctx, "Failed to convert pipeline options: %v", err)
}

experiments := getExperiments(options)
Copy link
Contributor

@tvalentyn tvalentyn Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think there might be a better home for the getExperiments helper than boot.go?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe in github.com/apache/beam/sdks/v2/go/pkg/beam/util/optionsx ?

Overtime people might add other helpers like this

def lookup_experiment(self, key, default=None):
, and use it in other boot.go files.

Copy link
Collaborator Author

@shunping shunping Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Let's do that in a separate PR. We will do another round of refactoring on other boot.go in there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, I think we may put that into https://github.com/apache/beam/blob/master/sdks/go/container/tools/pipeline_options.go.

The parsing of pipeline options in json format seems to be only used in boot.go for different SDKs.

pipNoBuildIsolation = false
if slices.Contains(experiments, "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!
Expand Down
14 changes: 14 additions & 0 deletions sdks/python/container/piputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading