internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: pypa/pip

Issue:
Deprecation warning about in-place builds is confusing/ambiguous
### Description

I have trouble understanding the text of the deprecation message:

> DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
   pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.

### Expected behavior

I would expect that after reading the deprecation message once, I understand roughly what is going to be changed, what will be removed in pip 21.3, and what I can do about it.

For more details, see https://github.com/pypa/pip/issues/7555#issuecomment-873612344

### pip version

21.1.3

### Python version

3.9.5

### OS

Linux

### How to Reproduce

Run `pip install .`


### Output

```sh-session
DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
   pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.
```


### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).


Discussion:
Whee! Thanks for filing this issue and PR separately @maresb! Much appreciated! ^>^

Resolving patch:
diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py
--- a/src/pip/_internal/operations/prepare.py
+++ b/src/pip/_internal/operations/prepare.py
@@ -216,14 +216,16 @@ def unpack_url(
     # be removed.
     if link.is_existing_dir():
         deprecated(
-            "A future pip version will change local packages to be built "
-            "in-place without first copying to a temporary directory. "
-            "We recommend you use --use-feature=in-tree-build to test "
-            "your packages with this new behavior before it becomes the "
-            "default.\n",
+            reason=(
+                "pip copied the source tree into a temporary directory "
+                "before building it. This is changing so that packages "
+                "are built in-place "
+                'within the original source tree ("in-tree build").'
+            ),
             replacement=None,
             gone_in="21.3",
-            issue=7555
+            feature_flag="in-tree-build",
+            issue=7555,
         )
         if os.path.isdir(location):
             rmtree(location)


Test patch:
Repository: pypa/pip

Issue:
Use sysconfig.get_preferred_scheme etc.
Todo to self. This has been implemented for 3.10 and we should support is in 21.2.


Discussion:

Resolving patch:
diff --git a/src/pip/_internal/locations/_sysconfig.py b/src/pip/_internal/locations/_sysconfig.py
--- a/src/pip/_internal/locations/_sysconfig.py
+++ b/src/pip/_internal/locations/_sysconfig.py
@@ -24,6 +24,8 @@
 
 _AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())
 
+_HAS_PREFERRED_SCHEME_API = sys.version_info >= (3, 10)
+
 
 def _infer_prefix() -> str:
     """Try to find a prefix scheme for the current platform.
@@ -39,6 +41,8 @@ def _infer_prefix() -> str:
 
     If none of the above works, fall back to ``posix_prefix``.
     """
+    if _HAS_PREFERRED_SCHEME_API:
+        return sysconfig.get_preferred_scheme("prefix")  # type: ignore
     os_framework_global = is_osx_framework() and not running_under_virtualenv()
     if os_framework_global and "osx_framework_library" in _AVAILABLE_SCHEMES:
         return "osx_framework_library"
@@ -57,6 +61,8 @@ def _infer_prefix() -> str:
 
 def _infer_user() -> str:
     """Try to find a user scheme for the current platform."""
+    if _HAS_PREFERRED_SCHEME_API:
+        return sysconfig.get_preferred_scheme("user")  # type: ignore
     if is_osx_framework() and not running_under_virtualenv():
         suffixed = "osx_framework_user"
     else:
@@ -70,6 +76,8 @@ def _infer_user() -> str:
 
 def _infer_home() -> str:
     """Try to find a home for the current platform."""
+    if _HAS_PREFERRED_SCHEME_API:
+        return sysconfig.get_preferred_scheme("home")  # type: ignore
     suffixed = f"{os.name}_home"
     if suffixed in _AVAILABLE_SCHEMES:
         return suffixed


Test patch:
Repository: pypa/pip

Issue:
pip config list -v
### Description

On the latest version of pip (21.2.2), I'm experiencing issues with the command "pip config list -v".

When running with pip=21.1.3, it lists the files needed for configuration. When running on the latest version, there are no files listed.

### Expected behavior

A list of config files.

### pip version

21.2.2

### Python version

3.8.5

### OS

Windows 10

### How to Reproduce

conda create -n name python=3.8.5
conda activate name
pip config list -v

### Output

_No response_

### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).


Discussion:
We changed the error level, the output is now available iin `-vv`. I think this should go in `-v` though, so a PR to put it back would be welcomed. You need to use `logger.verbose()` istead of `logger.debug()` (there are a few existing usages you can reference).

Resolving patch:
diff --git a/src/pip/_internal/configuration.py b/src/pip/_internal/configuration.py
--- a/src/pip/_internal/configuration.py
+++ b/src/pip/_internal/configuration.py
@@ -13,7 +13,6 @@
 
 import configparser
 import locale
-import logging
 import os
 import sys
 from typing import Any, Dict, Iterable, List, NewType, Optional, Tuple
@@ -24,6 +23,7 @@
 )
 from pip._internal.utils import appdirs
 from pip._internal.utils.compat import WINDOWS
+from pip._internal.utils.logging import getLogger
 from pip._internal.utils.misc import ensure_dir, enum
 
 RawConfigParser = configparser.RawConfigParser  # Shorthand
@@ -43,7 +43,7 @@
 OVERRIDE_ORDER = kinds.GLOBAL, kinds.USER, kinds.SITE, kinds.ENV, kinds.ENV_VAR
 VALID_LOAD_ONLY = kinds.USER, kinds.GLOBAL, kinds.SITE
 
-logger = logging.getLogger(__name__)
+logger = getLogger(__name__)
 
 
 # NOTE: Maybe use the optionx attribute to normalize keynames.
@@ -250,7 +250,7 @@ def _load_config_files(self) -> None:
                 self._parsers[variant].append((fname, parser))
 
     def _load_file(self, variant: Kind, fname: str) -> RawConfigParser:
-        logger.debug("For variant '%s', will try loading '%s'", variant, fname)
+        logger.verbose("For variant '%s', will try loading '%s'", variant, fname)
         parser = self._construct_parser(fname)
 
         for section in parser.sections():


Test patch:
Repository: pypa/pip

Issue:
21.3 regression with legacy resolver
Assuming the following project with an empty `pyproject.toml` and the following `setup.cfg`:

```ini
[metadata]
name = pkgb
version = 1.0

[options]
install_requires =
    wrapt
```

We get the following stack trace, using pip main branch, today:

```console
$ pip install --use-deprecated=legacy-resolver -e ./pkgb
Obtaining file:///home/me/tmp/brol/pkgb
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: wrapt in /home/me/.virtualenvs/tempenv-49ea1126817e6/lib/python3.8/site-packages (from pkgb==1.0) (1.12.1)
ERROR: Exception:
Traceback (most recent call last):
  File "/home/me/pip/src/pip/_internal/cli/base_command.py", line 179, in exc_logging_wrapper
    status = run_func(*args)
  File "/home/me/pip/src/pip/_internal/cli/req_command.py", line 203, in wrapper
    return func(self, options, args)
  File "/home/me/pip/src/pip/_internal/commands/install.py", line 334, in run
    requirement_set = resolver.resolve(
  File "/home/me/pip/src/pip/_internal/resolution/legacy/resolver.py", line 181, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "/home/me/pip/src/pip/_internal/resolution/legacy/resolver.py", line 382, in _resolve_one
    _check_dist_requires_python(
  File "/home/me/pip/src/pip/_internal/resolution/legacy/resolver.py", line 75, in _check_dist_requires_python
    requires_python = str(dist.requires_python)
  File "/home/me/pip/src/pip/_vendor/pkg_resources/__init__.py", line 2816, in __getattr__
    return getattr(self._provider, attr)
AttributeError: 'PathMetadata' object has no attribute 'requires_python'
```



Discussion:
I don't understand what's happening here. @uranusjr can you help ?
It's probably related to some of the importlib.metadata abstraction I made. I'll investigate next week (busy weekend).

The `dist` in the `_check_dist_requires_python` should not be a `PathMetadata` object, but the `Distribution` abstraction class defined in `pip._internal.metadata`. Something in the call chain passed an incorrect value.

Resolving patch:
diff --git a/src/pip/_internal/distributions/installed.py b/src/pip/_internal/distributions/installed.py
--- a/src/pip/_internal/distributions/installed.py
+++ b/src/pip/_internal/distributions/installed.py
@@ -11,8 +11,10 @@ class InstalledDistribution(AbstractDistribution):
     """
 
     def get_metadata_distribution(self) -> BaseDistribution:
+        from pip._internal.metadata.pkg_resources import Distribution as _Dist
+
         assert self.req.satisfied_by is not None, "not actually installed"
-        return self.req.satisfied_by
+        return _Dist(self.req.satisfied_by)
 
     def prepare_distribution_metadata(
         self, finder: PackageFinder, build_isolation: bool


Test patch:
Repository: pypa/pip

Issue:
pip backtracking output to link to "reduce backtracking" doc
Regarding the line in pip's resolver's output:

> INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. If you want to abort this run, you can press Ctrl + C to do so. To improve how pip performs, tell us what happened here: https://pip.pypa.io/surveys/backtracking

I would also like for the pip output to not only link to the survey but also to the specific "how to reduce backtracking" documentation we wrote:

https://pip.pypa.io/en/latest/user_guide/#possible-ways-to-reduce-backtracking-occurring


Discussion:

Resolving patch:
diff --git a/src/pip/_internal/resolution/resolvelib/reporter.py b/src/pip/_internal/resolution/resolvelib/reporter.py
--- a/src/pip/_internal/resolution/resolvelib/reporter.py
+++ b/src/pip/_internal/resolution/resolvelib/reporter.py
@@ -27,8 +27,8 @@ def __init__(self) -> None:
             13: (
                 "This is taking longer than usual. You might need to provide "
                 "the dependency resolver with stricter constraints to reduce "
-                "runtime. If you want to abort this run, you can press "
-                "Ctrl + C to do so."
+                "runtime. See https://pip.pypa.io/warnings/backtracking for "
+                "guidance. If you want to abort this run, press Ctrl + C."
             ),
         }
 


Test patch:
Repository: pypa/pip

Issue:
Metadata preparation log was wrong indent
### Description

With pyproject.toml:

```console
❯ pip install -e ./pkga
Obtaining file:///home/me/tmp/pkga
  Installing build dependencies ... done
  Getting requirements to build editable ... done
    Preparing editable metadata (pyproject.toml) ... done
    Build backend does not support editables, falling back to setup.py egg_info.
    Preparing metadata (setup.py) ... done
...
```

Without pyproject.toml:

```console
❯ pip install -e ./pkga
Obtaining file:///home/me/tmp/pkga
    Preparing metadata (setup.py) ... done
```

Notice the indent of the metadata preparation steps. With pyproject.toml, they appear to be "inside" *Getting requirements to build editable*, which is not correct as metadata preparation is done *after* that step. Without pyproject.toml, the indent is 4 characters instead of two.

### Expected behavior

Dedent metadata preparation log entries.


### pip version

21.3dev, 21.2 as well

### Python version

irrelevant

### OS

Linux, probably irrelevant

### How to Reproduce

pip install -e of any project.

### Output

_No response_

### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).


Discussion:
Note this also applies to non-editable installs with pyproject.toml.

Resolving patch:
diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py
--- a/src/pip/_internal/req/req_install.py
+++ b/src/pip/_internal/req/req_install.py
@@ -42,7 +42,6 @@
     direct_url_from_link,
 )
 from pip._internal.utils.hashes import Hashes
-from pip._internal.utils.logging import indent_log
 from pip._internal.utils.misc import (
     ask_path_exists,
     backup_dir,
@@ -587,11 +586,10 @@ def prepare_metadata(self) -> None:
         """
         assert self.source_dir
 
-        with indent_log():
-            if self.editable and self.permit_editable_wheels:
-                self.metadata_directory = self._generate_editable_metadata()
-            else:
-                self.metadata_directory = self._generate_metadata()
+        if self.editable and self.permit_editable_wheels:
+            self.metadata_directory = self._generate_editable_metadata()
+        else:
+            self.metadata_directory = self._generate_metadata()
 
         # Act on the newly generated metadata, based on the name and version.
         if not self.name:


Test patch:
Repository: pypa/pip

Issue:
Document PIP_REQUIRE_VIRTUALENV and --require-venv
### Description

The documentation does not seem to mention PIP_REQUIRE_VIRTUALENV or --require-venv anywhere.

### Expected behavior

_No response_

### pip version

20.3.3

### Python version

3.9

### OS

Linux

### How to Reproduce

Search for `PIP_REQUIRE_VIRTUALENV` in the docs or this repo.

### Output

_No response_

### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).


Discussion:
You're right. The documentation only talks about a bug fix related to `PIP_REQUIRE_VIRTUALENV`, and that's all. Maybe we should add a document to explain this
Let's consider this as a feature request, since it is not a "bug" at all. 

Resolving patch:
diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py
--- a/src/pip/_internal/cli/cmdoptions.py
+++ b/src/pip/_internal/cli/cmdoptions.py
@@ -177,13 +177,15 @@ class PipOption(Option):
 
 require_virtualenv: Callable[..., Option] = partial(
     Option,
-    # Run only if inside a virtualenv, bail if not.
     "--require-virtualenv",
     "--require-venv",
     dest="require_venv",
     action="store_true",
     default=False,
-    help=SUPPRESS_HELP,
+    help=(
+        "Allow pip to only run in a virtual environment; "
+        "exit with an error otherwise."
+    ),
 )
 
 verbose: Callable[..., Option] = partial(


Test patch:
Repository: pypa/pip

Issue:
EncodingWarning in configuration.py
### Description

When setting `PYTHONWARNDEFAULTENCODING=1` on Python 3.10, pip emits the following warning:

```
/path/to/pip/_internal/configuration.py:270: EncodingWarning: 'encoding' argument not specified
  parser.read(fname)
```

Maybe `parser.read(fname, encoding="utf-8")` should be used.

### Expected behavior

Expect to see no warning.

### pip version

21.3

### Python version

3.10.0

### OS

Windows 11

### How to Reproduce

Using Python 3.10 with environment variable `PYTHONWARNDEFAULTENCODING=1` set, run any pip command (e.g. `pip list`).

### Output

_No response_

### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).


Discussion:
This has been discussed previously. Unfortunately pip needs to read this configuration file in platform encoding for now, until at least we drop support for distutils (which will not happen in ~1 year). One possibility would be to explicitly set the platform encoding, which I believe is `locale.getpreferredencoding(False)`. A pull request for this would be much welcomed.

Resolving patch:
diff --git a/src/pip/_internal/build_env.py b/src/pip/_internal/build_env.py
--- a/src/pip/_internal/build_env.py
+++ b/src/pip/_internal/build_env.py
@@ -93,7 +93,9 @@ def __init__(self) -> None:
         self._site_dir = os.path.join(temp_dir.path, "site")
         if not os.path.exists(self._site_dir):
             os.mkdir(self._site_dir)
-        with open(os.path.join(self._site_dir, "sitecustomize.py"), "w") as fp:
+        with open(
+            os.path.join(self._site_dir, "sitecustomize.py"), "w", encoding="utf-8"
+        ) as fp:
             fp.write(
                 textwrap.dedent(
                     """
diff --git a/src/pip/_internal/configuration.py b/src/pip/_internal/configuration.py
--- a/src/pip/_internal/configuration.py
+++ b/src/pip/_internal/configuration.py
@@ -266,14 +266,13 @@ def _construct_parser(self, fname: str) -> RawConfigParser:
         # Doing this is useful when modifying and saving files, where we don't
         # need to construct a parser.
         if os.path.exists(fname):
+            locale_encoding = locale.getpreferredencoding(False)
             try:
-                parser.read(fname)
+                parser.read(fname, encoding=locale_encoding)
             except UnicodeDecodeError:
                 # See https://github.com/pypa/pip/issues/4963
                 raise ConfigurationFileCouldNotBeLoaded(
-                    reason="contains invalid {} characters".format(
-                        locale.getpreferredencoding(False)
-                    ),
+                    reason=f"contains invalid {locale_encoding} characters",
                     fname=fname,
                 )
             except configparser.Error as error:


Test patch:
Repository: pypa/pip

Issue:
Unable to delete packages installed as editable from Windows junction link
### Description

If a package with a path containing a Windows junction link is installed as editable, an egg-link `AssertionError` occurs that the package path does not match when uninstalling.

```
AssertionError: Egg-link \path\that\link\include\test_pkg does not match installed location of test-pkg (at \real\package\path)
```


### Expected behavior

Deleting or reinstalling packages should not raise `AssertionError: Egg-link`.

### pip version

21.2.2

### Python version

3.8.8

### OS

Windows 10 (version 1909)

### How to Reproduce

```batch
# Create or locate test package to original directory
code src\test_pkg

# Make junction link
mklink /J src-link src

# Install package over junction link path
cd src-link\test_pkg
pip install -e .

# Uninstall or re-install package over junction link
pip uninstall test_pkg

>> Raise AssertionError
```

### Output

```sh-session
ERROR: Exception:
Traceback (most recent call last):
  File "C:\Users\jiunbae\conda\lib\site-packages\pip\_internal\cli\base_command.py", line 173, in _main
    status = self.run(options, args)
  File "C:\Users\jiunbae\conda\lib\site-packages\pip\_internal\cli\req_command.py", line 203, in wrapper
    return func(self, options, args)
  File "C:\Users\jiunbae\conda\lib\site-packages\pip\_internal\commands\install.py", line 390, in run
    installed = install_given_reqs(
  File "C:\Users\jiunbae\conda\lib\site-packages\pip\_internal\req\__init__.py", line 66, in install_given_reqs
    uninstalled_pathset = requirement.uninstall(
  File "C:\Users\jiunbae\conda\lib\site-packages\pip\_internal\req\req_install.py", line 632, in uninstall
    uninstalled_pathset = UninstallPathSet.from_dist(dist)
  File "C:\Users\jiunbae\conda\lib\site-packages\pip\_internal\req\req_uninstall.py", line 527, in from_dist
    assert (link_pointer == dist.location), (
AssertionError: Egg-link e:\workspace-link\test_pkg does not match installed location of test-pkg (at e:\workspace\test_pkg)
```


### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).


Discussion:

Resolving patch:
diff --git a/src/pip/_internal/req/req_uninstall.py b/src/pip/_internal/req/req_uninstall.py
--- a/src/pip/_internal/req/req_uninstall.py
+++ b/src/pip/_internal/req/req_uninstall.py
@@ -527,7 +527,7 @@ def from_dist(cls, dist: BaseDistribution) -> "UninstallPathSet":
             # above, so this only covers the setuptools-style editable.
             with open(develop_egg_link) as fh:
                 link_pointer = os.path.normcase(fh.readline().strip())
-            assert link_pointer == dist_location, (
+            assert os.path.samefile(link_pointer, dist_location), (
                 f"Egg-link {link_pointer} does not match installed location of "
                 f"{dist.raw_name} (at {dist_location})"
             )


Test patch:
Repository: pypa/pip

Issue:
Print the exception via rich.traceback, when running with `--debug`
This would mean that exporting `PIP_DEBUG=1` and running tests with this would print a detailed traceback with information about locals! It would make debugging easier, especially in tests when there's a weird failure.

Plus, I'm pretty sure anyone passing `--debug` would likely appreciate this anyway. :)


Discussion:

Resolving patch:
diff --git a/src/pip/_internal/cli/base_command.py b/src/pip/_internal/cli/base_command.py
--- a/src/pip/_internal/cli/base_command.py
+++ b/src/pip/_internal/cli/base_command.py
@@ -10,6 +10,8 @@
 from optparse import Values
 from typing import Any, Callable, List, Optional, Tuple
 
+from pip._vendor.rich import traceback as rich_traceback
+
 from pip._internal.cli import cmdoptions
 from pip._internal.cli.command_context import CommandContextMixIn
 from pip._internal.cli.parser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
@@ -215,6 +217,7 @@ def exc_logging_wrapper(*args: Any) -> int:
                 run = intercepts_unhandled_exc(self.run)
             else:
                 run = self.run
+                rich_traceback.install(show_locals=True)
             return run(options, args)
         finally:
             self.handle_pip_version_check(options)


Test patch: