From 068b7ab1b7675af3704c944b9d5f856d7ac3e6f5 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 11:15:20 -0400 Subject: [PATCH 01/13] stole @jacebrowning's tests (modified) Signed-off-by: Kenneth Reitz --- test_windows/test_pipenv.py | 16 +++++++++++++++- tests/test_utils.py | 25 ++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/test_windows/test_pipenv.py b/test_windows/test_pipenv.py index 3ade112d..cc4351f3 100644 --- a/test_windows/test_pipenv.py +++ b/test_windows/test_pipenv.py @@ -8,15 +8,29 @@ import toml from pipenv.cli import ( ensure_proper_casing, - pip_install, pip_download + pip_install, pip_download, find_a_system_python ) +FULL_PYTHON_PATH = find_a_system_python('.'.join(os.environ.PYTHON_VERSION.split('.'[:2]))) + class TestPipenvWindows(): def test_existience(self): assert True + def test_cli_with_custom_python_path(self): + delegator.run('mkdir custom_python') + os.chdir('custom_python') + + c = delegator.run('pipenv install --python={0}'.format(FULL_PYTHON_PATH)) + + # Debugging, if it fails. + print(c.out) + print(c.err) + + assert c.return_code == 0 + def test_cli_usage(self): delegator.run('mkdir test_project') os.chdir('test_project') diff --git a/tests/test_utils.py b/tests/test_utils.py index 29d26e5d..a054ca24 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -138,15 +138,16 @@ class TestUtils: def test_split_vcs(self): pipfile_dict = { - 'packages': { - 'requests': {'git': 'https://github.com/kennethreitz/requests.git'}, - 'Flask': '*' - }, - 'dev-packages': { - 'Django': '==1.10', - 'click': {'svn': 'https://svn.notareal.com/click'}, - 'crayons': {'hg': 'https://hg.alsonotreal.com/crayons'} - }} + 'packages': { + 'requests': {'git': 'https://github.com/kennethreitz/requests.git'}, + 'Flask': '*' + }, + 'dev-packages': { + 'Django': '==1.10', + 'click': {'svn': 'https://svn.notareal.com/click'}, + 'crayons': {'hg': 'https://hg.alsonotreal.com/crayons'} + } + } split_dict = pipenv.utils.split_vcs(pipfile_dict) assert list(split_dict['packages'].keys()) == ['Flask'] @@ -154,3 +155,9 @@ class TestUtils: assert list(split_dict['dev-packages'].keys()) == ['Django'] assert 'click' in split_dict['dev-packages-vcs'] assert 'crayons' in split_dict['dev-packages-vcs'] + + def test_python_version_from_bad_path(self): + assert pipenv.utils.python_version("/fake/path") is None + + def test_python_version_from_non_python(self): + assert pipenv.utils.python_version("/dev/null") is None From bfd498419530ec318c3fb1554f40f51d8739f0f9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 11:16:24 -0400 Subject: [PATCH 02/13] oops Signed-off-by: Kenneth Reitz --- test_windows/test_pipenv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_windows/test_pipenv.py b/test_windows/test_pipenv.py index cc4351f3..314d248a 100644 --- a/test_windows/test_pipenv.py +++ b/test_windows/test_pipenv.py @@ -11,7 +11,7 @@ from pipenv.cli import ( pip_install, pip_download, find_a_system_python ) -FULL_PYTHON_PATH = find_a_system_python('.'.join(os.environ.PYTHON_VERSION.split('.'[:2]))) +FULL_PYTHON_PATH = find_a_system_python('.'.join(os.environ.PYTHON_VERSION.split('.')[:2])) class TestPipenvWindows(): From de861a3cfe3cd985c9132a8593485bc33fb0f36f Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 11:20:52 -0400 Subject: [PATCH 03/13] fix weird bug, maybe Signed-off-by: Kenneth Reitz --- pipenv/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 712178b0..a55bd196 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -398,7 +398,7 @@ def ensure_project(three=None, python=None, validate=True, system=False, warn=Tr path_to_python = which('python') - if project.required_python_version not in python_version(path_to_python): + if project.required_python_version not in python_version(path_to_python) or '': puts( '{0}: Your Pipfile requires {1} {2}, ' 'but you are using {3} ({4}).'.format( From 6f4c434b6208264c385c0c5078929a0e3473d653 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 11:21:32 -0400 Subject: [PATCH 04/13] further oops Signed-off-by: Kenneth Reitz --- test_windows/test_pipenv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_windows/test_pipenv.py b/test_windows/test_pipenv.py index 314d248a..de54e954 100644 --- a/test_windows/test_pipenv.py +++ b/test_windows/test_pipenv.py @@ -11,7 +11,7 @@ from pipenv.cli import ( pip_install, pip_download, find_a_system_python ) -FULL_PYTHON_PATH = find_a_system_python('.'.join(os.environ.PYTHON_VERSION.split('.')[:2])) +FULL_PYTHON_PATH = find_a_system_python('.'.join(os.environ['PYTHON_VERSION'].split('.')[:2])) class TestPipenvWindows(): From 8bc9c605d645b4a9162b6284bbb78af764bd6c99 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 11:22:39 -0400 Subject: [PATCH 05/13] comments Signed-off-by: Kenneth Reitz --- pipenv/cli.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pipenv/cli.py b/pipenv/cli.py index a55bd196..5016f201 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -289,6 +289,7 @@ def ensure_pipfile(validate=True): def find_a_system_python(python): + """Finds a system python, given a version (e.g. 2.7 / 3.6), or a full path.""" if python.startswith('py'): return system_which(python) elif os.path.isabs(python): From 0e3cf61e2768e332f9d7d078e1a6b8b4fcfa662f Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 11:24:08 -0400 Subject: [PATCH 06/13] be more specific Signed-off-by: Kenneth Reitz --- pipenv/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 5016f201..61f4e9ee 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -399,7 +399,7 @@ def ensure_project(three=None, python=None, validate=True, system=False, warn=Tr path_to_python = which('python') - if project.required_python_version not in python_version(path_to_python) or '': + if project.required_python_version not in (python_version(path_to_python) or ''): puts( '{0}: Your Pipfile requires {1} {2}, ' 'but you are using {3} ({4}).'.format( From 95cdd2b6e64d367561fca78f864f95a862bfe8d9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 11:33:13 -0400 Subject: [PATCH 07/13] don't assert status code Signed-off-by: Kenneth Reitz --- pipenv/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pipenv/utils.py b/pipenv/utils.py index 725a7ffd..6380b173 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -29,7 +29,6 @@ def python_version(path_to_python): try: TEMPLATE = 'Python {}.{}.{}' c = delegator.run([path_to_python, '--version'], block=False) - assert c.return_code == 0 except Exception: return None From faf111b9677669159d577c5ebc697599536144c2 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 11:45:48 -0400 Subject: [PATCH 08/13] debug Signed-off-by: Kenneth Reitz --- test_windows/test_pipenv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_windows/test_pipenv.py b/test_windows/test_pipenv.py index de54e954..2a053b83 100644 --- a/test_windows/test_pipenv.py +++ b/test_windows/test_pipenv.py @@ -12,7 +12,7 @@ from pipenv.cli import ( ) FULL_PYTHON_PATH = find_a_system_python('.'.join(os.environ['PYTHON_VERSION'].split('.')[:2])) - +print('.'.join(os.environ['PYTHON_VERSION'].split('.')[:2])) class TestPipenvWindows(): From eb4f13387305edb5409484273effea00b52e0a6d Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 11:52:20 -0400 Subject: [PATCH 09/13] try it @jacebrowning's way Signed-off-by: Kenneth Reitz --- test_windows/test_pipenv.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test_windows/test_pipenv.py b/test_windows/test_pipenv.py index 2a053b83..e9d24033 100644 --- a/test_windows/test_pipenv.py +++ b/test_windows/test_pipenv.py @@ -11,8 +11,7 @@ from pipenv.cli import ( pip_install, pip_download, find_a_system_python ) -FULL_PYTHON_PATH = find_a_system_python('.'.join(os.environ['PYTHON_VERSION'].split('.')[:2])) -print('.'.join(os.environ['PYTHON_VERSION'].split('.')[:2])) +FULL_PYTHON_PATH = 'C:\\Python36-x64\\python.exe' class TestPipenvWindows(): From b3f0b628a17b0777fb4ccf748918408e638fafaa Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 12:00:05 -0400 Subject: [PATCH 10/13] str python Signed-off-by: Kenneth Reitz --- pipenv/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/utils.py b/pipenv/utils.py index 6380b173..2e713915 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -55,7 +55,7 @@ class HackedPythonVersion(object): def __enter__(self): if self.python: - os.environ['PIP_PYTHON_VERSION'] = self.python + os.environ['PIP_PYTHON_VERSION'] = str(self.python) def __exit__(self, *args): # Restore original Python version information. From ba2aed74b11a09e4d4f774f33fbc59d6ed128e5a Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 12:29:01 -0400 Subject: [PATCH 11/13] use contoml Signed-off-by: Kenneth Reitz --- test_windows/test_pipenv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_windows/test_pipenv.py b/test_windows/test_pipenv.py index e9d24033..c98d36fd 100644 --- a/test_windows/test_pipenv.py +++ b/test_windows/test_pipenv.py @@ -4,7 +4,7 @@ import shutil from mock import patch, Mock, PropertyMock import delegator -import toml +from pipenv.patched import contoml from pipenv.cli import ( ensure_proper_casing, @@ -200,7 +200,7 @@ class TestPipenvWindows(): "PyTEST = \"*\"\n") # Load test Pipfile. - p = toml.loads(pfile_test) + p = contoml.loads(pfile_test) assert 'DjAnGO' in p['packages'] assert 'PyTEST' in p['dev-packages'] From a2228657660c6870afb636686b4bc5b2b271f347 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 12:34:07 -0400 Subject: [PATCH 12/13] warn the user of import requirements.txt side-effects. Signed-off-by: Kenneth Reitz --- pipenv/cli.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pipenv/cli.py b/pipenv/cli.py index 61f4e9ee..9cc591dd 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -269,6 +269,18 @@ def ensure_pipfile(validate=True): # Import requirements.txt. import_requirements() + # Warn the user of side-effects. + click.echo( + u'{0}: Your {1} now contains pinned versions, if your {2} did. \n' + 'We recommend updating your {1} to specify the {3} version, instead.' + ''.format( + crayons.red('Warning', bold=True), + crayons.white('Pipfile', bold=True), + crayons.white('requirements.txt', bold=True), + crayons.white('"*"', bold=True) + ) + ) + else: puts(crayons.white(u'Creating a Pipfile for this project…', bold=True), err=True) From 333f7b34f2ceb49214be7c2f05e35ad7f7576a86 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 15 Sep 2017 12:39:37 -0400 Subject: [PATCH 13/13] test utilities on windows Signed-off-by: Kenneth Reitz --- test_windows/test_utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test_windows/test_utils.py diff --git a/test_windows/test_utils.py b/test_windows/test_utils.py new file mode 100644 index 00000000..6a02170e --- /dev/null +++ b/test_windows/test_utils.py @@ -0,0 +1,14 @@ +import delegator + +from pipenv.utils import python_version + + +FULL_PYTHON_PATH = 'C:\\Python36-x64\\python.exe' + + +class TestUtilsWindows(): + + def test_python_version_from_full_path(self): + print(delegator.run('{0} --version'.format(FULL_PYTHON_PATH)).out) + + assert python_version(FULL_PYTHON_PATH) == "3.6.1"