Skip to content

Commit 4ed2120

Browse files
authored
refactor: turn version environment variables into constants (#90)
* refactor(pip): make a constant out of BP_PIP_VERSION * refactor(pipenv): make a constant out of BP_PIPENV_VERSION * refactor(pixi): make a constant out of BP_PIXI_VERSION * refactor(uv): make a constant out of BP_UV_VERSION * refactor(poetry): make a constant out of BP_POETRY_VERSION And also fix the priorities that was pointing to pip * refactor(miniconda): make a constant out of BP_MINICONDA_VERSION
1 parent 1b8138b commit 4ed2120

24 files changed

Lines changed: 75 additions & 57 deletions

integration/installers/miniconda_versions_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
. "github.com/paketo-buildpacks/occam/matchers"
1818

1919
integration_helpers "github.com/paketo-buildpacks/python-installers/integration"
20+
"github.com/paketo-buildpacks/python-installers/pkg/installers/miniconda"
2021
)
2122

2223
func minicondaTestVersions(t *testing.T, context spec.G, it spec.S) {
@@ -81,7 +82,7 @@ func minicondaTestVersions(t *testing.T, context spec.G, it spec.S) {
8182
settings.Buildpacks.PythonInstallers.Online,
8283
settings.Buildpacks.BuildPlan.Online,
8384
).
84-
WithEnv(map[string]string{"BP_MINICONDA_VERSION": firstMinicondaVersion}).
85+
WithEnv(map[string]string{miniconda.EnvVersion: firstMinicondaVersion}).
8586
Execute(name, source)
8687
Expect(err).ToNot(HaveOccurred(), firstLogs.String)
8788

@@ -110,7 +111,7 @@ func minicondaTestVersions(t *testing.T, context spec.G, it spec.S) {
110111
settings.Buildpacks.PythonInstallers.Online,
111112
settings.Buildpacks.BuildPlan.Online,
112113
).
113-
WithEnv(map[string]string{"BP_MINICONDA_VERSION": secondMinicondaVersion}).
114+
WithEnv(map[string]string{miniconda.EnvVersion: secondMinicondaVersion}).
114115
Execute(name, source)
115116
Expect(err).ToNot(HaveOccurred(), secondLogs.String)
116117

integration/installers/pip_layer_reuse_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
. "github.com/paketo-buildpacks/occam/matchers"
1919

2020
integration_helpers "github.com/paketo-buildpacks/python-installers/integration"
21+
"github.com/paketo-buildpacks/python-installers/pkg/installers/pip"
2122
)
2223

2324
func pipTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
@@ -160,7 +161,7 @@ func pipTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
160161
settings.Buildpacks.PythonInstallers.Online,
161162
settings.Buildpacks.BuildPlan.Online,
162163
).
163-
WithEnv(map[string]string{"BP_PIP_VERSION": dependencies[0].Version}).
164+
WithEnv(map[string]string{pip.EnvVersion: dependencies[0].Version}).
164165
Execute(name, source)
165166
Expect(err).ToNot(HaveOccurred(), logs.String)
166167

@@ -179,7 +180,7 @@ func pipTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
179180
settings.Buildpacks.PythonInstallers.Online,
180181
settings.Buildpacks.BuildPlan.Online,
181182
).
182-
WithEnv(map[string]string{"BP_PIP_VERSION": dependencies[1].Version}).
183+
WithEnv(map[string]string{pip.EnvVersion: dependencies[1].Version}).
183184
Execute(name, source)
184185
Expect(err).ToNot(HaveOccurred(), logs.String)
185186

integration/installers/pipenv_layer_reuse_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
. "github.com/paketo-buildpacks/occam/matchers"
2020

2121
integration_helpers "github.com/paketo-buildpacks/python-installers/integration"
22+
"github.com/paketo-buildpacks/python-installers/pkg/installers/pipenv"
2223
)
2324

2425
func pipenvTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
@@ -143,7 +144,7 @@ func pipenvTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
143144
settings.Buildpacks.PythonInstallers.Online,
144145
settings.Buildpacks.BuildPlan.Online,
145146
).
146-
WithEnv(map[string]string{"BP_PIPENV_VERSION": dependencies[0].Version}).
147+
WithEnv(map[string]string{pipenv.EnvVersion: dependencies[0].Version}).
147148
Execute(name, source)
148149
Expect(err).ToNot(HaveOccurred(), logs.String)
149150

@@ -154,7 +155,7 @@ func pipenvTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
154155
settings.Buildpacks.PythonInstallers.Online,
155156
settings.Buildpacks.BuildPlan.Online,
156157
).
157-
WithEnv(map[string]string{"BP_PIPENV_VERSION": dependencies[1].Version}).
158+
WithEnv(map[string]string{pipenv.EnvVersion: dependencies[1].Version}).
158159
Execute(name, source)
159160
Expect(err).ToNot(HaveOccurred(), logs.String)
160161

integration/installers/pixi_layer_reuse_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
. "github.com/paketo-buildpacks/occam/matchers"
1919

2020
integration_helpers "github.com/paketo-buildpacks/python-installers/integration"
21+
"github.com/paketo-buildpacks/python-installers/pkg/installers/pixi"
2122
)
2223

2324
func pixiTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
@@ -157,7 +158,7 @@ func pixiTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
157158
settings.Buildpacks.PythonInstallers.Online,
158159
settings.Buildpacks.BuildPlan.Online,
159160
).
160-
WithEnv(map[string]string{"BP_PIXI_VERSION": dependencies[0].Version}).
161+
WithEnv(map[string]string{pixi.EnvVersion: dependencies[0].Version}).
161162
Execute(name, source)
162163
Expect(err).ToNot(HaveOccurred(), logs.String)
163164

@@ -175,7 +176,7 @@ func pixiTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
175176
settings.Buildpacks.PythonInstallers.Online,
176177
settings.Buildpacks.BuildPlan.Online,
177178
).
178-
WithEnv(map[string]string{"BP_PIXI_VERSION": dependencies[2].Version}).
179+
WithEnv(map[string]string{pixi.EnvVersion: dependencies[2].Version}).
179180
Execute(name, source)
180181
Expect(err).ToNot(HaveOccurred(), logs.String)
181182

integration/installers/poetry_versions_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
. "github.com/paketo-buildpacks/occam/matchers"
1818

1919
integration_helpers "github.com/paketo-buildpacks/python-installers/integration"
20+
"github.com/paketo-buildpacks/python-installers/pkg/installers/poetry"
2021
)
2122

2223
func poetryTestVersions(t *testing.T, context spec.G, it spec.S) {
@@ -82,7 +83,7 @@ func poetryTestVersions(t *testing.T, context spec.G, it spec.S) {
8283
settings.Buildpacks.PythonInstallers.Online,
8384
settings.Buildpacks.BuildPlan.Online,
8485
).
85-
WithEnv(map[string]string{"BP_POETRY_VERSION": firstPoetryVersion}).
86+
WithEnv(map[string]string{poetry.EnvVersion: firstPoetryVersion}).
8687
Execute(name, source)
8788
Expect(err).ToNot(HaveOccurred(), firstLogs.String)
8889

@@ -112,7 +113,7 @@ func poetryTestVersions(t *testing.T, context spec.G, it spec.S) {
112113
settings.Buildpacks.PythonInstallers.Online,
113114
settings.Buildpacks.BuildPlan.Online,
114115
).
115-
WithEnv(map[string]string{"BP_POETRY_VERSION": secondPoetryVersion}).
116+
WithEnv(map[string]string{poetry.EnvVersion: secondPoetryVersion}).
116117
Execute(name, source)
117118
Expect(err).ToNot(HaveOccurred(), secondLogs.String)
118119

integration/installers/uv_layer_reuse_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
. "github.com/paketo-buildpacks/occam/matchers"
1919

2020
integration_helpers "github.com/paketo-buildpacks/python-installers/integration"
21+
"github.com/paketo-buildpacks/python-installers/pkg/installers/uv"
2122
)
2223

2324
func uvTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
@@ -157,7 +158,7 @@ func uvTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
157158
settings.Buildpacks.PythonInstallers.Online,
158159
settings.Buildpacks.BuildPlan.Online,
159160
).
160-
WithEnv(map[string]string{"BP_UV_VERSION": dependencies[0].Version}).
161+
WithEnv(map[string]string{uv.EnvVersion: dependencies[0].Version}).
161162
Execute(name, source)
162163
Expect(err).ToNot(HaveOccurred(), logs.String)
163164

@@ -175,7 +176,7 @@ func uvTestLayerReuse(t *testing.T, context spec.G, it spec.S) {
175176
settings.Buildpacks.PythonInstallers.Online,
176177
settings.Buildpacks.BuildPlan.Online,
177178
).
178-
WithEnv(map[string]string{"BP_UV_VERSION": dependencies[2].Version}).
179+
WithEnv(map[string]string{uv.EnvVersion: dependencies[2].Version}).
179180
Execute(name, source)
180181
Expect(err).ToNot(HaveOccurred(), logs.String)
181182

pkg/installers/miniconda/constants.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ const (
1515

1616
// DepName is the name of the metadata.dependencies id
1717
DepId = "miniconda3"
18+
19+
EnvVersion = "BP_MINICONDA_VERSION"
1820
)
1921

2022
// Priorities is a list of possible places where the buildpack could look for a
2123
// specific version of miniconda3 to install, ordered from highest to lowest priority.
22-
var Priorities = []interface{}{"BP_MINICONDA_VERSION"}
24+
var Priorities = []interface{}{EnvVersion}

pkg/installers/miniconda/detect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ func Detect() packit.DetectFunc {
2020
return func(context packit.DetectContext) (packit.DetectResult, error) {
2121
var requirements []packit.BuildPlanRequirement
2222

23-
if version, ok := os.LookupEnv("BP_MINICONDA_VERSION"); ok {
23+
if version, ok := os.LookupEnv(EnvVersion); ok {
2424
requirements = []packit.BuildPlanRequirement{
2525
{
2626
Name: Conda,
2727
Metadata: build.BuildPlanMetadata{
28-
VersionSource: "BP_MINICONDA_VERSION",
28+
VersionSource: EnvVersion,
2929
Version: version,
3030
},
3131
},

pkg/installers/miniconda/detect_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
3939
Expect(result).To(Equal(packit.DetectResult{
4040
Plan: packit.BuildPlan{
4141
Provides: []packit.BuildPlanProvision{
42-
{Name: "conda"},
42+
{Name: miniconda.Conda},
4343
},
4444
},
4545
}))
@@ -48,7 +48,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
4848

4949
context("when BP_MINICONDA_VERSION is set", func() {
5050
it.Before(func() {
51-
t.Setenv("BP_MINICONDA_VERSION", "some-version")
51+
t.Setenv(miniconda.EnvVersion, "some-version")
5252
})
5353

5454
it("returns a build plan that provides the version of conda from BP_MINICONDA_VERSION", func() {
@@ -57,14 +57,14 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
5757

5858
Expect(result.Plan).To(Equal(packit.BuildPlan{
5959
Provides: []packit.BuildPlanProvision{
60-
{Name: "conda"},
60+
{Name: miniconda.Conda},
6161
},
6262
Requires: []packit.BuildPlanRequirement{
6363
{
6464
Name: "conda",
6565
Metadata: build.BuildPlanMetadata{
6666
Version: "some-version",
67-
VersionSource: "BP_MINICONDA_VERSION",
67+
VersionSource: miniconda.EnvVersion,
6868
},
6969
},
7070
},

pkg/installers/pip/constants.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44

55
package pip
66

7-
// Pip is the name of the layer into which pip dependency is installed.
8-
const Pip = "pip"
7+
const (
8+
// Pip is the name of the layer into which pip dependency is installed.
9+
Pip = "pip"
910

10-
const PipSrc = "pip-source"
11+
PipSrc = "pip-source"
1112

12-
// CPython is the name of the python runtime dependency provided by the CPython buildpack: https://github.com/paketo-buildpacks/cpython
13-
const CPython = "cpython"
13+
// CPython is the name of the python runtime dependency provided by the CPython buildpack: https://github.com/paketo-buildpacks/cpython
14+
CPython = "cpython"
1415

15-
// DependencyChecksumKey is the name of the key in the pip layer TOML whose value is pip dependency's SHA256.
16-
const DependencyChecksumKey = "dependency_checksum"
16+
// DependencyChecksumKey is the name of the key in the pip layer TOML whose value is pip dependency's SHA256.
17+
DependencyChecksumKey = "dependency_checksum"
18+
19+
EnvVersion = "BP_PIP_VERSION"
20+
)
1721

1822
// Priorities is a list of possible places where the buildpack could look for a
1923
// specific version of Pip to install, ordered from highest to lowest priority.
20-
var Priorities = []interface{}{"BP_PIP_VERSION"}
24+
var Priorities = []interface{}{EnvVersion}

0 commit comments

Comments
 (0)