Fix create_pipfile version parsing

Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
Dan Ryan
2018-04-12 18:43:05 -04:00
parent 5458817b8b
commit 3fa64125c2
2 changed files with 17 additions and 10 deletions
+12 -6
View File
@@ -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):
+5 -4
View File
@@ -220,12 +220,13 @@ def python_version(path_to_python):
c = delegator.run([path_to_python, '--version'], block=False)
except Exception:
return None
if c.return_code != 0:
return None
c.block()
version = parse_python_version(c.out.strip() or c.err.strip())
if not version:
try:
version = u'{major}.{minor}.{micro}'.format(**version)
except TypeError:
return None
return u'{major}.{minor}.{micro}'.format(**version)
return version
def escape_grouped_arguments(s):