rez
rez copied to clipboard
Fix ResolvedContext.execute_command with parent_env=None
Specific problem I'm having is:
- A script uses
ResolvedContext.get_current()to run a child process (Nuke) - In this child process, env vars from the parent environment (such as
$http_proxy) do not get inherited by the child process
Described behaviour is os.environ should be used if parent_env is None, but prior to this change, an empty dict was used instead.
In other words, prior to this change the following would fail (printenv EXAMPLE returns nothing):
$ export EXAMPLE=abcdef
$ rez env rez -- python
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
>>> import os, rez, rez.resolved_context, subprocess
>>> ctx = rez.resolved_context.ResolvedContext.get_current()
>>> ctx.execute_command(['printenv', 'EXAMPLE'], parent_environ=None, stdout=subprocess.PIPE).communicate()
(b'abcdef\n', None)
Whereas this output is now consistent with, say, execute_shell:
>>> ctx.execute_shell('bash', parent_environ=None)
You are now in a rez-configured environment.
>> $ printenv EXAMPLE
abcdef
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: dbr / name: dbr/Ben (55d02e030916b3188415bd048270edb803522daf, 992eedfe7a3e7fce933e5091bbf3b59ce5e61748)
Is there anything I can do to help get this merged? We still have a workaround in place which is just to do
env = os.environ.copy()
env["WORKAROUND_REZ_THING"] = "abc"
ctx = rez.resolved_context.ResolvedContext.get_current()
p = ctx.execute_command(cmd, parent_environ=env)
which would be nice to remove
I have yet to be convinced that this change is good and will not break anything. So for now, I'm not willing to merge this PR yet.