diff --git a/news/3178.bugfix.rst b/news/3178.bugfix.rst new file mode 100644 index 0000000000..d3a4fd6ccb --- /dev/null +++ b/news/3178.bugfix.rst @@ -0,0 +1 @@ +Environment variables are expanded correctly before running scripts on POSIX. diff --git a/pipenv/core.py b/pipenv/core.py index 7624db8b8f..94212875e5 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -2262,7 +2262,7 @@ def do_run_nt(script): def do_run_posix(script, command): - command_path = system_which(script.command) + command_path = system_which(os.path.expandvars(script.command)) if not command_path: if project.has_script(command): click.echo( @@ -2287,7 +2287,9 @@ def do_run_posix(script, command): err=True, ) sys.exit(1) - os.execl(command_path, command_path, *script.args) + os.execl( + command_path, command_path, *[os.path.expandvars(arg) for arg in script.args] + ) def do_run(command, args, three=None, python=False, pypi_mirror=None): diff --git a/tests/integration/test_run.py b/tests/integration/test_run.py index 72f10596df..8167a31811 100644 --- a/tests/integration/test_run.py +++ b/tests/integration/test_run.py @@ -1,6 +1,7 @@ import os from pipenv.project import Project +from pipenv.utils import temp_environ import pytest @@ -27,6 +28,7 @@ def test_scripts(PipenvInstance): notfoundscript = "randomthingtotally" appendscript = "cmd arg1" multicommand = "bash -c \"cd docs && make html\"" +scriptwithenv = "echo $HELLO" """) c = p.pipenv('install') assert c.return_code == 0 @@ -52,3 +54,9 @@ def test_scripts(PipenvInstance): script = project.build_script('appendscript', ['a', 'b']) assert script.command == 'cmd' assert script.args == ['arg1', 'a', 'b'] + + with temp_environ(): + os.environ['HELLO'] = 'WORLD' + c = p.pipenv("run scriptwithenv") + assert c.ok + assert c.out.strip() == "WORLD"