Skip to content

Commit

Permalink
Fix ordered substitution of templated variables in env vars config (#227
Browse files Browse the repository at this point in the history
)

Fixes #223

---------

Co-authored-by: Nat Noordanus <n@natn.me>
  • Loading branch information
dbohdan and nat-n authored Jun 25, 2024
1 parent f863aa8 commit efcbea0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions poethepoet/env/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/test_env_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ""

0 comments on commit efcbea0

Please sign in to comment.