-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdetect.go
More file actions
72 lines (62 loc) · 1.72 KB
/
detect.go
File metadata and controls
72 lines (62 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package pipenv
import (
"os"
"github.com/paketo-buildpacks/packit/v2"
)
// BuildPlanMetadata is the buildpack specific data included in build plan
// requirements.
type BuildPlanMetadata struct {
// VersionSource denotes where dependency version came from (e.g. an
// environment variable).
VersionSource string `toml:"version-source"`
// Version denotes the version of a dependency, if there is one.
Version string `toml:"version"`
// Build denotes the dependency is needed at build-time.
Build bool `toml:"build"`
// Launch denotes the dependency is needed at runtime.
Launch bool `toml:"launch"`
}
// Detect will return a packit.DetectFunc that will be invoked during the
// detect phase of the buildpack lifecycle.
//
// This buildpack always passes detection and will contribute a Build Plan that
// provides pipenv.
//
// If a version is provided via the $BP_PIPENV_VERSION environment variable,
// that version of pipenv will be a requirement.
func Detect() packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
requirements := []packit.BuildPlanRequirement{
{
Name: Pip,
Metadata: BuildPlanMetadata{
Build: true,
},
},
{
Name: CPython,
Metadata: BuildPlanMetadata{
Build: true,
},
},
}
pipEnvVersion, ok := os.LookupEnv("BP_PIPENV_VERSION")
if ok {
requirements = append(requirements, packit.BuildPlanRequirement{
Name: Pipenv,
Metadata: BuildPlanMetadata{
Version: pipEnvVersion,
VersionSource: "BP_PIPENV_VERSION",
},
})
}
return packit.DetectResult{
Plan: packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: Pipenv},
},
Requires: requirements,
},
}, nil
}
}