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

Side by Side Diff: vpython/application/application.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 | « no previous file | vpython/options.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 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 25 matching lines...) Expand all
36 const ( 36 const (
37 // VirtualEnvRootENV is an environment variable that, if set, will be us ed 37 // VirtualEnvRootENV is an environment variable that, if set, will be us ed
38 // as the default VirtualEnv root. 38 // as the default VirtualEnv root.
39 // 39 //
40 // This value overrides the default (~/.vpython), but can be overridden by the 40 // This value overrides the default (~/.vpython), but can be overridden by the
41 // "-root" flag. 41 // "-root" flag.
42 // 42 //
43 // Like "-root", if this value is present but empty, a tempdir will be u sed 43 // Like "-root", if this value is present but empty, a tempdir will be u sed
44 // for the VirtualEnv root. 44 // for the VirtualEnv root.
45 VirtualEnvRootENV = "VPYTHON_VIRTUALENV_ROOT" 45 VirtualEnvRootENV = "VPYTHON_VIRTUALENV_ROOT"
46
47 // DefaultSpecENV is an enviornment variable that, if set, will be used as the
48 // default VirtualEnv spec file if none is provided or found through pro bing.
49 DefaultSpecENV = "VPYTHON_DEFAULT_SPEC"
46 ) 50 )
47 51
48 // ReturnCodeError is an error wrapping a return code value. 52 // ReturnCodeError is an error wrapping a return code value.
49 type ReturnCodeError int 53 type ReturnCodeError int
50 54
51 func (err ReturnCodeError) Error() string { 55 func (err ReturnCodeError) Error() string {
52 return fmt.Sprintf("python interpreter returned non-zero error: %d", err ) 56 return fmt.Sprintf("python interpreter returned non-zero error: %d", err )
53 } 57 }
54 58
55 // VerificationFunc is a function used in environment verification. 59 // VerificationFunc is a function used in environment verification.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 a.opts.EnvConfig.LookPathFunc = lp.look 196 a.opts.EnvConfig.LookPathFunc = lp.look
193 197
194 if a.help { 198 if a.help {
195 return a.showPythonHelp(c, fs, &lp) 199 return a.showPythonHelp(c, fs, &lp)
196 } 200 }
197 201
198 c = a.logConfig.Set(c) 202 c = a.logConfig.Set(c)
199 203
200 // If an spec path was manually specified, load and use it. 204 // If an spec path was manually specified, load and use it.
201 if a.specPath != "" { 205 if a.specPath != "" {
202 » » var err error 206 » » var sp vpythonAPI.Spec
203 » » if a.opts.EnvConfig.Spec, err = spec.Load(a.specPath); err != ni l { 207 » » if err := spec.Load(a.specPath, &sp); err != nil {
204 » » » return errors.Annotate(err).Reason("failed to load speci fication file (-spec) from: %(path)s"). 208 » » » return err
205 » » » » D("path", a.specPath). 209 » » }
210 » » a.opts.EnvConfig.Spec = &sp
211 » } else if specPath := a.opts.Environ.GetEmpty(DefaultSpecENV); specPath != "" {
212 » » if err := spec.Load(specPath, &a.opts.DefaultSpec); err != nil {
213 » » » return errors.Annotate(err).
214 » » » » Reason("failed to load default specification fil e ("+DefaultSpecENV+"from: %(path)s").
215 » » » » D("path", specPath).
206 Err() 216 Err()
207 } 217 }
208 } 218 }
209 219
210 // If an empty BaseDir was specified, use a temporary directory and clea n it 220 // If an empty BaseDir was specified, use a temporary directory and clea n it
211 // up on completion. 221 // up on completion.
212 if a.opts.EnvConfig.BaseDir == "" { 222 if a.opts.EnvConfig.BaseDir == "" {
213 tdir, err := ioutil.TempDir("", "vpython") 223 tdir, err := ioutil.TempDir("", "vpython")
214 if err != nil { 224 if err != nil {
215 return errors.Annotate(err).Reason("failed to create tem porary directory").Err() 225 return errors.Annotate(err).Reason("failed to create tem porary directory").Err()
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 }, 312 },
303 logConfig: logging.Config{ 313 logConfig: logging.Config{
304 Level: logging.Error, 314 Level: logging.Error,
305 }, 315 },
306 } 316 }
307 317
308 return run(c, func(c context.Context) error { 318 return run(c, func(c context.Context) error {
309 return a.mainImpl(c, os.Args[0], os.Args[1:]) 319 return a.mainImpl(c, os.Args[0], os.Args[1:])
310 }) 320 })
311 } 321 }
OLDNEW
« no previous file with comments | « no previous file | vpython/options.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698