| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package venv | 5 package venv |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "os" | 9 "os" |
| 10 "path/filepath" | 10 "path/filepath" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 // Package is the VirtualEnv package to install. It must be non-nil and | 43 // Package is the VirtualEnv package to install. It must be non-nil and |
| 44 // valid. It will be used if the environment specification doesn't suppl
y an | 44 // valid. It will be used if the environment specification doesn't suppl
y an |
| 45 // overriding one. | 45 // overriding one. |
| 46 Package vpython.Spec_Package | 46 Package vpython.Spec_Package |
| 47 | 47 |
| 48 // Python is the Python interpreter to use. If empty, one will be resolv
ed | 48 // Python is the Python interpreter to use. If empty, one will be resolv
ed |
| 49 // based on the Spec and the current PATH. | 49 // based on the Spec and the current PATH. |
| 50 Python string | 50 Python string |
| 51 | 51 |
| 52 // LookPathFunc, if not nil, will be used instead of exec.LookPath to fi
nd the |
| 53 // underlying Python interpreter. |
| 54 LookPathFunc python.LookPathFunc |
| 55 |
| 52 // Spec is the specification file to use to construct the VirtualEnv. If | 56 // Spec is the specification file to use to construct the VirtualEnv. If |
| 53 // nil, or if fields are missing, they will be filled in by probing the
system | 57 // nil, or if fields are missing, they will be filled in by probing the
system |
| 54 // PATH. | 58 // PATH. |
| 55 Spec *vpython.Spec | 59 Spec *vpython.Spec |
| 56 | 60 |
| 57 // PruneThreshold, if >0, is the maximum age of a VirtualEnv before it s
hould | 61 // PruneThreshold, if >0, is the maximum age of a VirtualEnv before it s
hould |
| 58 // be pruned. If <= 0, there is no maximum age, so no pruning will be | 62 // be pruned. If <= 0, there is no maximum age, so no pruning will be |
| 59 // performed. | 63 // performed. |
| 60 PruneThreshold time.Duration | 64 PruneThreshold time.Duration |
| 61 // MaxPrunesPerSweep applies a limit to the number of items to prune per | 65 // MaxPrunesPerSweep applies a limit to the number of items to prune per |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 specVers, err := python.ParseVersion(s.PythonVersion) | 251 specVers, err := python.ParseVersion(s.PythonVersion) |
| 248 if err != nil { | 252 if err != nil { |
| 249 return errors.Annotate(err).Reason("failed to parse Python versi
on from: %(value)q"). | 253 return errors.Annotate(err).Reason("failed to parse Python versi
on from: %(value)q"). |
| 250 D("value", s.PythonVersion). | 254 D("value", s.PythonVersion). |
| 251 Err() | 255 Err() |
| 252 } | 256 } |
| 253 | 257 |
| 254 if cfg.Python == "" { | 258 if cfg.Python == "" { |
| 255 // No explicitly-specified Python path. Determine one based on t
he | 259 // No explicitly-specified Python path. Determine one based on t
he |
| 256 // specification. | 260 // specification. |
| 257 » » if cfg.si, err = python.Find(c, specVers); err != nil { | 261 » » if cfg.si, err = python.Find(c, specVers, cfg.LookPathFunc); err
!= nil { |
| 258 return errors.Annotate(err).Reason("could not find Pytho
n for: %(vers)s"). | 262 return errors.Annotate(err).Reason("could not find Pytho
n for: %(vers)s"). |
| 259 D("vers", specVers). | 263 D("vers", specVers). |
| 260 Err() | 264 Err() |
| 261 } | 265 } |
| 262 cfg.Python = cfg.si.Python | 266 cfg.Python = cfg.si.Python |
| 263 } else { | 267 } else { |
| 264 cfg.si = &python.Interpreter{ | 268 cfg.si = &python.Interpreter{ |
| 265 Python: cfg.Python, | 269 Python: cfg.Python, |
| 266 } | 270 } |
| 267 } | 271 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 288 // Resolve to absolute path. | 292 // Resolve to absolute path. |
| 289 if err := filesystem.AbsPath(&cfg.Python); err != nil { | 293 if err := filesystem.AbsPath(&cfg.Python); err != nil { |
| 290 return errors.Annotate(err).Reason("could not get absolute path
for: %(python)s"). | 294 return errors.Annotate(err).Reason("could not get absolute path
for: %(python)s"). |
| 291 D("python", cfg.Python). | 295 D("python", cfg.Python). |
| 292 Err() | 296 Err() |
| 293 } | 297 } |
| 294 return nil | 298 return nil |
| 295 } | 299 } |
| 296 | 300 |
| 297 func (cfg *Config) systemInterpreter() *python.Interpreter { return cfg.si } | 301 func (cfg *Config) systemInterpreter() *python.Interpreter { return cfg.si } |
| OLD | NEW |