asottile-archive/pip-custom-platform

Incompatible with pip 20.0

Closed this issue · 6 comments

pip 20.0 was uploaded a few hours ago and our jenkins builds started failing with this error:

Traceback (most recent call last):
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pip_custom_platform/_main.py", line 15, in <module>
    from pip._internal.commands import get_summaries
ImportError: cannot import name 'get_summaries'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/work/debian/yspofs/opt/venvs/yspofs/bin/pip-custom-platform", line 8, in <module>
    sys.exit(main())
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pymonkey.py", line 261, in entry
    tuple(patches) + ('--', original_entry_point) + tuple(argv)
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pymonkey.py", line 249, in main
    return entry.load()()
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2444, in load
    return self.resolve()
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2450, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pymonkey.py", line 164, in load_module
    module = importmod(fullname)
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pymonkey.py", line 94, in importmod
    return __import__(mod, fromlist=[str('__name__')], level=0)
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pip/__init__.py", line 1, in <module>
    from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pymonkey.py", line 166, in load_module
    hook_fn(module, self._entry_data[entry])
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pip_custom_platform/pymonkey.py", line 20, in pymonkey_patch
    from pip_custom_platform._main import get_main
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pymonkey.py", line 164, in load_module
    module = importmod(fullname)
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pymonkey.py", line 94, in importmod
    return __import__(mod, fromlist=[str('__name__')], level=0)
  File "/work/debian/yspofs/opt/venvs/yspofs/lib/python3.6/site-packages/pip_custom_platform/_main.py", line 17, in <module>
    from pip.commands import get_summaries
ModuleNotFoundError: No module named 'pip.commands'

patches welcome!

Looks like this was fixed in 38d9603 would you mind cutting a release so we can use it?

does not appear fixed even on master:

$ pip-custom-platform --help
Traceback (most recent call last):
  File "/tmp/pip-custom-platform/venv/bin/pip-custom-platform", line 11, in <module>
    load_entry_point('pip-custom-platform', 'console_scripts', 'pip-custom-platform')()
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 270, in entry
    tuple(patches) + ('--', original_entry_point) + tuple(argv)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 258, in main
    return entry.load()()
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2443, in load
    return self.resolve()
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2449, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 173, in load_module
    module = importmod(fullname)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 94, in importmod
    return __import__(mod, fromlist=[str('__name__')], level=0)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 173, in load_module
    module = importmod(fullname)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 94, in importmod
    return __import__(mod, fromlist=[str('__name__')], level=0)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 173, in load_module
    module = importmod(fullname)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 94, in importmod
    return __import__(mod, fromlist=[str('__name__')], level=0)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 173, in load_module
    module = importmod(fullname)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 94, in importmod
    return __import__(mod, fromlist=[str('__name__')], level=0)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pip/_internal/cli/cmdoptions.py", line 28, in <module>
    from pip._internal.models.target_python import TargetPython
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 173, in load_module
    module = importmod(fullname)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 94, in importmod
    return __import__(mod, fromlist=[str('__name__')], level=0)
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pip/_internal/models/target_python.py", line 3, in <module>
    from pip._internal.pep425tags import get_supported, version_info_to_nodot
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/tmp/pip-custom-platform/venv/lib/python3.6/site-packages/pymonkey.py", line 175, in load_module
    hook_fn(module, self._entry_data[entry])
  File "/tmp/pip-custom-platform/pip_custom_platform/pymonkey.py", line 16, in pymonkey_patch
    mod.get_platform = get_platform_func(args, mod.get_platform)
AttributeError: module 'pip._internal.pep425tags' has no attribute 'get_platform'

welp

yeah looks like the pep425 implementation moved into packaging -- so probably just need to update the patching code for that -- shouldn't be too bad

this might help you get started on a patch, there's more to fix though:

diff --git a/pip_custom_platform/pymonkey.py b/pip_custom_platform/pymonkey.py
index facf730..545a181 100644
--- a/pip_custom_platform/pymonkey.py
+++ b/pip_custom_platform/pymonkey.py
@@ -1,3 +1,15 @@
+PEP425_MODS = frozenset((
+    'pip.pep425tags',  # pip < 9
+    'pip._internal.pep425tags',  # pip < 20
+))
+MAIN_MODS = frozenset((
+    'pip',  # pip < 10
+    'pip._internal',  # pip < 19.3
+    'pip._internal.main',  # pip < 20
+    'pip._internal.cli.main',  # pip 20
+))
+
+
 def pymonkey_argparse(argv):
     # We want to parse --platform out as early as possible so we can do patches
     # based on it
@@ -11,11 +23,11 @@ def pymonkey_patch(mod, args):
     if mod.__name__ == 'distutils.util':
         from pip_custom_platform.default_platform import get_platform_func
         mod.get_platform = get_platform_func(args, mod.get_platform)
-    elif mod.__name__ in ('pip.pep425tags', 'pip._internal.pep425tags'):
+    elif mod.__name__ in PEP425_MODS and hasattr(mod, 'get_platform'):
         from pip_custom_platform.default_platform import get_platform_func
         mod.get_platform = get_platform_func(args, mod.get_platform)
         mod.supported_tags = mod.get_supported()
         mod.supported_tags_noarch = mod.get_supported(noarch=True)
-    elif mod.__name__ in ('pip', 'pip._internal') and hasattr(mod, 'main'):
+    elif mod.__name__ in MAIN_MODS and hasattr(mod, 'main'):
         from pip_custom_platform._main import get_main
         mod.main = get_main(mod.main)