-
Notifications
You must be signed in to change notification settings - Fork 384
specify environment variables in run() #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
invoke/runners.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- E501 line too long (82 > 79 characters)
|
Don't know exactly why the tests fail. On my PC tox doesn't report any problem. Anyway, please find below a simple task that shows the feature. from invoke import run, task
@task
def foo():
run("env")
print "************************************************************"
run("env", env={'FOO':'BAR'})
print "************************************************************"
run("env", env={}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty big breaking change to current (and arguably expected) behaviour. If the user doesn't pass an environment, the child process is executed with no environment (empty dict). The general expected behaviour is that a child is spawned with the environment of it's parent unless otherwise specified.
This would probably be best as:
# Environment variables
self.env = os.environ.copy()
if env:
self.env.update(env)
|
@sophacles thanks for your feedback. if the user doesn't pass an environment the child process is executed WITH the parent's environment. there is no breaking change. only if the user passes an empty dict the child process is executed with no environment. my implementation is:
|
|
@philtay Oh got it, I was a bit confused on that chunk of code. I understand the logic now - thanks for the clarification Thinking further about it - I think perhaps the best thing to do would be mirror the # from subprocess.py line 1281 in python 2.7.10
if env is None:
os.execvp(executable, args)
else:
os.execvpe(executable, args, env)Using values from
|
|
Tangentially related to my comment above: the @bitprophet - the answer to this todo is: yes, subprocess uses |
|
@sophacles i agree with you. i'll wait for @bitprophet input before making changes. |
|
Went ahead with my own version of this today (necessitated by interim changes); credited in changelog though. Thanks! |
Ref: #259
Tests and docs after your approval and first round of comments.