Skip to content

Commit

Permalink
feat: add ability to pass flags to setup.py in pythonBuild step (#5235)
Browse files Browse the repository at this point in the history
  • Loading branch information
phgermanov authored Jan 15, 2025
1 parent fb23269 commit 6dfccc5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/pythonBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func pythonBuild(config pythonBuildOptions, telemetryData *telemetry.CustomData,
}

func runPythonBuild(config *pythonBuildOptions, telemetryData *telemetry.CustomData, utils pythonBuildUtils, commonPipelineEnvironment *pythonBuildCommonPipelineEnvironment) error {

pipInstallFlags := []string{"install", "--upgrade"}
virutalEnvironmentPathMap := make(map[string]string)

Expand Down Expand Up @@ -106,10 +105,11 @@ func runPythonBuild(config *pythonBuildOptions, telemetryData *telemetry.CustomD
}

func buildExecute(config *pythonBuildOptions, utils pythonBuildUtils, pipInstallFlags []string, virutalEnvironmentPathMap map[string]string) error {

var flags []string
flags = append(flags, config.BuildFlags...)
flags = append(flags, "setup.py", "sdist", "bdist_wheel")
flags = append(flags, "setup.py")
flags = append(flags, config.SetupFlags...)
flags = append(flags, "sdist", "bdist_wheel")

log.Entry().Info("starting building python project:")
err := utils.RunExecutable(virutalEnvironmentPathMap["python"], flags...)
Expand Down
13 changes: 12 additions & 1 deletion cmd/pythonBuild_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions cmd/pythonBuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,34 @@ func TestRunPythonBuild(t *testing.T) {
assert.Equal(t, []string{"--e", "--output", "bom-pip.xml", "--format", "xml", "--schema-version", "1.4"}, utils.ExecMockRunner.Calls[4].Params)
})
}

func TestPythonBuildExecute(t *testing.T) {
t.Run("Test build with flags", func(t *testing.T) {
config := pythonBuildOptions{
BuildFlags: []string{"--verbose"},
SetupFlags: []string{"egg_info", "--tag-build=pr13"},
VirutalEnvironmentName: "venv",
}

utils := pythonBuildMockUtils{
ExecMockRunner: &mock.ExecMockRunner{},
}

virutalEnvironmentPathMap := map[string]string{
"python": "python",
}

err := buildExecute(&config, &utils, []string{}, virutalEnvironmentPathMap)

assert.NoError(t, err)
assert.Equal(t, "python", utils.ExecMockRunner.Calls[0].Exec)
assert.Equal(t, []string{
"--verbose",
"setup.py",
"egg_info",
"--tag-build=pr13",
"sdist",
"bdist_wheel",
}, utils.ExecMockRunner.Calls[0].Params)
})
}
9 changes: 8 additions & 1 deletion resources/metadata/pythonBuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ spec:
params:
- name: buildFlags
type: "[]string"
description: Defines list of build flags to be used.
description: Defines list of build flags passed to python binary.
scope:
- PARAMETERS
- STAGES
- STEPS
- name: setupFlags
type: "[]string"
description: Defines list of flags passed to setup.py.
scope:
- PARAMETERS
- STAGES
Expand Down

0 comments on commit 6dfccc5

Please sign in to comment.