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

Side by Side Diff: vpython/application/application.go

Issue 2917093003: [vpython] Allow default spec via enviornment. (Closed)
Patch Set: 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 | « no previous file | vpython/options.go » ('j') | vpython/options.go » ('J')
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 application 5 package application
6 6
7 import ( 7 import (
8 "flag" 8 "flag"
9 "fmt" 9 "fmt"
10 "io/ioutil" 10 "io/ioutil"
(...skipping 24 matching lines...) Expand all
35 const ( 35 const (
36 // VirtualEnvRootENV is an environment variable that, if set, will be us ed 36 // VirtualEnvRootENV is an environment variable that, if set, will be us ed
37 // as the default VirtualEnv root. 37 // as the default VirtualEnv root.
38 // 38 //
39 // This value overrides the default (~/.vpython), but can be overridden by the 39 // This value overrides the default (~/.vpython), but can be overridden by the
40 // "-root" flag. 40 // "-root" flag.
41 // 41 //
42 // Like "-root", if this value is present but empty, a tempdir will be u sed 42 // Like "-root", if this value is present but empty, a tempdir will be u sed
43 // for the VirtualEnv root. 43 // for the VirtualEnv root.
44 VirtualEnvRootENV = "VPYTHON_VIRTUALENV_ROOT" 44 VirtualEnvRootENV = "VPYTHON_VIRTUALENV_ROOT"
45
46 // DefaultSpecENV is an enviornment variable that, if set, will be used as the
47 // default VirtualEnv spec file if none is provided or found through pro bing.
48 DefaultSpecENV = "VPYTHON_DEFAULT_SPEC"
45 ) 49 )
46 50
47 // ReturnCodeError is an error wrapping a return code value. 51 // ReturnCodeError is an error wrapping a return code value.
48 type ReturnCodeError int 52 type ReturnCodeError int
49 53
50 func (err ReturnCodeError) Error() string { 54 func (err ReturnCodeError) Error() string {
51 return fmt.Sprintf("python interpreter returned non-zero error: %d", err ) 55 return fmt.Sprintf("python interpreter returned non-zero error: %d", err )
52 } 56 }
53 57
54 // VerificationFunc is a function used in environment verification. 58 // VerificationFunc is a function used in environment verification.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 if a.help { 174 if a.help {
171 return a.showPythonHelp(c, fs) 175 return a.showPythonHelp(c, fs)
172 } 176 }
173 177
174 c = a.logConfig.Set(c) 178 c = a.logConfig.Set(c)
175 179
176 // If an spec path was manually specified, load and use it. 180 // If an spec path was manually specified, load and use it.
177 if a.specPath != "" { 181 if a.specPath != "" {
178 var err error 182 var err error
179 if a.opts.EnvConfig.Spec, err = spec.Load(a.specPath); err != ni l { 183 if a.opts.EnvConfig.Spec, err = spec.Load(a.specPath); err != ni l {
180 » » » return errors.Annotate(err).Reason("failed to load speci fication file (-spec) from: %(path)s"). 184 » » » return errors.Annotate(err).
185 » » » » Reason("failed to load specification file (%(sou rce)s) from: %(path)s").
181 D("path", a.specPath). 186 D("path", a.specPath).
iannucci 2017/06/05 19:46:36 no D for source?
dnj 2017/06/06 13:40:39 oops, "source" is old.
182 Err() 187 Err()
183 } 188 }
189 } else if specPath := a.opts.Environ.GetEmpty(DefaultSpecENV); specPath != "" {
190 var err error
191 if a.opts.DefaultSpec, err = spec.Load(specPath); err != nil {
192 return errors.Annotate(err).
193 Reason("failed to load default specification fil e ("+DefaultSpecENV+"from: %(path)s").
194 D("path", specPath).
195 Err()
196 }
184 } 197 }
185 198
186 // If an empty BaseDir was specified, use a temporary directory and clea n it 199 // If an empty BaseDir was specified, use a temporary directory and clea n it
187 // up on completion. 200 // up on completion.
188 if a.opts.EnvConfig.BaseDir == "" { 201 if a.opts.EnvConfig.BaseDir == "" {
189 tdir, err := ioutil.TempDir("", "vpython") 202 tdir, err := ioutil.TempDir("", "vpython")
190 if err != nil { 203 if err != nil {
191 return errors.Annotate(err).Reason("failed to create tem porary directory").Err() 204 return errors.Annotate(err).Reason("failed to create tem porary directory").Err()
192 } 205 }
193 defer func() { 206 defer func() {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 }, 284 },
272 logConfig: logging.Config{ 285 logConfig: logging.Config{
273 Level: logging.Error, 286 Level: logging.Error,
274 }, 287 },
275 } 288 }
276 289
277 return run(c, func(c context.Context) error { 290 return run(c, func(c context.Context) error {
278 return a.mainImpl(c, os.Args[1:]) 291 return a.mainImpl(c, os.Args[1:])
279 }) 292 })
280 } 293 }
OLDNEW
« no previous file with comments | « no previous file | vpython/options.go » ('j') | vpython/options.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698