MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/buildpacks / RuntimeVersion

Function RuntimeVersion

pkg/python/python.go:116–146  ·  view source on GitHub ↗

RuntimeVersion validate and returns the customer requested Python version by inspecting the environment variables and .python-version file.

(ctx *gcp.Context, dir string)

Source from the content-addressed store, hash-verified

114func Version(ctx *gcp.Context) (string, error) {
115 result, err := ctx.Exec([]string{Command(), "--version"})
116 if err != nil {
117 return "", err
118 }
119 return strings.TrimSpace(result.Stdout), nil
120}
121
122// RuntimeVersion validate and returns the customer requested Python version by inspecting the
123// environment variables and .python-version file.
124func RuntimeVersion(ctx *gcp.Context, dir string) (string, error) {
125 if v := os.Getenv(env.Runtime); v != "" && !strings.HasPrefix(v, "python") {
126 return "*", nil
127 }
128
129 if v := os.Getenv(versionEnv); v != "" {
130 ctx.Logf("Using Python version from %s: %s", versionEnv, v)
131 return v, nil
132 }
133 if v := os.Getenv(env.RuntimeVersion); v != "" {
134 ctx.Logf("Using Python version from %s: %s", env.RuntimeVersion, v)
135 return v, nil
136 }
137 v, err := versionFromFile(ctx, dir)
138 if err != nil {
139 return "", err
140 }
141 if v != "" {
142 return v, nil
143 }
144
145 os := runtime.OSForStack(ctx)
146
147 latestPythonVersionForStack, ok := latestPythonVersionPerStack[os]
148 if !ok {
149 return "", gcp.UserErrorf("invalid stack for Python runtime: %q", os)

Callers 4

BuildFnFunction · 0.92
TestRuntimeVersionFunction · 0.70

Calls 3

OSForStackFunction · 0.92
versionFromFileFunction · 0.85
LogfMethod · 0.80

Tested by 1

TestRuntimeVersionFunction · 0.56