From 6901eae31d5433da5edd3c77aa8825712ec7faea Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Sat, 17 Nov 2018 22:50:04 +0800 Subject: [PATCH] expand env before run script Signed-off-by: Frost Ming --- news/3178.bugfix.rst | 1 + pipenv/core.py | 6 ++++-- tests/integration/test_run.py | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 news/3178.bugfix.rst diff --git a/news/3178.bugfix.rst b/news/3178.bugfix.rst new file mode 100644 index 00000000..d3a4fd6c --- /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 7624db8b..94212875 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 72f10596..8167a318 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 @@ printfoo = "python -c \"print('foo')\"" 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 @@ multicommand = "bash -c \"cd docs && make html\"" 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"