#153 Fix CPython test to work with new pip
Closed 2 months ago by torsava. Opened 2 months ago by torsava.
rpms/ torsava/python3 pip-patch  into  master

@@ -0,0 +1,33 @@ 

+ From 164c3b7b1527ddec3351527edf238f14f829a243 Mon Sep 17 00:00:00 2001

+ From: Tomas Orsava <torsava@redhat.com>

+ Date: Wed, 20 Nov 2019 14:26:46 +0100

+ Subject: [PATCH] First try the new method for invoking pip

+ 

+ ---

+  Lib/ensurepip/__init__.py | 10 ++++++++--

+  1 file changed, 8 insertions(+), 2 deletions(-)

+ 

+ diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py

+ index fc0edec..084f908 100644

+ --- a/Lib/ensurepip/__init__.py

+ +++ b/Lib/ensurepip/__init__.py

+ @@ -24,8 +24,14 @@ def _run_pip(args, additional_paths=None):

+          sys.path = additional_paths + sys.path

+  

+      # Install the bundled software

+ -    import pip._internal

+ -    return pip._internal.main(args)

+ +    try:

+ +        # Try to import pip using the new method (pip19+)

19.3+

+ +        import pip._internal.main

+ +        return pip._internal.main.main(args)

+ +    except ImportError:

+ +        # Try importing pip using the old method

+ +        import pip._internal

+ +        return pip._internal.main(args)

+  

+  

+  def version():

+ -- 

+ 2.20.1

+ 

file modified
+8

@@ -264,6 +264,13 @@ 

  # See https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/57#comment-27426

  Patch328: 00328-pyc-timestamp-invalidation-mode.patch

  

+ # 00336 #

+ # pip19+ needs to be invoked differently than previous versions, let's try both

+ #   invocations

+ # Downstream only: When upstream switches to new version of pip, they'll just

+ #   switch to the new invocation instead of trying both

+ Patch336: 00336-first-try-the-new-method-for-invoking-pip.patch

+ 

  # (New patches go here ^^^)

  #

  # When adding new patches to "python" and "python3" in Fedora, EL, etc.,

@@ -601,6 +608,7 @@ 

  %patch251 -p1

  %patch274 -p1

  %patch328 -p1

+ %patch336 -p1

  

  

  # Remove files that should be generated by the build

Failure with the new pip:

======================================================================
FAIL: test_with_pip (test.test_venv.EnsurePipTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.8.0/Lib/test/test_venv.py", line 430, in do_test_with_pip
    self.run_with_capture(venv.create, self.env_dir,
  File "/builddir/build/BUILD/Python-3.8.0/Lib/test/test_venv.py", line 76, in run_with_capture
    func(*args, **kwargs)
subprocess.CalledProcessError: Command '['/tmp/tmpw0i_0yft/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.8.0/Lib/test/test_venv.py", line 490, in test_with_pip
    self.do_test_with_pip(False)
  File "/builddir/build/BUILD/Python-3.8.0/Lib/test/test_venv.py", line 438, in do_test_with_pip
    self.fail(msg.format(exc, details))
AssertionError: Command '['/tmp/tmpw0i_0yft/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
**Subprocess Output**
Traceback (most recent call last):
  File "/builddir/build/BUILD/Python-3.8.0/Lib/runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/builddir/build/BUILD/Python-3.8.0/Lib/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/builddir/build/BUILD/Python-3.8.0/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/builddir/build/BUILD/Python-3.8.0/Lib/ensurepip/__init__.py", line 208, in _main
    return _bootstrap(
  File "/builddir/build/BUILD/Python-3.8.0/Lib/ensurepip/__init__.py", line 127, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/builddir/build/BUILD/Python-3.8.0/Lib/ensurepip/__init__.py", line 39, in _run_pip
    return pip._internal.main(args)
AttributeError: module 'pip._internal' has no attribute 'main'
----------------------------------------------------------------------

Please, could you open a PR in https://github.com/fedora-python/cpython/tree/fedora-3.8 ?

We also either need to do this to all our Pythons, or reconsider how we are doing things.

We also either need to do this to all our Pythons, or reconsider how we are doing things.

The only thing we can reconsider is re-bundling pip in this case...

Or maybe patching pip to still support the old method?

Good idea as a temporary fix. And in the long run we can convince CPython and pip to agree on a stable supported API.

Rescinding this PR in favour of that solution.

Pull-Request has been closed by torsava

2 months ago