Skip to content

Commit

Permalink
expand env before run scriptSigned-off-by: Frost Ming <mianghong@gmai…
Browse files Browse the repository at this point in the history
…l.com>
  • Loading branch information
frostming committed Nov 17, 2018
1 parent 32f5d85 commit 112bbad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/3178.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Environment variables are expanded correctly before running scripts on POSIX.
6 changes: 4 additions & 2 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from pipenv.project import Project
from pipenv.utils import temp_environ

import pytest

Expand All @@ -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
Expand All @@ -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"

0 comments on commit 112bbad

Please sign in to comment.