Skip to content

Commit d2693ea

Browse files
authored
refactor: code cleanup (#89)
* refactor: cleanup SBOMGenerator * refactor: move sbom to own package * refactor: move build related types in own module And removed common.go file * chore: move sbom generate comment to correct file * refactor: moved DependencyManager in own package This also unifies the various implementations. * refactor: move Executable to own package * refactor: move common content into pkg Since the content is indeed used by all the installers, make it accessible at the pkg level rather that having the indirection of common. * chore: remove stray print in tests * refactor: cleanup Executable Use the new dedicated module
1 parent 43ad04b commit d2693ea

63 files changed

Lines changed: 329 additions & 1073 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ import (
1818
poetry "github.com/paketo-buildpacks/python-installers/pkg/installers/poetry"
1919
uv "github.com/paketo-buildpacks/python-installers/pkg/installers/uv"
2020

21-
pythoninstallers "github.com/paketo-buildpacks/python-installers/pkg/installers/common"
21+
"github.com/paketo-buildpacks/python-installers/pkg/build"
2222
)
2323

2424
type PackagerParameters interface {
2525
}
2626

2727
func Build(
2828
logger scribe.Emitter,
29-
commonBuildParameters pythoninstallers.CommonBuildParameters,
29+
commonBuildParameters build.CommonBuildParameters,
3030
buildParameters map[string]PackagerParameters,
3131
) packit.BuildFunc {
3232
return func(context packit.BuildContext) (packit.BuildResult, error) {

build_test.go

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import (
2222
"github.com/paketo-buildpacks/packit/v2/scribe"
2323

2424
pythoninstallers "github.com/paketo-buildpacks/python-installers"
25-
pkgcommon "github.com/paketo-buildpacks/python-installers/pkg/installers/common"
25+
"github.com/paketo-buildpacks/python-installers/pkg/build"
26+
dependencyfakes "github.com/paketo-buildpacks/python-installers/pkg/dependency/fakes"
2627
miniconda "github.com/paketo-buildpacks/python-installers/pkg/installers/miniconda"
2728
minicondafakes "github.com/paketo-buildpacks/python-installers/pkg/installers/miniconda/fakes"
2829
pip "github.com/paketo-buildpacks/python-installers/pkg/installers/pip"
@@ -35,6 +36,7 @@ import (
3536
poetryfakes "github.com/paketo-buildpacks/python-installers/pkg/installers/poetry/fakes"
3637
uv "github.com/paketo-buildpacks/python-installers/pkg/installers/uv"
3738
uvfakes "github.com/paketo-buildpacks/python-installers/pkg/installers/uv/fakes"
39+
sbomfakes "github.com/paketo-buildpacks/python-installers/pkg/sbom/fakes"
3840

3941
. "github.com/onsi/gomega"
4042
"github.com/sclevine/spec"
@@ -55,41 +57,41 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
5557

5658
buffer *bytes.Buffer
5759
logger scribe.Emitter
58-
build packit.BuildFunc
60+
buildFunc packit.BuildFunc
5961
buildContext packit.BuildContext
6062

6163
// common
62-
sbomGenerator *pipfakes.SBOMGenerator
63-
// dependencyManager *pipfakes.DependencyManager
64+
sbomGenerator *sbomfakes.SBOMGenerator
65+
// dependencyManager *dependencyfakes.DependencyManager
6466

6567
// conda
66-
minicondaDependencyManager *minicondafakes.DependencyManager
68+
minicondaDependencyManager *dependencyfakes.DependencyManager
6769
runner *minicondafakes.Runner
6870

6971
// pip
70-
pipDependencyManager *pipfakes.DependencyManager
72+
pipDependencyManager *dependencyfakes.DependencyManager
7173
pipInstallProcess *pipfakes.InstallProcess
7274
pipSitePackageProcess *pipfakes.SitePackageProcess
7375

7476
// pipenv
75-
pipenvDependencyManager *pipenvfakes.DependencyManager
77+
pipenvDependencyManager *dependencyfakes.DependencyManager
7678
pipenvProcess *pipenvfakes.InstallProcess
7779
pipenvSitePackageProcess *pipenvfakes.SitePackageProcess
7880

7981
// poetry
80-
poetryDependencyManager *poetryfakes.DependencyManager
82+
poetryDependencyManager *dependencyfakes.DependencyManager
8183
poetryProcess *poetryfakes.InstallProcess
8284
poetrySitePackageProcess *poetryfakes.SitePackageProcess
8385

8486
// uv
85-
uvDependencyManager *uvfakes.DependencyManager
87+
uvDependencyManager *dependencyfakes.DependencyManager
8688
uvInstallProcess *uvfakes.InstallProcess
8789

8890
// pixi
89-
pixiDependencyManager *pixifakes.DependencyManager
91+
pixiDependencyManager *dependencyfakes.DependencyManager
9092
pixiInstallProcess *pixifakes.InstallProcess
9193

92-
buildParameters pkgcommon.CommonBuildParameters
94+
buildParameters build.CommonBuildParameters
9395

9496
testPlans []TestPlan
9597
)
@@ -102,11 +104,11 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
102104
buffer = bytes.NewBuffer(nil)
103105
logger = scribe.NewEmitter(buffer)
104106

105-
sbomGenerator = &pipfakes.SBOMGenerator{}
107+
sbomGenerator = &sbomfakes.SBOMGenerator{}
106108
sbomGenerator.GenerateFromDependencyCall.Returns.SBOM = sbom.SBOM{}
107109

108110
// miniconda
109-
minicondaDependencyManager = &minicondafakes.DependencyManager{}
111+
minicondaDependencyManager = &dependencyfakes.DependencyManager{}
110112
minicondaDependencyManager.ResolveCall.Returns.Dependency = postal.Dependency{
111113
ID: "miniconda3",
112114
Name: "miniconda3-dependency-name",
@@ -134,7 +136,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
134136
runner = &minicondafakes.Runner{}
135137

136138
// pip
137-
pipDependencyManager = &pipfakes.DependencyManager{}
139+
pipDependencyManager = &dependencyfakes.DependencyManager{}
138140
pipDependencyManager.ResolveCall.Returns.Dependency = postal.Dependency{
139141
ID: "pip",
140142
Name: "Pip",
@@ -171,7 +173,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
171173
pipSitePackageProcess.ExecuteCall.Returns.String = filepath.Join(layersDir, "pip", "lib", "python1.23", "site-packages")
172174

173175
// pipenv
174-
pipenvDependencyManager = &pipenvfakes.DependencyManager{}
176+
pipenvDependencyManager = &dependencyfakes.DependencyManager{}
175177
pipenvDependencyManager.ResolveCall.Returns.Dependency = postal.Dependency{
176178
ID: "pipenv",
177179
Name: "pipenv-dependency-name",
@@ -201,7 +203,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
201203
pipenvSitePackageProcess.ExecuteCall.Returns.String = filepath.Join(layersDir, "pipenv", "lib", "python3.8", "site-packages")
202204

203205
// poetry
204-
poetryDependencyManager = &poetryfakes.DependencyManager{}
206+
poetryDependencyManager = &dependencyfakes.DependencyManager{}
205207
poetryDependencyManager.ResolveCall.Returns.Dependency = postal.Dependency{
206208
ID: "poetry",
207209
Name: "poetry-dependency-name",
@@ -230,7 +232,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
230232
poetrySitePackageProcess.ExecuteCall.Returns.String = filepath.Join(layersDir, "poetry", "lib", "python3.8", "site-packages")
231233

232234
// uv
233-
uvDependencyManager = &uvfakes.DependencyManager{}
235+
uvDependencyManager = &dependencyfakes.DependencyManager{}
234236
uvDependencyManager.ResolveCall.Returns.Dependency = postal.Dependency{
235237
ID: "uv",
236238
Name: "uv-dependency-name",
@@ -258,7 +260,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
258260
uvInstallProcess = &uvfakes.InstallProcess{}
259261

260262
// pixi
261-
pixiDependencyManager = &pixifakes.DependencyManager{}
263+
pixiDependencyManager = &dependencyfakes.DependencyManager{}
262264
pixiDependencyManager.ResolveCall.Returns.Dependency = postal.Dependency{
263265
ID: "pixi",
264266
Name: "pixi-dependency-name",
@@ -285,8 +287,8 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
285287

286288
pixiInstallProcess = &pixifakes.InstallProcess{}
287289

288-
buildParameters = pkgcommon.CommonBuildParameters{
289-
SbomGenerator: pkgcommon.Generator{},
290+
buildParameters = build.CommonBuildParameters{
291+
SbomGenerator: sbomGenerator,
290292
Clock: chronos.DefaultClock,
291293
Logger: logger,
292294
}
@@ -321,7 +323,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
321323
},
322324
}
323325

324-
build = pythoninstallers.Build(logger, buildParameters, packagerParameters)
326+
buildFunc = pythoninstallers.Build(logger, buildParameters, packagerParameters)
325327

326328
buildContext = packit.BuildContext{
327329
BuildpackInfo: packit.BuildpackInfo{
@@ -435,7 +437,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
435437
for _, testPlan := range testPlans {
436438
logger.Detail("Doing: %s", testPlan)
437439
buildContext.Plan = testPlan.Plan
438-
result, err := build(buildContext)
440+
result, err := buildFunc(buildContext)
439441
Expect(err).NotTo(HaveOccurred())
440442

441443
layers := result.Layers
@@ -469,7 +471,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
469471
for _, testPlan := range orderTestPlans {
470472
logger.Detail("Doing: %s", testPlan)
471473
buildContext.Plan = testPlan
472-
result, err := build(buildContext)
474+
result, err := buildFunc(buildContext)
473475
Expect(err).NotTo(HaveOccurred())
474476

475477
layers := result.Layers
@@ -482,11 +484,11 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
482484
it("fails if packager parameters is missing", func() {
483485
packagerParameters := map[string]pythoninstallers.PackagerParameters{}
484486

485-
build = pythoninstallers.Build(logger, buildParameters, packagerParameters)
487+
buildFunc = pythoninstallers.Build(logger, buildParameters, packagerParameters)
486488

487489
for _, testPlan := range testPlans {
488490
buildContext.Plan = testPlan.Plan
489-
_, err := build(buildContext)
491+
_, err := buildFunc(buildContext)
490492
Expect(err).To(HaveOccurred())
491493
}
492494
})

detect_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/paketo-buildpacks/packit/v2/scribe"
1616

1717
pythoninstallers "github.com/paketo-buildpacks/python-installers"
18-
common "github.com/paketo-buildpacks/python-installers/pkg/installers/common"
18+
"github.com/paketo-buildpacks/python-installers/pkg/build"
1919

2020
miniconda "github.com/paketo-buildpacks/python-installers/pkg/installers/miniconda"
2121
pip "github.com/paketo-buildpacks/python-installers/pkg/installers/pip"
@@ -65,7 +65,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
6565
Requires: []packit.BuildPlanRequirement{
6666
{
6767
Name: pip.CPython,
68-
Metadata: common.BuildPlanMetadata{
68+
Metadata: build.BuildPlanMetadata{
6969
Build: true,
7070
},
7171
},
@@ -88,14 +88,14 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
8888
Requires: []packit.BuildPlanRequirement{
8989
{
9090
Name: pipenv.CPython,
91-
Metadata: common.BuildPlanMetadata{
91+
Metadata: build.BuildPlanMetadata{
9292
Build: true,
9393
Launch: false,
9494
},
9595
},
9696
{
9797
Name: pipenv.Pip,
98-
Metadata: common.BuildPlanMetadata{
98+
Metadata: build.BuildPlanMetadata{
9999
Build: true,
100100
Launch: false,
101101
},
@@ -141,15 +141,15 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
141141
Requires: []packit.BuildPlanRequirement{
142142
{
143143
Name: poetry.CPython,
144-
Metadata: common.BuildPlanMetadata{
144+
Metadata: build.BuildPlanMetadata{
145145
Build: true,
146146
Version: "1.2.3",
147147
VersionSource: "pyproject.toml",
148148
},
149149
},
150150
{
151151
Name: poetry.Pip,
152-
Metadata: common.BuildPlanMetadata{
152+
Metadata: build.BuildPlanMetadata{
153153
Build: true,
154154
},
155155
},
@@ -187,15 +187,15 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
187187
Requires: []packit.BuildPlanRequirement{
188188
{
189189
Name: poetry.CPython,
190-
Metadata: common.BuildPlanMetadata{
190+
Metadata: build.BuildPlanMetadata{
191191
Build: true,
192192
Version: "1.2.3",
193193
VersionSource: "pyproject.toml",
194194
},
195195
},
196196
{
197197
Name: poetry.Pip,
198-
Metadata: common.BuildPlanMetadata{
198+
Metadata: build.BuildPlanMetadata{
199199
Build: true,
200200
},
201201
},

integration/installers/miniconda_default_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ func minicondaTestDefault(t *testing.T, context spec.G, it spec.S) {
6464
err error
6565
)
6666

67-
fmt.Printf("Settings are: %s", settings)
6867
image, logs, err = pack.WithNoColor().Build.
6968
WithPullPolicy("never").
7069
WithBuildpacks(
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,19 @@
33
//
44
// SPDX-License-Identifier: Apache-2.0
55

6-
package pythoninstallers
6+
package build
77

88
import (
99
"github.com/paketo-buildpacks/packit/v2/chronos"
10-
"github.com/paketo-buildpacks/packit/v2/postal"
11-
"github.com/paketo-buildpacks/packit/v2/sbom"
1210
"github.com/paketo-buildpacks/packit/v2/scribe"
13-
)
14-
15-
type SBOMGenerator interface {
16-
GenerateFromDependency(dependency postal.Dependency, path string) (sbom.SBOM, error)
17-
}
1811

19-
type Generator struct{}
20-
21-
func (f Generator) GenerateFromDependency(dependency postal.Dependency, path string) (sbom.SBOM, error) {
22-
return sbom.GenerateFromDependency(dependency, path)
23-
}
12+
"github.com/paketo-buildpacks/python-installers/pkg/sbom"
13+
)
2414

2515
// CommonBuildParameters are the parameters shared
2616
// by all packager build function implementation
2717
type CommonBuildParameters struct {
28-
SbomGenerator SBOMGenerator
18+
SbomGenerator sbom.SBOMGenerator
2919
Clock chronos.Clock
3020
Logger scribe.Emitter
3121
}

pkg/dependency/dependency.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-FileCopyrightText: © 2026 Idiap Research Institute <contact@idiap.ch>
2+
// SPDX-FileContributor: Samuel Gaist <samuel.gaist@idiap.ch>
3+
//
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package dependency
7+
8+
import (
9+
"github.com/paketo-buildpacks/packit/v2"
10+
"github.com/paketo-buildpacks/packit/v2/postal"
11+
)
12+
13+
// DependencyManager defines the interface for picking the best matching
14+
// dependency and installing it.
15+
type DependencyManager interface {
16+
Resolve(path, id, version, stack string) (postal.Dependency, error)
17+
Deliver(dependency postal.Dependency, cnbPath, destinationPath, platformPath string) error
18+
GenerateBillOfMaterials(dependencies ...postal.Dependency) []packit.BOMEntry
19+
}
File renamed without changes.

pkg/executable/executable.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2013-Present CloudFoundry.org Foundation, Inc. All Rights Reserved.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package executable
6+
7+
import (
8+
"github.com/paketo-buildpacks/packit/v2/pexec"
9+
)
10+
11+
//go:generate faux --interface Executable --output fakes/executable.go
12+
13+
// Executable defines the interface for invoking an executable.
14+
type Executable interface {
15+
Execute(pexec.Execution) error
16+
}
File renamed without changes.

0 commit comments

Comments
 (0)