From 8af5422b4ee70a71904cf0a0bec078ffdad22c7d Mon Sep 17 00:00:00 2001 From: "D. Bohdan" Date: Tue, 18 Jun 2024 21:24:22 +0000 Subject: [PATCH 1/3] Add failing test for #223 --- .../substitution_in_envvar_project/pyproject.toml | 7 +++++++ tests/test_subtitution_in_envvar.py | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/fixtures/substitution_in_envvar_project/pyproject.toml create mode 100644 tests/test_subtitution_in_envvar.py diff --git a/tests/fixtures/substitution_in_envvar_project/pyproject.toml b/tests/fixtures/substitution_in_envvar_project/pyproject.toml new file mode 100644 index 000000000..5d8eb9b53 --- /dev/null +++ b/tests/fixtures/substitution_in_envvar_project/pyproject.toml @@ -0,0 +1,7 @@ +[tool.poe.env] +BASE_DIR = "/foo" +SUBDIR = "${BASE_DIR}/bar" +FILE = "${SUBDIR}/baz" + +[tool.poe.tasks.frobnicate] +expr = "${FILE}" diff --git a/tests/test_subtitution_in_envvar.py b/tests/test_subtitution_in_envvar.py new file mode 100644 index 000000000..76181de32 --- /dev/null +++ b/tests/test_subtitution_in_envvar.py @@ -0,0 +1,9 @@ +from pathlib import Path + + +def test_substitution_in_envvar(run_poe_subproc): + result = run_poe_subproc("frobnicate", project="substitution_in_envvar") + + assert result.capture == "Poe => ${FILE}\n" + assert result.stdout == f"/foo/bar/baz\n" + assert result.stderr == "" From 70d07b62e169dd052520b18d15a3eab6afecd72a Mon Sep 17 00:00:00 2001 From: Nat Noordanus Date: Mon, 24 Jun 2024 23:11:35 +0200 Subject: [PATCH 2/3] run poe format --- tests/test_subtitution_in_envvar.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_subtitution_in_envvar.py b/tests/test_subtitution_in_envvar.py index 76181de32..4ad15a68a 100644 --- a/tests/test_subtitution_in_envvar.py +++ b/tests/test_subtitution_in_envvar.py @@ -1,9 +1,6 @@ -from pathlib import Path - - def test_substitution_in_envvar(run_poe_subproc): result = run_poe_subproc("frobnicate", project="substitution_in_envvar") assert result.capture == "Poe => ${FILE}\n" - assert result.stdout == f"/foo/bar/baz\n" + assert result.stdout == "/foo/bar/baz\n" assert result.stderr == "" From 37766183e1b6e8272f42c9566a726f0afead0558 Mon Sep 17 00:00:00 2001 From: Nat Noordanus Date: Tue, 25 Jun 2024 23:16:46 +0200 Subject: [PATCH 3/3] Fix env substitution --- poethepoet/env/manager.py | 1 + .../pyproject.toml | 7 ------- tests/test_env_config.py | 20 +++++++++++++++++++ tests/test_subtitution_in_envvar.py | 6 ------ 4 files changed, 21 insertions(+), 13 deletions(-) delete mode 100644 tests/fixtures/substitution_in_envvar_project/pyproject.toml delete mode 100644 tests/test_subtitution_in_envvar.py diff --git a/poethepoet/env/manager.py b/poethepoet/env/manager.py index e9c478afd..d5658bb0a 100644 --- a/poethepoet/env/manager.py +++ b/poethepoet/env/manager.py @@ -116,6 +116,7 @@ def apply_env_config( self._vars[key] = apply_envvars_to_template( value_str, scoped_env, require_braces=True ) + scoped_env.set(key, self._vars[key]) def update(self, env_vars: Mapping[str, Any]): # ensure all values are strings diff --git a/tests/fixtures/substitution_in_envvar_project/pyproject.toml b/tests/fixtures/substitution_in_envvar_project/pyproject.toml deleted file mode 100644 index 5d8eb9b53..000000000 --- a/tests/fixtures/substitution_in_envvar_project/pyproject.toml +++ /dev/null @@ -1,7 +0,0 @@ -[tool.poe.env] -BASE_DIR = "/foo" -SUBDIR = "${BASE_DIR}/bar" -FILE = "${SUBDIR}/baz" - -[tool.poe.tasks.frobnicate] -expr = "${FILE}" diff --git a/tests/test_env_config.py b/tests/test_env_config.py index 9d9a2e5ab..a0416002c 100644 --- a/tests/test_env_config.py +++ b/tests/test_env_config.py @@ -32,3 +32,23 @@ def test_global_env_templating(temp_pyproject, run_poe_subproc): } for value in printed_vars.values(): assert value.endswith(str(project_path)[5:]) + + +EXAMPLE_WITH_ENV_COMPOSITION = """ +[tool.poe.env] +BASE_DIR = "/foo" +SUBDIR = "${BASE_DIR}/bar" +FILE = "${SUBDIR}/baz" + +[tool.poe.tasks.frobnicate] +expr = "${FILE}" +""" + + +def test_substitution_in_envvar(temp_pyproject, run_poe_subproc): + project_path = temp_pyproject(EXAMPLE_WITH_ENV_COMPOSITION) + result = run_poe_subproc("frobnicate", cwd=project_path) + + assert result.capture == "Poe => ${FILE}\n" + assert result.stdout == "/foo/bar/baz\n" + assert result.stderr == "" diff --git a/tests/test_subtitution_in_envvar.py b/tests/test_subtitution_in_envvar.py deleted file mode 100644 index 4ad15a68a..000000000 --- a/tests/test_subtitution_in_envvar.py +++ /dev/null @@ -1,6 +0,0 @@ -def test_substitution_in_envvar(run_poe_subproc): - result = run_poe_subproc("frobnicate", project="substitution_in_envvar") - - assert result.capture == "Poe => ${FILE}\n" - assert result.stdout == "/foo/bar/baz\n" - assert result.stderr == ""