Skip to content

Commit

Permalink
Merge pull request #11 from pyiron/env
Browse files Browse the repository at this point in the history
Add support for environment variables
  • Loading branch information
jan-janssen authored Jun 18, 2024
2 parents 4c016fd + a127cd3 commit d557bfc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion conda_subprocess/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def Popen(
preexec_fn=None,
close_fds=True,
cwd=None,
env=None,
prefix_name=None,
prefix_path=None,
universal_newlines=None,
Expand Down Expand Up @@ -52,6 +53,11 @@ def Popen(
if not isiterable(command):
command = shlex_split_unicode(command)

# update environment
environment_dict = os.environ.copy()
if env is not None:
environment_dict.update(env)

# spawn subprocess
return subprocess_Popen(
args=encode_arguments(command),
Expand All @@ -63,7 +69,7 @@ def Popen(
close_fds=close_fds,
shell=False,
cwd=cwd,
env=encode_environment(os.environ.copy()),
env=encode_environment(environment_dict),
universal_newlines=universal_newlines,
startupinfo=startupinfo,
creationflags=creationflags,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_conda_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ def test_popen(self):
else:
self.assertEqual(output[0], b"Python 3.12.1\n")
self.assertIsNone(output[1])

def test_environment_variable(self):
self.assertTrue(
"TESTVAR=test"
in check_output(
"env",
prefix_path=self.env_path,
env={"TESTVAR": "test"},
universal_newlines=True,
).split("\n"),
)

0 comments on commit d557bfc

Please sign in to comment.