diff --git a/pipenv/cli.py b/pipenv/cli.py index 712178b0..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) @@ -289,6 +301,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): @@ -398,7 +411,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( diff --git a/pipenv/utils.py b/pipenv/utils.py index 725a7ffd..2e713915 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 @@ -56,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. diff --git a/test_windows/test_pipenv.py b/test_windows/test_pipenv.py index 3ade112d..c98d36fd 100644 --- a/test_windows/test_pipenv.py +++ b/test_windows/test_pipenv.py @@ -4,19 +4,32 @@ import shutil from mock import patch, Mock, PropertyMock import delegator -import toml +from pipenv.patched import contoml from pipenv.cli import ( ensure_proper_casing, - pip_install, pip_download + pip_install, pip_download, find_a_system_python ) +FULL_PYTHON_PATH = 'C:\\Python36-x64\\python.exe' 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') @@ -187,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'] 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" 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