From f36f7ca1bc7f60c5d86d9c727d2a5771838b62fc Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Fri, 23 Mar 2018 23:48:44 -0400 Subject: [PATCH 1/4] Fix `shlex.split()` call to check for posix first - Currently it assumes posix complience and uses `posix=True` - This breaks when parsing on windows --- pipenv/project.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pipenv/project.py b/pipenv/project.py index 747c6ac7..9475c6c5 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -369,8 +369,9 @@ class Project(object): @property def scripts(self): scripts = self.parsed_pipfile.get('scripts', {}) + posix = os.name == 'posix' for (k, v) in scripts.items(): - scripts[k] = shlex.split(v, posix=True) + scripts[k] = shlex.split(v, posix=posix) return scripts def update_settings(self, d): From 844bc3f7d1753dc75cbc3212b3703744c481bae1 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sat, 24 Mar 2018 12:45:46 -0400 Subject: [PATCH 2/4] Fix pipenv scripts for windows shell --- pipenv/project.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pipenv/project.py b/pipenv/project.py index 9475c6c5..26fe79df 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -3,6 +3,7 @@ import codecs import json import os import re +import six import sys import shlex import base64 @@ -370,9 +371,10 @@ class Project(object): def scripts(self): scripts = self.parsed_pipfile.get('scripts', {}) posix = os.name == 'posix' + _scripts = {} for (k, v) in scripts.items(): - scripts[k] = shlex.split(v, posix=posix) - return scripts + _scripts[k] = shlex.split(six.u(v), posix=posix) + return _scripts def update_settings(self, d): settings = self.settings From 052c57c59c21631e7d225aebc1732982aceb8ff1 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sat, 24 Mar 2018 14:18:26 -0400 Subject: [PATCH 3/4] Don't use `six.u` --- pipenv/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/project.py b/pipenv/project.py index 26fe79df..90423e19 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -373,7 +373,7 @@ class Project(object): posix = os.name == 'posix' _scripts = {} for (k, v) in scripts.items(): - _scripts[k] = shlex.split(six.u(v), posix=posix) + _scripts[k] = shlex.split(str(v), posix=posix) return _scripts def update_settings(self, d): From c590e804497aa7ae7826aa4ba0af9637b153c54d Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Mon, 26 Mar 2018 15:48:06 +0800 Subject: [PATCH 4/4] Some tests for the scripts section --- tests/test_pipenv.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index 1329d5b2..49cf3cc8 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -1170,3 +1170,38 @@ flask = "==0.12.2" with open(p.pipfile_path, 'a') as f: f.write('requests = "==2.14.0"\n') assert Project().get_lockfile_hash() != Project.calculate_pipfile_hash() + + @pytest.mark.run + def test_scripts_basic(self): + with PipenvInstance(chdir=True) as p: + with open(p.pipfile_path, 'w') as f: + f.write(""" +[scripts] +printfoo = "python -c print('foo')" + """) + + c = p.pipenv('install') + assert c.return_code == 0 + + c = p.pipenv('run printfoo') + assert c.return_code == 0 + assert c.out == 'foo\n' + assert c.err == '' + + @pytest.mark.run + @pytest.mark.skip(reason='This fails on Windows (not sure about POSIX).') + def test_scripts_quoted(self): + with PipenvInstance(chdir=True) as p: + with open(p.pipfile_path, 'w') as f: + f.write(""" +[scripts] +printfoo = "python -c print('foo')" + """) + + c = p.pipenv('install') + assert c.return_code == 0 + + c = p.pipenv('run printfoo') + assert c.return_code == 0 + assert c.out == 'foo\n' + assert c.err == ''