Skip to content

Commit

Permalink
specify a version of python
Browse files Browse the repository at this point in the history
Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
  • Loading branch information
kennethreitz committed Sep 22, 2017
1 parent 78c19eb commit d69d116
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 11 additions & 0 deletions pipenv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,9 @@ def do_install_dependencies(
if concurrent:
c.block()

if verbose:
click.echo(crayons.blue(c.out or c.err))

# The Installtion failed...
if c.return_code != 0:

Expand Down Expand Up @@ -985,6 +988,10 @@ def do_lock(verbose=False, system=False, clear=False):
if 'index' in dep:
lockfile['develop'][dep['name']]['index'] = dep['index']

# Add Python Version metadata to lockfile.
if 'python_version' in dep:
lockfile['develop'][dep['name']]['python_version'] = dep['python_version']

# Add refs for VCS installs.
# TODO: be smarter about this.
vcs_deps = convert_deps_to_pip(project.vcs_dev_packages, project, r=False)
Expand Down Expand Up @@ -1036,6 +1043,10 @@ def do_lock(verbose=False, system=False, clear=False):
if 'index' in dep:
lockfile['default'][dep['name']]['index'] = dep['index']

# Add Python Version metadata to lockfile.
if 'python_version' in dep:
lockfile['default'][dep['name']]['python_version'] = dep['python_version']

# Add refs for VCS installs.
# TODO: be smarter about this.
vcs_deps = convert_deps_to_pip(project.vcs_packages, project, r=False)
Expand Down
23 changes: 18 additions & 5 deletions pipenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ def resolve_deps(deps, which, which_pip, project, sources=None, verbose=False, p
"""

index_lookup = {}
python_version_lookup = {}

with HackedPythonVersion(python):

Expand Down Expand Up @@ -428,6 +429,8 @@ class PipCommand(pip.basecommand.Command):

if ' -i ' in dep:
index_lookup[constraint.name] = project.get_source(url=dep.split(' -i ')[1]).get('name')
if 'python_version' in dep:
python_version_lookup[constraint.name] = dep.split(';')[1].strip().split('python_version ')[1]
if '==' not in dep:
constraints.append(constraint)
constraints.extend(extra_constraints)
Expand Down Expand Up @@ -477,6 +480,7 @@ class PipCommand(pip.basecommand.Command):
name = pep423_name(result.name)
version = clean_pkg_version(result.specifier)
index = index_lookup.get(result.name)
python_version = python_version_lookup.get(result.name)

collected_hashes = []
if 'python.org' in '|'.join([source['url'] for source in sources]):
Expand All @@ -501,10 +505,15 @@ class PipCommand(pip.basecommand.Command):
except (ValueError, KeyError):
pass

d = {'name': name, 'version': version, 'hashes': collected_hashes}

if index:
results.append({'name': name, 'version': version, 'hashes': collected_hashes, 'index': index})
else:
results.append({'name': name, 'version': version, 'hashes': collected_hashes})
d.update({'index': index})

if python_version:
d.update({'python_version': python_version})

results.append(d)

return results

Expand Down Expand Up @@ -612,6 +621,7 @@ def convert_deps_to_pip(deps, project=None, r=True, include_index=False):
extra = deps[dep] if isinstance(deps[dep], six.string_types) else ''
version = ''
index = ''
requires_python = ''

# Get rid of '*'.
if deps[dep] == '*' or str(extra) == '{}':
Expand All @@ -634,6 +644,10 @@ def convert_deps_to_pip(deps, project=None, r=True, include_index=False):
if not deps[dep]['version'] == '*':
version = deps[dep]['version']

if 'python_version' in deps[dep]:
if not deps[dep]['python_version'] == '*':
requires_python = '; python_version {0}'.format(deps[dep]['python_version'])

if include_index:
if 'index' in deps[dep]:
pip_args = prepare_pip_source_args([project.get_source(deps[dep]['index'])])
Expand Down Expand Up @@ -683,8 +697,7 @@ def convert_deps_to_pip(deps, project=None, r=True, include_index=False):
else:
dep = ''

dependencies.append('{0}{1}{2}{3} {4}'.format(dep, extra, version, hash, index).strip())

dependencies.append('{0}{1}{2}{3}{4} {5}'.format(dep, extra, version, hash, requires_python, index).strip())
if not r:
return dependencies

Expand Down
2 changes: 1 addition & 1 deletion pipenv/vendor/pipfile/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def lock(self):
"""Returns a JSON representation of the Pipfile."""
data = self.data
data['_meta']['hash'] = {"sha256": self.hash}
data['_meta']['pipfile-spec'] = 5
data['_meta']['pipfile-spec'] = 6
return json.dumps(data, indent=4, separators=(',', ': '))

def assert_requirements(self):
Expand Down

0 comments on commit d69d116

Please sign in to comment.