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
4 changes: 2 additions & 2 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
poetry "github.com/paketo-buildpacks/python-installers/pkg/installers/poetry"
uv "github.com/paketo-buildpacks/python-installers/pkg/installers/uv"

pythoninstallers "github.com/paketo-buildpacks/python-installers/pkg/installers/common"
"github.com/paketo-buildpacks/python-installers/pkg/build"
)

type PackagerParameters interface {
}

func Build(
logger scribe.Emitter,
commonBuildParameters pythoninstallers.CommonBuildParameters,
commonBuildParameters build.CommonBuildParameters,
buildParameters map[string]PackagerParameters,
) packit.BuildFunc {
return func(context packit.BuildContext) (packit.BuildResult, error) {
Expand Down
52 changes: 27 additions & 25 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (
"github.com/paketo-buildpacks/packit/v2/scribe"

pythoninstallers "github.com/paketo-buildpacks/python-installers"
pkgcommon "github.com/paketo-buildpacks/python-installers/pkg/installers/common"
"github.com/paketo-buildpacks/python-installers/pkg/build"
dependencyfakes "github.com/paketo-buildpacks/python-installers/pkg/dependency/fakes"
miniconda "github.com/paketo-buildpacks/python-installers/pkg/installers/miniconda"
minicondafakes "github.com/paketo-buildpacks/python-installers/pkg/installers/miniconda/fakes"
pip "github.com/paketo-buildpacks/python-installers/pkg/installers/pip"
Expand All @@ -35,6 +36,7 @@ import (
poetryfakes "github.com/paketo-buildpacks/python-installers/pkg/installers/poetry/fakes"
uv "github.com/paketo-buildpacks/python-installers/pkg/installers/uv"
uvfakes "github.com/paketo-buildpacks/python-installers/pkg/installers/uv/fakes"
sbomfakes "github.com/paketo-buildpacks/python-installers/pkg/sbom/fakes"

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

buffer *bytes.Buffer
logger scribe.Emitter
build packit.BuildFunc
buildFunc packit.BuildFunc
buildContext packit.BuildContext

// common
sbomGenerator *pipfakes.SBOMGenerator
// dependencyManager *pipfakes.DependencyManager
sbomGenerator *sbomfakes.SBOMGenerator
// dependencyManager *dependencyfakes.DependencyManager

// conda
minicondaDependencyManager *minicondafakes.DependencyManager
minicondaDependencyManager *dependencyfakes.DependencyManager
runner *minicondafakes.Runner

// pip
pipDependencyManager *pipfakes.DependencyManager
pipDependencyManager *dependencyfakes.DependencyManager
pipInstallProcess *pipfakes.InstallProcess
pipSitePackageProcess *pipfakes.SitePackageProcess

// pipenv
pipenvDependencyManager *pipenvfakes.DependencyManager
pipenvDependencyManager *dependencyfakes.DependencyManager
pipenvProcess *pipenvfakes.InstallProcess
pipenvSitePackageProcess *pipenvfakes.SitePackageProcess

// poetry
poetryDependencyManager *poetryfakes.DependencyManager
poetryDependencyManager *dependencyfakes.DependencyManager
poetryProcess *poetryfakes.InstallProcess
poetrySitePackageProcess *poetryfakes.SitePackageProcess

// uv
uvDependencyManager *uvfakes.DependencyManager
uvDependencyManager *dependencyfakes.DependencyManager
uvInstallProcess *uvfakes.InstallProcess

// pixi
pixiDependencyManager *pixifakes.DependencyManager
pixiDependencyManager *dependencyfakes.DependencyManager
pixiInstallProcess *pixifakes.InstallProcess

buildParameters pkgcommon.CommonBuildParameters
buildParameters build.CommonBuildParameters

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

sbomGenerator = &pipfakes.SBOMGenerator{}
sbomGenerator = &sbomfakes.SBOMGenerator{}
sbomGenerator.GenerateFromDependencyCall.Returns.SBOM = sbom.SBOM{}

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

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

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

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

// uv
uvDependencyManager = &uvfakes.DependencyManager{}
uvDependencyManager = &dependencyfakes.DependencyManager{}
uvDependencyManager.ResolveCall.Returns.Dependency = postal.Dependency{
ID: "uv",
Name: "uv-dependency-name",
Expand Down Expand Up @@ -258,7 +260,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
uvInstallProcess = &uvfakes.InstallProcess{}

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

pixiInstallProcess = &pixifakes.InstallProcess{}

buildParameters = pkgcommon.CommonBuildParameters{
SbomGenerator: pkgcommon.Generator{},
buildParameters = build.CommonBuildParameters{
SbomGenerator: sbomGenerator,
Clock: chronos.DefaultClock,
Logger: logger,
}
Expand Down Expand Up @@ -321,7 +323,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
}

build = pythoninstallers.Build(logger, buildParameters, packagerParameters)
buildFunc = pythoninstallers.Build(logger, buildParameters, packagerParameters)

buildContext = packit.BuildContext{
BuildpackInfo: packit.BuildpackInfo{
Expand Down Expand Up @@ -435,7 +437,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
for _, testPlan := range testPlans {
logger.Detail("Doing: %s", testPlan)
buildContext.Plan = testPlan.Plan
result, err := build(buildContext)
result, err := buildFunc(buildContext)
Expect(err).NotTo(HaveOccurred())

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

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

build = pythoninstallers.Build(logger, buildParameters, packagerParameters)
buildFunc = pythoninstallers.Build(logger, buildParameters, packagerParameters)

for _, testPlan := range testPlans {
buildContext.Plan = testPlan.Plan
_, err := build(buildContext)
_, err := buildFunc(buildContext)
Expect(err).To(HaveOccurred())
}
})
Expand Down
16 changes: 8 additions & 8 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/paketo-buildpacks/packit/v2/scribe"

pythoninstallers "github.com/paketo-buildpacks/python-installers"
common "github.com/paketo-buildpacks/python-installers/pkg/installers/common"
"github.com/paketo-buildpacks/python-installers/pkg/build"

miniconda "github.com/paketo-buildpacks/python-installers/pkg/installers/miniconda"
pip "github.com/paketo-buildpacks/python-installers/pkg/installers/pip"
Expand Down Expand Up @@ -65,7 +65,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Requires: []packit.BuildPlanRequirement{
{
Name: pip.CPython,
Metadata: common.BuildPlanMetadata{
Metadata: build.BuildPlanMetadata{
Build: true,
},
},
Expand All @@ -88,14 +88,14 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Requires: []packit.BuildPlanRequirement{
{
Name: pipenv.CPython,
Metadata: common.BuildPlanMetadata{
Metadata: build.BuildPlanMetadata{
Build: true,
Launch: false,
},
},
{
Name: pipenv.Pip,
Metadata: common.BuildPlanMetadata{
Metadata: build.BuildPlanMetadata{
Build: true,
Launch: false,
},
Expand Down Expand Up @@ -141,15 +141,15 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Requires: []packit.BuildPlanRequirement{
{
Name: poetry.CPython,
Metadata: common.BuildPlanMetadata{
Metadata: build.BuildPlanMetadata{
Build: true,
Version: "1.2.3",
VersionSource: "pyproject.toml",
},
},
{
Name: poetry.Pip,
Metadata: common.BuildPlanMetadata{
Metadata: build.BuildPlanMetadata{
Build: true,
},
},
Expand Down Expand Up @@ -187,15 +187,15 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Requires: []packit.BuildPlanRequirement{
{
Name: poetry.CPython,
Metadata: common.BuildPlanMetadata{
Metadata: build.BuildPlanMetadata{
Build: true,
Version: "1.2.3",
VersionSource: "pyproject.toml",
},
},
{
Name: poetry.Pip,
Metadata: common.BuildPlanMetadata{
Metadata: build.BuildPlanMetadata{
Build: true,
},
},
Expand Down
1 change: 0 additions & 1 deletion integration/installers/miniconda_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func minicondaTestDefault(t *testing.T, context spec.G, it spec.S) {
err error
)

fmt.Printf("Settings are: %s", settings)
image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithBuildpacks(
Expand Down
18 changes: 4 additions & 14 deletions pkg/installers/common/common.go → pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,19 @@
//
// SPDX-License-Identifier: Apache-2.0

package pythoninstallers
package build

import (
"github.com/paketo-buildpacks/packit/v2/chronos"
"github.com/paketo-buildpacks/packit/v2/postal"
"github.com/paketo-buildpacks/packit/v2/sbom"
"github.com/paketo-buildpacks/packit/v2/scribe"
)

type SBOMGenerator interface {
GenerateFromDependency(dependency postal.Dependency, path string) (sbom.SBOM, error)
}

type Generator struct{}

func (f Generator) GenerateFromDependency(dependency postal.Dependency, path string) (sbom.SBOM, error) {
return sbom.GenerateFromDependency(dependency, path)
}
"github.com/paketo-buildpacks/python-installers/pkg/sbom"
)

// CommonBuildParameters are the parameters shared
// by all packager build function implementation
type CommonBuildParameters struct {
SbomGenerator SBOMGenerator
SbomGenerator sbom.SBOMGenerator
Clock chronos.Clock
Logger scribe.Emitter
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/dependency/dependency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: © 2026 Idiap Research Institute <contact@idiap.ch>
// SPDX-FileContributor: Samuel Gaist <samuel.gaist@idiap.ch>
//
// SPDX-License-Identifier: Apache-2.0

package dependency

import (
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/postal"
)

// DependencyManager defines the interface for picking the best matching
// dependency and installing it.
type DependencyManager interface {
Resolve(path, id, version, stack string) (postal.Dependency, error)
Deliver(dependency postal.Dependency, cnbPath, destinationPath, platformPath string) error
GenerateBillOfMaterials(dependencies ...postal.Dependency) []packit.BOMEntry
}
16 changes: 16 additions & 0 deletions pkg/executable/executable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: Copyright (c) 2013-Present CloudFoundry.org Foundation, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0

package executable

import (
"github.com/paketo-buildpacks/packit/v2/pexec"
)

//go:generate faux --interface Executable --output fakes/executable.go

// Executable defines the interface for invoking an executable.
type Executable interface {
Execute(pexec.Execution) error
}
Loading
Loading