Skip to content

Commit

Permalink
Only install packages for current python version
Browse files Browse the repository at this point in the history
- Still resolve all packages to lockfile
- Fixes #1952

Signed-off-by: Dan Ryan <[email protected]>
  • Loading branch information
techalchemy committed Apr 27, 2018
1 parent 828269f commit 903ad38
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 10 deletions.
4 changes: 3 additions & 1 deletion pipenv/patched/notpip/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,9 @@ def _link_package_versions(self, link, search, ignore_compatibility=True):
link.filename, link.requires_python)
support_this_python = True

if not support_this_python and not ignore_compatibility:
# Normally we would keep this the same, but instead we always
# want to include only things that support this python version
if not support_this_python: # and not ignore_compatibility:
logger.debug("The package %s is incompatible with the python"
"version in use. Acceptable python versions are:%s",
link, link.requires_python)
Expand Down
28 changes: 19 additions & 9 deletions pipenv/patched/piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,28 @@ def get_json_dependencies(self, ireq):
def gen(ireq):
if self.DEFAULT_INDEX_URL in self.finder.index_urls:

url = 'https://pypi.org/pypi/{0}/json'.format(ireq.req.name)
url = 'https://pypi.org/pypi/{0}/{1}/json'.format(
ireq.req.name,
str(ireq.req.specifier),
)
r = self.session.get(url)
if not r:
r = self.session.get(
'https://pypi.org/pypi/{0}/json'.format(
ireq.req.name,
)
)
json = r.json()

# TODO: Latest isn't always latest.
latest = list(r.json()['releases'].keys())[-1]
if str(ireq.req.specifier) == '=={0}'.format(latest):

for requires in r.json().get('info', {}).get('requires_dist', {}):
i = InstallRequirement.from_line(requires)

if 'extra' not in repr(i.markers):
yield i
version = json['version']
if str(ireq.req.specifier) == '=={0}'.format(version):
dependencies = json.get('info', {}).get('requires_dist', {})
for dep in dependencies:
req = InstallRequirement.from_line(dep)

if 'extra' not in repr(req.markers):
yield req

try:
if ireq not in self._json_dep_cache:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/pipenv/patched/notpip/index.py b/pipenv/patched/notpip/index.py
index bf1cba9..42968a5 100644
--- a/pipenv/patched/notpip/index.py
+++ b/pipenv/patched/notpip/index.py
@@ -711,7 +711,9 @@ class PackageFinder(object):
link.filename, link.requires_python)
support_this_python = True

- if not support_this_python and not ignore_compatibility:
+ # Normally we would keep this the same, but instead we always
+ # want to include only things that support this python version
+ if not support_this_python: # and not ignore_compatibility:
logger.debug("The package %s is incompatible with the python"
"version in use. Acceptable python versions are:%s",
link, link.requires_python)
42 changes: 42 additions & 0 deletions tasks/vendoring/patches/patched/piptools-update-json-search.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/pipenv/patched/piptools/repositories/pypi.py b/pipenv/patched/piptools/repositories/pypi.py
index e503197..ce78e8a 100644
--- a/pipenv/patched/piptools/repositories/pypi.py
+++ b/pipenv/patched/piptools/repositories/pypi.py
@@ -168,18 +168,28 @@ class PyPIRepository(BaseRepository):
def gen(ireq):
if self.DEFAULT_INDEX_URL in self.finder.index_urls:

- url = 'https://pypi.org/pypi/{0}/json'.format(ireq.req.name)
+ url = 'https://pypi.org/pypi/{0}/{1}/json'.format(
+ ireq.req.name,
+ str(ireq.req.specifier),
+ )
r = self.session.get(url)
+ if not r:
+ r = self.session.get(
+ 'https://pypi.org/pypi/{0}/json'.format(
+ ireq.req.name,
+ )
+ )
+ json = r.json()

# TODO: Latest isn't always latest.
- latest = list(r.json()['releases'].keys())[-1]
- if str(ireq.req.specifier) == '=={0}'.format(latest):
-
- for requires in r.json().get('info', {}).get('requires_dist', {}):
- i = InstallRequirement.from_line(requires)
-
- if 'extra' not in repr(i.markers):
- yield i
+ version = json['version']
+ if str(ireq.req.specifier) == '=={0}'.format(version):
+ dependencies = json.get('info', {}).get('requires_dist', {})
+ for dep in dependencies:
+ req = InstallRequirement.from_line(dep)
+
+ if 'extra' not in repr(req.markers):
+ yield req

try:
if ireq not in self._json_dep_cache:

0 comments on commit 903ad38

Please sign in to comment.