Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: vpython/options.go

Issue 2917093003: [vpython] Allow default spec via enviornment. (Closed)
Patch Set: spec load Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « vpython/application/application.go ('k') | vpython/spec/load.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 vpython 5 package vpython
6 6
7 import ( 7 import (
8 "os" 8 "os"
9 9
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
11 11
12 "github.com/luci/luci-go/vpython/api/vpython" 12 "github.com/luci/luci-go/vpython/api/vpython"
13 "github.com/luci/luci-go/vpython/python" 13 "github.com/luci/luci-go/vpython/python"
14 "github.com/luci/luci-go/vpython/spec" 14 "github.com/luci/luci-go/vpython/spec"
15 "github.com/luci/luci-go/vpython/venv" 15 "github.com/luci/luci-go/vpython/venv"
16 16
17 "github.com/luci/luci-go/common/errors" 17 "github.com/luci/luci-go/common/errors"
18 "github.com/luci/luci-go/common/logging" 18 "github.com/luci/luci-go/common/logging"
19 "github.com/luci/luci-go/common/system/environ" 19 "github.com/luci/luci-go/common/system/environ"
20 "github.com/luci/luci-go/common/system/filesystem" 20 "github.com/luci/luci-go/common/system/filesystem"
21 ) 21 )
22 22
23 // Options is the set of options to use to construct and execute a VirtualEnv 23 // Options is the set of options to use to construct and execute a VirtualEnv
24 // Python application. 24 // Python application.
25 type Options struct { 25 type Options struct {
26 // EnvConfig is the VirtualEnv configuration to run from. 26 // EnvConfig is the VirtualEnv configuration to run from.
27 EnvConfig venv.Config 27 EnvConfig venv.Config
28 28
29 // DefaultSpec is the default specification to use, if no specification was
30 // supplied or probed.
31 DefaultSpec vpython.Spec
32
29 // SpecLoader is the spec.Loader to use to load a specification file for a 33 // SpecLoader is the spec.Loader to use to load a specification file for a
30 // given script. 34 // given script.
31 // 35 //
32 // The empty value is a valid default spec.Loader. 36 // The empty value is a valid default spec.Loader.
33 SpecLoader spec.Loader 37 SpecLoader spec.Loader
34 38
35 // Args are the arguments to forward to the Python process. 39 // Args are the arguments to forward to the Python process.
36 Args []string 40 Args []string
37 41
38 // WaitForEnv, if true, means that if another agent holds a lock on the target 42 // WaitForEnv, if true, means that if another agent holds a lock on the target
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 Err() 142 Err()
139 } 143 }
140 if spec != nil { 144 if spec != nil {
141 o.EnvConfig.Spec = spec 145 o.EnvConfig.Spec = spec
142 return nil 146 return nil
143 } 147 }
144 } 148 }
145 149
146 // Do we have a spec file in the environment? 150 // Do we have a spec file in the environment?
147 if v, ok := o.Environ.Get(EnvironmentStampPathENV); ok { 151 if v, ok := o.Environ.Get(EnvironmentStampPathENV); ok {
148 » » if o.EnvConfig.Spec, err = spec.Load(v); err != nil { 152 » » var sp vpython.Spec
153 » » if err := spec.Load(v, &sp); err != nil {
149 return errors.Annotate(err).Reason("failed to load envir onment-supplied spec from: %(path)s"). 154 return errors.Annotate(err).Reason("failed to load envir onment-supplied spec from: %(path)s").
150 D("path", v). 155 D("path", v).
151 Err() 156 Err()
152 } 157 }
158
153 logging.Infof(c, "Loaded spec from environment: %s", v) 159 logging.Infof(c, "Loaded spec from environment: %s", v)
160 o.EnvConfig.Spec = &sp
154 return nil 161 return nil
155 } 162 }
156 163
157 » // Unable to load a spec. 164 » // If standard resolution doesn't yield a spec, fall back on our default spec.
158 » logging.Infof(c, "Unable to resolve specification path. Using empty spec ification.") 165 » logging.Infof(c, "Unable to resolve specification path. Using default sp ecification.")
159 » o.EnvConfig.Spec = &vpython.Spec{} 166 » o.EnvConfig.Spec = &o.DefaultSpec
160 return nil 167 return nil
161 } 168 }
OLDNEW
« no previous file with comments | « vpython/application/application.go ('k') | vpython/spec/load.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698