Commit 6fed3ff0 authored by Maurits van Rees's avatar Maurits van Rees Committed by GitHub

Make compatible with pip 22.2+, restoring Requires-Python patch (#616)

* Make compatible with pip 22.2+, restoring Requires-Python functionality there.

Fixes https://github.com/buildout/buildout/issues/613.

Note: we are patching `process_url` from `setuptools`.
The existing comment says that this method was copied over from setuptools 46.1.3.
I was wondering, so I checked: the method is still the same in latest setuptools.  And it is largely unchanged since setuptools 42.0.2.
So for that part we should still be compatible with quite a long range of setuptools versions.

* process_url patch: must pass cache_link_parsing=False.

This fixes test failures: extdemo-1.5 was not found, because the previous index page containing only extdemo-1.4 was cached.
We were passing this before to HTMLPage, and still do as a fallback, but I missed that this was also needed in pip 22.2+ for the new IndexContent class.
parent 4b86eb17
Make compatible with pip 22.2+, restoring Requires-Python functionality there.
Fixes `issue 613 <https://github.com/buildout/buildout/issues/613>`_.
[maurits]
......@@ -40,18 +40,27 @@ patch_Distribution()
def patch_PackageIndex():
"""Patch the package index from setuptools.
Main goal: check the package urls on an index page to see if they are
compatible with the Python version.
"""
try:
import logging
logging.getLogger('pip._internal.index.collector').setLevel(logging.ERROR)
from setuptools.package_index import PackageIndex
from setuptools.package_index import URL_SCHEME
from setuptools.package_index import HREF
from setuptools.package_index import distros_for_url
from setuptools.package_index import htmldecode
from pip._internal.index.collector import HTMLPage
try:
# pip 22.2+
from pip._internal.index.collector import IndexContent
except ImportError:
# pip 22.1-
from pip._internal.index.collector import HTMLPage as IndexContent
from pip._internal.index.collector import parse_links
from pip._internal.index.collector import _clean_link
from pip._internal.index.package_finder import _check_link_requires_python
from pip._internal.models.target_python import TargetPython
from pip._vendor import six
......@@ -114,13 +123,34 @@ def patch_PackageIndex():
except AttributeError:
# Python 2
charset = f.headers.getparam('charset') or 'latin-1'
try:
content_type = f.getheader('content-type')
except AttributeError:
# On at least Python 2.7:
# addinfourl instance has no attribute 'getheader'
content_type = "text/html"
try:
# pip 22.2+
html_page = IndexContent(
page,
content_type=content_type,
encoding=charset,
url=base,
cache_link_parsing=False,
)
except TypeError:
try:
html_page = HTMLPage(page, charset, base, cache_link_parsing=False)
# pip 20.1-22.1
html_page = IndexContent(page, charset, base, cache_link_parsing=False)
except TypeError:
html_page = HTMLPage(page, charset, base)
# pip 20.0 or older
html_page = IndexContent(page, charset, base)
# https://github.com/buildout/buildout/issues/598
# use_deprecated_html5lib is a required addition in pip 22.
# use_deprecated_html5lib is a required addition in pip 22.0/22.1
# and it is gone already in 22.2
try:
plinks = parse_links(html_page, use_deprecated_html5lib=False)
except TypeError:
......@@ -150,7 +180,9 @@ def patch_PackageIndex():
except ImportError:
import logging
logger = logging.getLogger('zc.buildout.patches')
logger.warning('Requires-Python support missing. \n\n',
logger.warning(
'Requires-Python support missing and could not be patched into '
'zc.buildout. \n\n',
exc_info=True
)
return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment