RuntimeVersion validate and returns the customer requested Python version by inspecting the environment variables and .python-version file.
(ctx *gcp.Context, dir string)
| 114 | func 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. |
| 124 | func 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) |