From 1a30448e968c1af61bbbc79fed34ffa561854ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Tue, 18 Jun 2024 18:32:14 +0200 Subject: [PATCH 01/12] Add support for environment variables --- conda_subprocess/process.py | 8 +++++++- tests/test_conda_subprocess.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/conda_subprocess/process.py b/conda_subprocess/process.py index 5981588..3d7a178 100644 --- a/conda_subprocess/process.py +++ b/conda_subprocess/process.py @@ -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, @@ -52,6 +53,11 @@ def Popen( if not isiterable(command): command = shlex_split_unicode(command) + # update environment + if env is not None: + environment_dict = os.environ.copy() + environment_dict.update(env) + # spawn subprocess return subprocess_Popen( args=encode_arguments(command), @@ -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, diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index cd12863..4595e74 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -36,3 +36,13 @@ 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.assertEqual( + call( + "echo ${TESTVAR}", + prefix_path=self.env_path, + env={"TESTVAR": "test"} + ), + "test", + ) From 28e34b7dd339ee9aa9701ce00b6a6ed983912f65 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:34:02 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_conda_subprocess.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index 7933aa3..b1e6e19 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -52,10 +52,6 @@ def test_popen(self): def test_environment_variable(self): self.assertEqual( - call( - "echo ${TESTVAR}", - prefix_path=self.env_path, - env={"TESTVAR": "test"} - ), + call("echo ${TESTVAR}", prefix_path=self.env_path, env={"TESTVAR": "test"}), "test", ) From 7a9797bd0accae3b2987b7193b125e6ef6d124c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Tue, 18 Jun 2024 18:38:55 +0200 Subject: [PATCH 03/12] use check_output() --- tests/test_conda_subprocess.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index b1e6e19..6508b5c 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -52,6 +52,8 @@ def test_popen(self): def test_environment_variable(self): self.assertEqual( - call("echo ${TESTVAR}", prefix_path=self.env_path, env={"TESTVAR": "test"}), - "test", + check_output( + "echo ${TESTVAR}", prefix_path=self.env_path, env={"TESTVAR": "test"} + ), + b"test\n", ) From 421ca4f5a115f762b029fadb16db4b9297708f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Tue, 18 Jun 2024 18:41:56 +0200 Subject: [PATCH 04/12] fix bug --- conda_subprocess/process.py | 2 +- tests/test_conda_subprocess.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/conda_subprocess/process.py b/conda_subprocess/process.py index 3d7a178..960eb3f 100644 --- a/conda_subprocess/process.py +++ b/conda_subprocess/process.py @@ -54,8 +54,8 @@ def Popen( command = shlex_split_unicode(command) # update environment + environment_dict = os.environ.copy() if env is not None: - environment_dict = os.environ.copy() environment_dict.update(env) # spawn subprocess diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index 6508b5c..f67d08a 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -53,7 +53,7 @@ def test_popen(self): def test_environment_variable(self): self.assertEqual( check_output( - "echo ${TESTVAR}", prefix_path=self.env_path, env={"TESTVAR": "test"} + "echo $TESTVAR", prefix_path=self.env_path, env={"TESTVAR": "test"} ), b"test\n", ) From 3e720c7029f1cf01e0b9a5629a55d281ed2c072b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Tue, 18 Jun 2024 19:02:01 +0200 Subject: [PATCH 05/12] environment --- tests/test_conda_subprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index f67d08a..5a269f1 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -53,7 +53,7 @@ def test_popen(self): def test_environment_variable(self): self.assertEqual( check_output( - "echo $TESTVAR", prefix_path=self.env_path, env={"TESTVAR": "test"} + "env", prefix_path=self.env_path, env={"TESTVAR": "test"} ), b"test\n", ) From 30ae724ccbaea255bf4ca2bc1c9322d70a9c7fe4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:02:10 +0000 Subject: [PATCH 06/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_conda_subprocess.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index 5a269f1..2e8661c 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -52,8 +52,6 @@ def test_popen(self): def test_environment_variable(self): self.assertEqual( - check_output( - "env", prefix_path=self.env_path, env={"TESTVAR": "test"} - ), + check_output("env", prefix_path=self.env_path, env={"TESTVAR": "test"}), b"test\n", ) From 0382f6f5b57fe4aae9fd0ed08e39539a493495e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Tue, 18 Jun 2024 19:05:38 +0200 Subject: [PATCH 07/12] test environment --- tests/test_conda_subprocess.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index 2e8661c..6523050 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -51,7 +51,8 @@ def test_popen(self): self.assertIsNone(output[1]) def test_environment_variable(self): - self.assertEqual( - check_output("env", prefix_path=self.env_path, env={"TESTVAR": "test"}), - b"test\n", + self.assertTrue( + "TESTVAR" in check_output( + "env", prefix_path=self.env_path, env={"TESTVAR": "test"}, universal_newlines=True + ).split("\n"), ) From d5717e3961044bf30b829a330d0bd970715360e6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:05:51 +0000 Subject: [PATCH 08/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_conda_subprocess.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index 6523050..566ee34 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -52,7 +52,11 @@ def test_popen(self): def test_environment_variable(self): self.assertTrue( - "TESTVAR" in check_output( - "env", prefix_path=self.env_path, env={"TESTVAR": "test"}, universal_newlines=True + "TESTVAR" + in check_output( + "env", + prefix_path=self.env_path, + env={"TESTVAR": "test"}, + universal_newlines=True, ).split("\n"), ) From f4a9e703bc6f6001f6ec89a0309202e15970d643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Tue, 18 Jun 2024 19:21:08 +0200 Subject: [PATCH 09/12] more testing --- tests/test_conda_subprocess.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index 6523050..dacb4b4 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -51,8 +51,9 @@ def test_popen(self): self.assertIsNone(output[1]) def test_environment_variable(self): - self.assertTrue( - "TESTVAR" in check_output( + print( + check_output( "env", prefix_path=self.env_path, env={"TESTVAR": "test"}, universal_newlines=True ).split("\n"), ) + self.assertTrue(True) \ No newline at end of file From 3069209ffbc86c3fe94c1fd200ef3e689dea0a80 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:24:24 +0000 Subject: [PATCH 10/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_conda_subprocess.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index dacb4b4..24f56e6 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -53,7 +53,10 @@ def test_popen(self): def test_environment_variable(self): print( check_output( - "env", prefix_path=self.env_path, env={"TESTVAR": "test"}, universal_newlines=True + "env", + prefix_path=self.env_path, + env={"TESTVAR": "test"}, + universal_newlines=True, ).split("\n"), ) - self.assertTrue(True) \ No newline at end of file + self.assertTrue(True) From a9a462185a4529a54f14e8122b115c481ff11bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Tue, 18 Jun 2024 19:29:48 +0200 Subject: [PATCH 11/12] fix test --- tests/test_conda_subprocess.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index dacb4b4..dd7fc2f 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -51,9 +51,8 @@ def test_popen(self): self.assertIsNone(output[1]) def test_environment_variable(self): - print( - check_output( + self.assertTrue( + 'TESTVAR=test' in check_output( "env", prefix_path=self.env_path, env={"TESTVAR": "test"}, universal_newlines=True ).split("\n"), - ) - self.assertTrue(True) \ No newline at end of file + ) \ No newline at end of file From a127cd3824c1b7a28c2738958744270362418820 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:30:21 +0000 Subject: [PATCH 12/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_conda_subprocess.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index dd7fc2f..d3d9c1a 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -52,7 +52,11 @@ def test_popen(self): def test_environment_variable(self): self.assertTrue( - 'TESTVAR=test' in check_output( - "env", prefix_path=self.env_path, env={"TESTVAR": "test"}, universal_newlines=True + "TESTVAR=test" + in check_output( + "env", + prefix_path=self.env_path, + env={"TESTVAR": "test"}, + universal_newlines=True, ).split("\n"), - ) \ No newline at end of file + )