diff --git a/.travis.yml b/.travis.yml index b9c0967f..e10d2400 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ env: global: - PYPI_VENDOR_DIR='./tests/pypi/' - GIT_ASK_YESNO='false' + - PYTHONIOENCODING='utf-8' matrix: - TEST_SUITE='not install' - TEST_SUITE='install' diff --git a/pipenv/project.py b/pipenv/project.py index 46bf8103..642dc519 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -44,6 +44,7 @@ from .environments import ( PIPENV_VIRTUALENV, PIPENV_TEST_INDEX, PIPENV_PYTHON, + PIPENV_DEFAULT_PYTHON_VERSION, ) @@ -578,12 +579,17 @@ class Project(object): u'dev-packages': {}, } # Default requires. - required_python = python or self.which( - 'python', self.virtualenv_location - ) - data[u'requires'] = { - 'python_version': python_version(required_python)[: len('2.7')] - } + required_python = python + if not python: + if self.virtualenv_location: + required_python = self.which('python', self.virtualenv_location) + else: + required_python = self.which('python') + version = python_version(required_python) or PIPENV_DEFAULT_PYTHON_VERSION + if version and len(version) >= 3: + data[u'requires'] = { + 'python_version': version[: len('2.7')] + } self.write_toml(data, 'Pipfile') def write_toml(self, data, path=None): diff --git a/pipenv/utils.py b/pipenv/utils.py index 832105fa..4a4ce008 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -220,8 +220,13 @@ def python_version(path_to_python): c = delegator.run([path_to_python, '--version'], block=False) except Exception: return None + c.block() version = parse_python_version(c.out.strip() or c.err.strip()) - return u'{major}.{minor}.{micro}'.format(**version) + try: + version = u'{major}.{minor}.{micro}'.format(**version) + except TypeError: + return None + return version def escape_grouped_arguments(s): diff --git a/tests/unit/test_help.py b/tests/unit/test_help.py new file mode 100644 index 00000000..2432e969 --- /dev/null +++ b/tests/unit/test_help.py @@ -0,0 +1,11 @@ +import os +import subprocess +import sys + + +def test_help(): + output = subprocess.check_output( + [sys.executable, '-m', 'pipenv.help'], + stderr=subprocess.STDOUT, env=os.environ.copy(), + ) + assert output