Blame SOURCES/nowarn-pip._internal.main.patch

59709e
From 619782ad2d181fe2933ddf4edc7127fdc13dd0df Mon Sep 17 00:00:00 2001
59709e
From: Karolina Surma <ksurma@redhat.com>
59709e
Date: Mon, 10 May 2021 16:48:49 +0200
59709e
Subject: [PATCH] Don't warn the user about pip._internal.main() entrypoint
59709e
59709e
In Fedora, we use that in ensurepip and users cannot do anything about it,
59709e
this warning is juts moot. Also, the warning breaks CPython test suite.
59709e
59709e
Co-Authored-By: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
59709e
---
59709e
 src/pip/_internal/__init__.py          |  2 +-
59709e
 src/pip/_internal/utils/entrypoints.py | 19 ++++++++++---------
59709e
 tests/functional/test_cli.py           |  3 ++-
59709e
 3 files changed, 13 insertions(+), 11 deletions(-)
59709e
59709e
diff --git a/src/pip/_internal/__init__.py b/src/pip/_internal/__init__.py
59709e
index 6afb5c6..faf25af 100755
59709e
--- a/src/pip/_internal/__init__.py
59709e
+++ b/src/pip/_internal/__init__.py
59709e
@@ -16,4 +16,4 @@ def main(args: (Optional[List[str]]) = None) -> int:
59709e
     """
59709e
     from pip._internal.utils.entrypoints import _wrapper
59709e
 
59709e
-    return _wrapper(args)
59709e
+    return _wrapper(args, _nowarn=True)
59709e
diff --git a/src/pip/_internal/utils/entrypoints.py b/src/pip/_internal/utils/entrypoints.py
59709e
index 1504a12..07d941b 100644
59709e
--- a/src/pip/_internal/utils/entrypoints.py
59709e
+++ b/src/pip/_internal/utils/entrypoints.py
59709e
@@ -4,7 +4,7 @@ from typing import List, Optional
59709e
 from pip._internal.cli.main import main
59709e
 
59709e
 
59709e
-def _wrapper(args: Optional[List[str]] = None) -> int:
59709e
+def _wrapper(args: Optional[List[str]] = None, _nowarn: bool = False) -> int:
59709e
     """Central wrapper for all old entrypoints.
59709e
 
59709e
     Historically pip has had several entrypoints defined. Because of issues
59709e
@@ -16,12 +16,13 @@ def _wrapper(args: Optional[List[str]] = None) -> int:
59709e
     directing them to an appropriate place for help, we now define all of
59709e
     our old entrypoints as wrappers for the current one.
59709e
     """
59709e
-    sys.stderr.write(
59709e
-        "WARNING: pip is being invoked by an old script wrapper. This will "
59709e
-        "fail in a future version of pip.\n"
59709e
-        "Please see https://github.com/pypa/pip/issues/5599 for advice on "
59709e
-        "fixing the underlying issue.\n"
59709e
-        "To avoid this problem you can invoke Python with '-m pip' instead of "
59709e
-        "running pip directly.\n"
59709e
-    )
59709e
+    if not _nowarn:
59709e
+        sys.stderr.write(
59709e
+            "WARNING: pip is being invoked by an old script wrapper. This will "
59709e
+            "fail in a future version of pip.\n"
59709e
+            "Please see https://github.com/pypa/pip/issues/5599 for advice on "
59709e
+            "fixing the underlying issue.\n"
59709e
+            "To avoid this problem you can invoke Python with '-m pip' instead of "
59709e
+            "running pip directly.\n"
59709e
+        )
59709e
     return main(args)
59709e
diff --git a/tests/functional/test_cli.py b/tests/functional/test_cli.py
59709e
index e416315..7f57f67 100644
59709e
--- a/tests/functional/test_cli.py
59709e
+++ b/tests/functional/test_cli.py
59709e
@@ -31,4 +31,5 @@ def test_entrypoints_work(entrypoint, script):
59709e
     result = script.pip("-V")
59709e
     result2 = script.run("fake_pip", "-V", allow_stderr_warning=True)
59709e
     assert result.stdout == result2.stdout
59709e
-    assert "old script wrapper" in result2.stderr
59709e
+    if entrypoint[0] != "fake_pip = pip._internal:main":
59709e
+        assert "old script wrapper" in result2.stderr
59709e
-- 
59709e
2.32.0
59709e