nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pypa/pip
Pull request #12563 (2024-03-10 10:42:53)

Cache the user agent
This does not need to be computed multiple times in the same process.


pfmoore: lol unit tests failing because they expect to be able to change the environment and see changes in the function result.

I'm inclined to think the benefit of caching isn't sufficient to bother if we need to fix the tests, but it's your call as you'll be doing the work 😉

Patch:
diff --git a/src/pip/_internal/network/session.py b/src/pip/_internal/network/session.py
index e07b795b4..1765b4f6b 100644
--- a/src/pip/_internal/network/session.py
+++ b/src/pip/_internal/network/session.py
@@ -3,6 +3,7 @@ network request configuration and behavior.
 """
 
 import email.utils
+import functools
 import io
 import ipaddress
 import json
@@ -106,6 +107,7 @@ def looks_like_ci() -> bool:
     return any(name in os.environ for name in CI_ENVIRONMENT_VARIABLES)
 
 
+@functools.lru_cache(maxsize=1)
 def user_agent() -> str:
     """
     Return a string representing the user agent.


Test patch:
diff --git a/tests/unit/test_network_session.py b/tests/unit/test_network_session.py
index 2bb9317b7..3f1a596ad 100644
--- a/tests/unit/test_network_session.py
+++ b/tests/unit/test_network_session.py
@@ -10,10 +10,17 @@ from pip._vendor import requests
 
 from pip import __version__
 from pip._internal.models.link import Link
-from pip._internal.network.session import CI_ENVIRONMENT_VARIABLES, PipSession
+from pip._internal.network.session import (
+    CI_ENVIRONMENT_VARIABLES,
+    PipSession,
+    user_agent,
+)
 
 
 def get_user_agent() -> str:
+    # These tests are testing the computation of the user agent, so we want to
+    # avoid reusing cached values.
+    user_agent.cache_clear()
     return PipSession().headers["User-Agent"]
 
 
@@ -58,7 +65,7 @@ def test_user_agent__ci(
 
 def test_user_agent_user_data(monkeypatch: pytest.MonkeyPatch) -> None:
     monkeypatch.setenv("PIP_USER_AGENT_USER_DATA", "some_string")
-    assert "some_string" in PipSession().headers["User-Agent"]
+    assert "some_string" in get_user_agent()
 
 
 class TestPipSession:
Repository: pypa/pip
Pull request #12690 (2024-05-09 17:00:29)

Suggestion to check 'pip config debug' in case of InvalidProxyURL exception
When an `InvalidProxyURL` exception happens, an additional suggestion to check `pip config debug` is added. Attempt to fix issue #12649.

This is done by checking in function `create_os_error_message` if the type of the error corresponds to `InvalidProxyURL`.

A unit test is added in `tests/unit/test_command_install.py`, alongside with other existing tests for `create_os_error_message`.

ichard26: While I would like to see this land at some point, I don't think I'll get around to pushing this across the merge line soon. In any respect, I don't want to block 24.2 on this. 

Patch:
diff --git a/news/12649.feature.rst b/news/12649.feature.rst
new file mode 100644
index 000000000..127194655
--- /dev/null
+++ b/news/12649.feature.rst
@@ -0,0 +1,1 @@
+Suggest checking "pip config debug" in case of an InvalidProxyURL error.
diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py
index 5239d0104..49b8fd78b 100644
--- a/src/pip/_internal/commands/install.py
+++ b/src/pip/_internal/commands/install.py
@@ -8,6 +8,7 @@ from optparse import SUPPRESS_HELP, Values
 from typing import List, Optional
 
 from pip._vendor.packaging.utils import canonicalize_name
+from pip._vendor.requests.exceptions import InvalidProxyURL
 from pip._vendor.rich import print_json
 
 # Eagerly import self_outdated_check to avoid crashes. Otherwise,
@@ -766,6 +767,13 @@ def create_os_error_message(
             parts.append(permissions_part)
         parts.append(".\n")
 
+    # Suggest to check "pip config debug" in case of invalid proxy
+    if type(error) is InvalidProxyURL:
+        parts.append(
+            'Consider checking your local proxy configuration with "pip config debug"'
+        )
+        parts.append(".\n")
+
     # Suggest the user to enable Long Paths if path length is
     # more than 260
     if (


Test patch:
diff --git a/tests/unit/test_command_install.py b/tests/unit/test_command_install.py
index 5e7889fe1..e28edf644 100644
--- a/tests/unit/test_command_install.py
+++ b/tests/unit/test_command_install.py
@@ -3,6 +3,8 @@ from unittest import mock
 
 import pytest
 
+from pip._vendor.requests.exceptions import InvalidProxyURL
+
 from pip._internal.commands import install
 from pip._internal.commands.install import create_os_error_message, decide_user_install
 
@@ -108,6 +110,16 @@ class TestDecideUserInstall:
             " file permission\nConsider using the `--user` option or check the"
             " permissions.\n",
         ),
+        # Testing custom InvalidProxyURL with help message
+        #  show_traceback = True, using_user_site = True
+        (
+            InvalidProxyURL(),
+            True,
+            True,
+            "Could not install packages due to an OSError.\n"
+            "Consider checking your local proxy configuration"
+            ' with "pip config debug".\n',
+        ),
     ],
 )
 def test_create_os_error_message(
Repository: pypa/pip
Pull request #12710 (2024-05-19 14:42:38)

Enable verbose logging with `--debug`
This helps ensure that all relevant context is presented when a failure happens and diagnosis is being done through the use of `--debug`.

<!---
Thank you for your soon to be pull request. Before you submit this, please
double check to make sure that you've added a news file fragment. In pip we
generate our NEWS.rst from multiple news fragment files, and all pull requests
require either a news file fragment or a marker to indicate they don't require
one.

To read more about adding a news file fragment for your PR, please check out
our documentation at: https://pip.pypa.io/en/latest/development/contributing/#news-entries
-->


uranusjr: Should we do even larger? I have no idea how many levels of verbosity we actually have…
ichard26: Setting verbosity to 2 should be enough as it enables the DEBUG logging level:

https://github.com/pypa/pip/blob/af0087094e1a84552f180e011ad298ab1a725fa0/src/pip/_internal/utils/logging.py#L232-L243

This just needs a changelog entry, and it should be good to go!

Patch:
diff --git a/news/12710.feature.rst b/news/12710.feature.rst
new file mode 100644
index 000000000..4b65e4f04
--- /dev/null
+++ b/news/12710.feature.rst
@@ -0,0 +1,1 @@
+Using ``--debug`` also enables verbose logging.
diff --git a/src/pip/_internal/cli/base_command.py b/src/pip/_internal/cli/base_command.py
index 362f84b6b..509f7463b 100644
--- a/src/pip/_internal/cli/base_command.py
+++ b/src/pip/_internal/cli/base_command.py
@@ -172,6 +172,8 @@ class Command(CommandContextMixIn):
 
         # Set verbosity so that it can be used elsewhere.
         self.verbosity = options.verbose - options.quiet
+        if options.debug_mode:
+            self.verbosity = 2
 
         reconfigure(no_color=options.no_color)
         level_number = setup_logging(


Test patch:
diff --git a/tests/unit/test_base_command.py b/tests/unit/test_base_command.py
index 87665fbde..33d2a95a3 100644
--- a/tests/unit/test_base_command.py
+++ b/tests/unit/test_base_command.py
@@ -107,6 +107,12 @@ def test_handle_pip_version_check_called(mock_handle_version_check: Mock) -> Non
     mock_handle_version_check.assert_called_once()
 
 
+def test_debug_enables_verbose_logs() -> None:
+    cmd = FakeCommand()
+    cmd.main(["fake", "--debug"])
+    assert cmd.verbosity >= 2
+
+
 def test_log_command_success(fixed_time: None, tmpdir: Path) -> None:
     """Test the --log option logs when command succeeds."""
     cmd = FakeCommand()
Repository: pypa/pip
Pull request #13252 (2025-03-01 15:29:03)

Do not prefer star specified package as though it were a pinned package
Fixes https://github.com/pypa/pip/issues/13030

This is pretty simple, currently pip prefers pinned requirements, e.g. `requests==2.32.2`, when resolving so as to follow a path through the requirement graph that does not increase the number of possibilities.

However, the current code considers a requirement like `requests==2.*` to be pinned, which it is not. This fixes that.


Patch:
diff --git a/news/13252.bugfix.rst b/news/13252.bugfix.rst
new file mode 100644
index 000000000..477374589
--- /dev/null
+++ b/news/13252.bugfix.rst
@@ -0,0 +1,3 @@
+When choosing a preferred requirement for resolving dependencies
+do not consider a specifier with a * in it, e.g. "==1.*", to be a
+pinned specifier.
diff --git a/src/pip/_internal/resolution/resolvelib/provider.py b/src/pip/_internal/resolution/resolvelib/provider.py
index 74cdb9d80..40326001e 100644
--- a/src/pip/_internal/resolution/resolvelib/provider.py
+++ b/src/pip/_internal/resolution/resolvelib/provider.py
@@ -142,14 +142,14 @@ class PipProvider(_ProviderBase):
         else:
             candidate, ireqs = None, ()
 
-        operators = [
-            specifier.operator
+        operators: list[tuple[str, str]] = [
+            (specifier.operator, specifier.version)
             for specifier_set in (ireq.specifier for ireq in ireqs if ireq)
             for specifier in specifier_set
         ]
 
         direct = candidate is not None
-        pinned = any(op[:2] == "==" for op in operators)
+        pinned = any(((op[:2] == "==") and ("*" not in ver)) for op, ver in operators)
         unfree = bool(operators)
         requested_order = self._user_requested.get(identifier, math.inf)
 


Test patch:
diff --git a/tests/unit/resolution_resolvelib/test_provider.py b/tests/unit/resolution_resolvelib/test_provider.py
index 45536a9ea..d37076a93 100644
--- a/tests/unit/resolution_resolvelib/test_provider.py
+++ b/tests/unit/resolution_resolvelib/test_provider.py
@@ -52,6 +52,14 @@ def build_req_info(
             {},
             (True, False, False, True, math.inf, False, "pinned-package"),
         ),
+        # Star-specified package, i.e. with "*"
+        (
+            "star-specified-package",
+            {"star-specified-package": [build_req_info("star-specified-package==1.*")]},
+            [],
+            {},
+            (True, False, True, True, math.inf, False, "star-specified-package"),
+        ),
         # Package that caused backtracking
         (
             "backtrack-package",