Skip to content

Commit

Permalink
Fixed cmd launch failure when venv path has a space
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidWhittingham authored and adamkerz committed Sep 17, 2019
1 parent c11c234 commit 4414d42
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ def create(self,extraArguments='',pythonCmd='python',py3=PY3):
def cmd(self,c):
"""Runs the command `c` in this virtualenv."""
if WINDOWS:
c=r'cmd /c "{}\Scripts\activate.bat && {}"'.format(self.path,c)
# cmd.exe /C has real specific behaviour around quotes.
# The below double quote syntax is valid because it strips the outside quotes.
# The path to activate.bat must be quoted in case it contains spaces
c=r'''cmd /c ""{}\Scripts\activate.bat" && {}"'''.format(self.path,c)
else:
c=r'bash -c "source {}/bin/activate && {}"'.format(self.path,c)
return CmdContextManager.cmd(c,self.contextPosition)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_venv_context(pie,pie_tasks_path,pie_mock_cmd):
second_activate=r'{}\second\Scripts\activate.bat'.format(cwd)
# TODO: only correct on Windows
assert len(pie_mock_cmd.cmds)==1
assert pie_mock_cmd.cmds[0][0][0]==r'cmd /c "{} && cmd /c "{} && blah""'.format(first_activate,second_activate)
assert pie_mock_cmd.cmds[0][0][0]==r'''cmd /c ""{}" && cmd /c ""{}" && blah""'''.format(first_activate,second_activate)


@pytest.mark.parametrize('pie_tasks_path',['cd_context'],indirect=['pie_tasks_path'])
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pie_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ def test_use_venv(pie,capsys,pie_tasks_path,pie_mock_cmd):
out,err=capsys.readouterr()
# TODO: Windows only
assert len(pie_mock_cmd.cmds)==1
assert pie_mock_cmd.cmds[0][0][0].endswith('.venv-pie\\Scripts\\activate.bat && python pie.py test"')
assert '.venv-pie\\Scripts\\activate.bat"' in pie_mock_cmd.cmds[0][0][0] or '.venv-pie/Scripts/activate' in pie_mock_cmd.cmds[0][0][0]
assert pie_mock_cmd.cmds[0][0][0].endswith('python pie.py test"')
venv_path.rmdir()

0 comments on commit 4414d42

Please sign in to comment.