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

Side by Side Diff: vpython/run.go

Issue 2867843002: vpython: Forcefully clear PYTHON* environment. (Closed)
Patch Set: block user site too Created 3 years, 7 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 | no next file » | 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 "os/exec" 9 "os/exec"
10 "os/signal" 10 "os/signal"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 // Create our virtual environment root directory. 60 // Create our virtual environment root directory.
61 err := venv.With(c, opts.EnvConfig, opts.WaitForEnv, func(c context.Cont ext, ve *venv.Env) error { 61 err := venv.With(c, opts.EnvConfig, opts.WaitForEnv, func(c context.Cont ext, ve *venv.Env) error {
62 // Build the augmented environment variables. 62 // Build the augmented environment variables.
63 e := opts.Environ 63 e := opts.Environ
64 if e.Len() == 0 { 64 if e.Len() == 0 {
65 // If no environment was supplied, use the system enviro nment. 65 // If no environment was supplied, use the system enviro nment.
66 e = environ.System() 66 e = environ.System()
67 } 67 }
68 68
69 // Remove PYTHONPATH and PYTHONHOME from the environment. This p revents them
70 // from being propagated to delegate processes (e.g., "vpython" script calls
71 // Python script, the "vpython" one uses the Interpreter's Isola tedCommand
72 // to isolate the initial run, but the delegate command blindly uses the
73 // environment that it's provided).
74 //
75 // Also set PYTHONNOUSERSITE, which prevents a user's "site" con figuration
76 // from influencing Python startup. The system "site" should alr eady be
77 // ignored b/c we're using the VirtualEnv Python interpreter.
78 e.Remove("PYTHONPATH")
79 e.Remove("PYTHONHOME")
80 e.Set("PYTHONNOUSERSITE", "1")
81
69 e.Set("VIRTUAL_ENV", ve.Root) // Set by VirtualEnv script. 82 e.Set("VIRTUAL_ENV", ve.Root) // Set by VirtualEnv script.
70 if ve.EnvironmentStampPath != "" { 83 if ve.EnvironmentStampPath != "" {
71 e.Set(EnvironmentStampPathENV, ve.EnvironmentStampPath) 84 e.Set(EnvironmentStampPathENV, ve.EnvironmentStampPath)
72 } 85 }
73 86
74 // Prefix PATH with the VirtualEnv "bin" directory. 87 // Prefix PATH with the VirtualEnv "bin" directory.
75 prefixPATH(e, ve.BinDir) 88 prefixPATH(e, ve.BinDir)
76 89
77 // Run our bootstrapped Python command. 90 // Run our bootstrapped Python command.
78 cmd := ve.Interpreter().IsolatedCommand(c, opts.Args...) 91 cmd := ve.Interpreter().IsolatedCommand(c, opts.Args...)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 components = append([]string(nil), components...) 160 components = append([]string(nil), components...)
148 161
149 // If there is a current PATH (likely), add that to the end. 162 // If there is a current PATH (likely), add that to the end.
150 cur, _ := env.Get("PATH") 163 cur, _ := env.Get("PATH")
151 if len(cur) > 0 { 164 if len(cur) > 0 {
152 components = append(components, cur) 165 components = append(components, cur)
153 } 166 }
154 167
155 env.Set("PATH", strings.Join(components, string(os.PathListSeparator))) 168 env.Set("PATH", strings.Join(components, string(os.PathListSeparator)))
156 } 169 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698