From 96969818c2acd50556b86e4220f0113746b4fd2e Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Fri, 12 Sep 2025 14:18:16 +0200 Subject: [PATCH] use other pip --- cmd/pythonBuild.go | 16 ++++++++-------- pkg/python/pip.go | 15 ++++++++++----- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cmd/pythonBuild.go b/cmd/pythonBuild.go index c40b5f947..0e4a6f76a 100644 --- a/cmd/pythonBuild.go +++ b/cmd/pythonBuild.go @@ -54,10 +54,10 @@ func pythonBuild(config pythonBuildOptions, telemetryData *telemetry.CustomData, } func runPythonBuild(config *pythonBuildOptions, telemetryData *telemetry.CustomData, utils pythonBuildUtils, commonPipelineEnvironment *pythonBuildCommonPipelineEnvironment) error { - virutalEnvironmentPathMap := make(map[string]string) + virtualEnvPathMap := make(map[string]string) // create virtualEnv - if err := createVirtualEnvironment(utils, config, virutalEnvironmentPathMap); err != nil { + if err := createVirtualEnvironment(utils, config, virtualEnvPathMap); err != nil { return err } //TODO: use a defer func to cleanup the virtual environment @@ -70,13 +70,13 @@ func runPythonBuild(config *pythonBuildOptions, telemetryData *telemetry.CustomD if strings.HasSuffix(buildDescriptorFilePath, "pyproject.toml") { // handle pyproject.toml file - if err := python.InstallPip(utils.RunExecutable); err != nil { + if err := python.InstallPip(virtualEnvPathMap["pip"], utils.RunExecutable); err != nil { return fmt.Errorf("failed to upgrade pip: %w", err) } - if err := python.InstallProjectDependencies(utils.RunExecutable); err != nil { + if err := python.InstallProjectDependencies(virtualEnvPathMap["pip"], utils.RunExecutable); err != nil { return fmt.Errorf("failed to install project dependencies: %w", err) } - if err := python.InstallBuild(utils.RunExecutable); err != nil { + if err := python.InstallBuild(virtualEnvPathMap["pip"], utils.RunExecutable); err != nil { return fmt.Errorf("failed to install build module: %w", err) } if err := python.Build(utils.RunExecutable, python.Binary, config.BuildFlags, config.SetupFlags); err != nil { @@ -84,14 +84,14 @@ func runPythonBuild(config *pythonBuildOptions, telemetryData *telemetry.CustomD } } else { // handle legacy setup.py file - if err := buildExecute(config, utils, virutalEnvironmentPathMap); err != nil { + if err := buildExecute(config, utils, virtualEnvPathMap); err != nil { return fmt.Errorf("failed to build python project: %w", err) } } // generate BOM if config.CreateBOM { - if err := runBOMCreationForPy(utils, virutalEnvironmentPathMap, config); err != nil { + if err := runBOMCreationForPy(utils, virtualEnvPathMap, config); err != nil { return fmt.Errorf("BOM creation failed: %w", err) } } @@ -116,7 +116,7 @@ func runPythonBuild(config *pythonBuildOptions, telemetryData *telemetry.CustomD // publish package if config.Publish { - if err := publishWithTwine(config, utils, virutalEnvironmentPathMap); err != nil { + if err := publishWithTwine(config, utils, virtualEnvPathMap); err != nil { return fmt.Errorf("failed to publish: %w", err) } } diff --git a/pkg/python/pip.go b/pkg/python/pip.go index 7d1de8379..d0fe3309c 100644 --- a/pkg/python/pip.go +++ b/pkg/python/pip.go @@ -15,40 +15,45 @@ var ( ) func Install( + binary string, executeFn func(executable string, params ...string) error, module string, version string, ) error { - flags := append([]string{"-m", "pip"}, PipInstallFlags...) + // flags := append([]string{"-m", "pip"}, PipInstallFlags...) + flags := PipInstallFlags if len(version) > 0 { module = fmt.Sprintf("%s==%s", module, version) } flags = append(flags, module) - if err := executeFn(Binary, flags...); err != nil { + if err := executeFn(binary, flags...); err != nil { return fmt.Errorf("failed to install %s: %w", module, err) } return nil } func InstallProjectDependencies( + binary string, executeFn func(executable string, params ...string) error, ) error { log.Entry().Debug("installing project dependencies") - return Install(executeFn, ".", "") + return Install(binary, executeFn, ".", "") } func InstallBuild( + binary string, executeFn func(executable string, params ...string) error, ) error { log.Entry().Debug("installing build") - return Install(executeFn, "build", "") + return Install(binary, executeFn, "build", "") } func InstallPip( + binary string, executeFn func(executable string, params ...string) error, ) error { log.Entry().Debug("updating pip") - return Install(executeFn, "pip", "") + return Install(binary, executeFn, "pip", "") }