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

Issue:
Packages installed from wheel have incorrect permissions on Windows
On Windows, packages installed from wheels retain the permissions of the installing user's temp directory, rather than inheriting the permissions of the destination site-packages directory.  This means users who aren't administrators and aren't the installing user can't access the installed package.

Output from accesschk:

```
C:\Users\admin\AppData\Local\Temp>accesschk -q -d .
C:\Users\admin\AppData\Local\Temp
  RW NT AUTHORITY\SYSTEM
  RW BUILTIN\Administrators
  RW MYPC\admin

C:\Users\admin\AppData\Local\Temp>accesschk -q -d C:\Python33\Lib\site-packages
C:\Python33\Lib\site-packages
  RW BUILTIN\Administrators
  RW NT AUTHORITY\SYSTEM
  R  BUILTIN\Users

C:\Users\admin\AppData\Local\Temp>accesschk -q C:\Python33\Lib\site-packages\sqlalchemy\__init__.py
C:\Python33\Lib\site-packages\sqlalchemy\__init__.py
  RW NT AUTHORITY\SYSTEM
  RW BUILTIN\Administrators
  RW MYPC\admin
```

This doesn't seem to happen with packages that aren't installed from wheels.  I would assume (and Process Monitor suggests) that the files installed from wheels are moved instead of copied (on Windows, files that are moved retain their permissions; new/copied files inherit the parent directory's).  This was tested on Windows 7 64-bit with Python 2.7.6 and 3.3.3.



Discussion:

Resolving patch:
diff --git a/pip/wheel.py b/pip/wheel.py
--- a/pip/wheel.py
+++ b/pip/wheel.py
@@ -200,10 +200,20 @@ def clobber(source, dest, is_base, fixer=None, filter=None):
                 # uninstalled.
                 if not os.path.exists(destdir):
                     os.makedirs(destdir)
-                # use copy2 (not move) to be extra sure we're not moving
-                # directories over; copy2 fails for directories.  this would
-                # fail tests (not during released/user execution)
-                shutil.copy2(srcfile, destfile)
+
+                # We use copyfile (not move, copy, or copy2) to be extra sure
+                # that we are not moving directories over (copyfile fails for
+                # directories) as well as to ensure that we are not copying
+                # over any metadata because we want more control over what
+                # metadata we actually copy over.
+                shutil.copyfile(srcfile, destfile)
+
+                # Copy over the metadata for the file, currently this only
+                # includes the atime and mtime.
+                st = os.stat(srcfile)
+                if hasattr(os, "utime"):
+                    os.utime(destfile, (st.st_atime, st.st_mtime))
+
                 changed = False
                 if fixer:
                     changed = fixer(destfile)


Test patch:
Repository: pypa/pip

Issue:
pip show returns success on failure
```
(venv)f@foo:~$ pip --version
pip 1.3.1 from bar/venv/lib/python2.6/site-packages (python 2.6)
(venv)f@foo:~$ pip show not_installed_package && echo installed || echo fail
installed
```

Should echo 'fail' because package is not installed



Discussion:

Resolving patch:
diff --git a/pip/commands/show.py b/pip/commands/show.py
--- a/pip/commands/show.py
+++ b/pip/commands/show.py
@@ -4,6 +4,7 @@
 import os
 
 from pip.basecommand import Command
+from pip.status_codes import SUCCESS, ERROR
 from pip._vendor import pkg_resources
 
 
@@ -31,11 +32,13 @@ def __init__(self, *args, **kw):
     def run(self, options, args):
         if not args:
             logger.warning('ERROR: Please provide a package name or names.')
-            return
+            return ERROR
         query = args
 
         results = search_packages_info(query)
-        print_results(results, options.files)
+        if not print_results(results, options.files):
+            return ERROR
+        return SUCCESS
 
 
 def search_packages_info(query):
@@ -79,7 +82,9 @@ def print_results(distributions, list_all_files):
     """
     Print the informations from installed distributions found.
     """
+    results_printed = False
     for dist in distributions:
+        results_printed = True
         logger.info("---")
         logger.info("Name: %s" % dist['name'])
         logger.info("Version: %s" % dist['version'])
@@ -92,3 +97,4 @@ def print_results(distributions, list_all_files):
                     logger.info("  %s" % line.strip())
             else:
                 logger.info("Cannot locate installed-files.txt")
+    return results_printed


Test patch:
diff --git a/tests/functional/test_show.py b/tests/functional/test_show.py
--- a/tests/functional/test_show.py
+++ b/tests/functional/test_show.py
@@ -64,7 +64,7 @@ def test_missing_argument(script):
     """
     Test show command with no arguments.
     """
-    result = script.pip('show')
+    result = script.pip('show', expect_error=True)
     assert 'ERROR: Please provide a package name or names.' in result.stdout
Repository: pypa/pip

Issue:
PEP 440 local version identifiers cannot be installed
This is with current pip development version.

```
$ pip install -U --trusted-host pypi.zestsoftware.nl -f http://pypi.zestsoftware.nl/public/packagingtest/ myproject==1.1+maurits.3
Collecting myproject==1.1+maurits.3
  Could not find a version that satisfies the requirement myproject==1.1+maurits.3 (from versions: )
  No distributions matching the version for myproject==1.1+maurits.3
```

It should be installable, because the distribution is there.  A direct install works:

```
pip install http://pypi.zestsoftware.nl/public/packagingtest/myproject-1.1+maurits.3.zip
```

For more info, see [distutils-sig](https://mail.python.org/pipermail/distutils-sig/2014-December/025414.html)



Discussion:

Resolving patch:
diff --git a/pip/index.py b/pip/index.py
--- a/pip/index.py
+++ b/pip/index.py
@@ -609,7 +609,7 @@ def _get_pages(self, locations, req):
                 all_locations.append(link)
 
     _egg_fragment_re = re.compile(r'#egg=([^&]*)')
-    _egg_info_re = re.compile(r'([a-z0-9_.]+)-([a-z0-9_.-]+)', re.I)
+    _egg_info_re = re.compile(r'([a-z0-9_.]+)-([a-z0-9_.!+-]+)', re.I)
     _py_version_re = re.compile(r'-py([123]\.?[0-9]?)$')
 
     def _sort_links(self, links):


Test patch:
Repository: pypa/pip

Issue:
Fix pip install -v fails
```
Traceback (most recent call last):
  File "/var/lib/jenkins/.pyenv/versions/3.4.2/lib/python3.4/logging/__init__.py", line 978, in emit
    msg = self.format(record)
  File "/var/lib/jenkins/venv/lib/python3.4/site-packages/pip/utils/logging.py", line 103, in format

▽
    msg = logging.StreamHandler.format(self, record)
  File "/var/lib/jenkins/.pyenv/versions/3.4.2/lib/python3.4/logging/__init__.py", line 828, in format
    return fmt.format(record)
  File "/var/lib/jenkins/venv/lib/python3.4/site-packages/pip/utils/logging.py", line 49, in format
    formatted = logging.Formatter.format(self, record)
  File "/var/lib/jenkins/.pyenv/versions/3.4.2/lib/python3.4/logging/__init__.py", line 565, in format
    record.message = record.getMessage()
  File "/var/lib/jenkins/.pyenv/versions/3.4.2/lib/python3.4/logging/__init__.py", line 328, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "venv/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/var/lib/jenkins/venv/lib/python3.4/site-packages/pip/__init__.py", line 217, in main
    return command.main(cmd_args)
  File "/var/lib/jenkins/venv/lib/python3.4/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/var/lib/jenkins/venv/lib/python3.4/site-packages/pip/commands/install.py", line 339, in run
    requirement_set.prepare_files(finder)
  File "/var/lib/jenkins/venv/lib/python3.4/site-packages/pip/req/req_set.py", line 235, in prepare_files
    req_to_install, self.upgrade)
  File "/var/lib/jenkins/venv/lib/python3.4/site-packages/pip/index.py", line 512, in find_requirement
    or "none",
Message: 'Installed version (%s) is most up-to-date (past versions: '
Arguments: ('%s)', '2.3.1', '2.3.1, 2.3.1, 2.3.1, 2.3.0, 2.3.0, 2.3.0, 2.2.0, 2.2.0, 2.2.0, 2.1.0, 2.1.0, 2.1.0, 2.0.0, 2.0.0, 2.0.0, 1.2.1, 1.2.1, 1.2.0, 1.2.0, 1.1.0, 1.1.0, 1.0.0, 1.0.0, 0.13.2, 0.13.2, 0.13.1, 0.13.1, 0.13, 0.13, 0.12.1, 0.12.1, 0.12, 0.12, 0.11, 0.11, 0.10.2, 0.10.2, 0.10.1, 0.10.1, 0.10')
```



Discussion:

Resolving patch:
diff --git a/pip/index.py b/pip/index.py
--- a/pip/index.py
+++ b/pip/index.py
@@ -505,7 +505,7 @@ def mkurl_pypi_url(url):
         if applicable_versions[0].location is INSTALLED_VERSION:
             # We have an existing version, and its the best version
             logger.debug(
-                'Installed version (%s) is most up-to-date (past versions: ',
+                'Installed version (%s) is most up-to-date (past versions: '
                 '%s)',
                 req.satisfied_by.version,
                 ', '.join(str(i.version) for i in applicable_versions[1:])


Test patch:
Repository: pypa/pip

Issue:
regression: TypeError when using dependency_links
Installing a package using dependency_links produces the following traceback:

```
Exception:
Traceback (most recent call last):
  File ".../lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File ".../lib/python2.7/site-packages/pip/commands/install.py", line 339, in run
    requirement_set.prepare_files(finder)
  File ".../lib/python2.7/site-packages/pip/req/req_set.py", line 333, in prepare_files
    upgrade=self.upgrade,
  File ".../lib/python2.7/site-packages/pip/index.py", line 363, in find_requirement
    link.url for p, link, version in dependency_versions
TypeError: 'InstallationCandidate' object is not iterable
```

The issue seems to affect only [this](https://github.com/pypa/pip/blob/develop/pip/index.py#L360) logging call, since the installation proceeds normally if I comment the call out.

Tested under python 2.7 on Ubuntu 14.04 and OS X 10.10



Discussion:

Resolving patch:
diff --git a/pip/index.py b/pip/index.py
--- a/pip/index.py
+++ b/pip/index.py
@@ -360,7 +360,7 @@ def mkurl_pypi_url(url):
             logger.debug(
                 'dependency_links found: %s',
                 ', '.join([
-                    link.url for p, link, version in dependency_versions
+                    version.location.url for version in dependency_versions
                 ])
             )
         file_versions = list(


Test patch:
diff --git a/tests/unit/test_finder.py b/tests/unit/test_finder.py
--- a/tests/unit/test_finder.py
+++ b/tests/unit/test_finder.py
@@ -273,6 +273,23 @@ def test_finder_priority_file_over_page(data):
     assert link.url.startswith("file://")
 
 
+def test_finder_deplink():
+    """
+    Test PackageFinder with dependency links only
+    """
+    req = InstallRequirement.from_line('gmpy==1.15', None)
+    finder = PackageFinder(
+        [],
+        [],
+        process_dependency_links=True,
+        session=PipSession(),
+    )
+    finder.add_dependency_links(
+        ['https://pypi.python.org/packages/source/g/gmpy/gmpy-1.15.zip'])
+    link = finder.find_requirement(req, False)
+    assert link.url.startswith("https://pypi"), link
+
+
 def test_finder_priority_page_over_deplink():
     """
     Test PackageFinder prefers page links over equivalent dependency links
Repository: pypa/pip

Issue:
Selfcheck failure on Windows
I get this warning all the time:

```
There was an error checking the latest version of pip
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pip\utils\outdated.py", line 115, in pip_version_check
    state.save(pypi_version, current_time)
  File "C:\Python27\lib\site-packages\pip\utils\outdated.py", line 62, in save
    with open(self.statefile_path) as statefile:
IOError: [Errno 2] No such file or directory: u'C:\\Users\\ionel_000\\AppData\\Local\\pip\\Cache\\selfcheck.json'
```

If I create the file, it complains about invalid json. I've put `{}` inside, the warning has gone away, but this seems very wrong to me.



Discussion:
pip 6.0.3, python 2.7.9

Looks like the `USER_CACHE_DIR` directory isn't created before the state check. We should probably put some defensive code in `GlobalSelfCheckState.save()`, but I don't immediately see how to fix it cleanly...

Are you using `-v` or is this just by default?

Ooops, yes, I had `-v`. Not sure how I copy-pasted without it.


Resolving patch:
diff --git a/pip/utils/outdated.py b/pip/utils/outdated.py
--- a/pip/utils/outdated.py
+++ b/pip/utils/outdated.py
@@ -1,6 +1,7 @@
 from __future__ import absolute_import
 
 import datetime
+import errno
 import json
 import logging
 import os.path
@@ -12,6 +13,7 @@
 from pip.compat import total_seconds
 from pip.index import PyPI
 from pip.locations import USER_CACHE_DIR, running_under_virtualenv
+from pip.utils.filesystem import check_path_owner
 
 
 SELFCHECK_DATE_FMT = "%Y-%m-%dT%H:%M:%SZ"
@@ -57,6 +59,19 @@ def __init__(self):
             self.state = {}
 
     def save(self, pypi_version, current_time):
+        # Check to make sure that we own the directory
+        if not check_path_owner(
+                os.path.dirname(self.statefile_path), os.geteuid()):
+            return
+
+        # Now that we've ensured the directory is owned by this user, we'll go
+        # ahead and make sure that all our directories are created.
+        try:
+            os.makedirs(os.path.dirname(self.statefile_path))
+        except OSError as exc:
+            if exc.errno != errno.EEXIST:
+                raise
+
         # Attempt to write out our version check file
         with lockfile.LockFile(self.statefile_path):
             with open(self.statefile_path) as statefile:


Test patch:
diff --git a/tests/unit/test_unit_outdated.py b/tests/unit/test_unit_outdated.py
--- a/tests/unit/test_unit_outdated.py
+++ b/tests/unit/test_unit_outdated.py
@@ -128,6 +128,8 @@ def fake_open(filename, mode='r'):
     def fake_lock(filename):
         yield
 
+    monkeypatch.setattr(outdated, "check_path_owner", lambda p, u: True)
+
     monkeypatch.setattr(lockfile, 'LockFile', fake_lock)
 
     monkeypatch.setattr(outdated, 'running_under_virtualenv',
Repository: pypa/pip

Issue:
pip install --quiet shows progress bar
This is hardly a show-stopper but I was surprised to see progress indicators when running `pip install --quiet`.  I didn't see any discussion regarding this, so figured I'd add an official request for progress to be suppressed when the `--quiet` flag is present.



Discussion:
Hmm, this is a regression from pip 1.5 due to our switching around of how we handle our output.


Resolving patch:
diff --git a/pip/download.py b/pip/download.py
--- a/pip/download.py
+++ b/pip/download.py
@@ -537,7 +537,9 @@ def _download_url(resp, link, content_file):
 
     cached_resp = getattr(resp, "from_cache", False)
 
-    if cached_resp:
+    if logger.getEffectiveLevel() > logging.INFO:
+        show_progress = False
+    elif cached_resp:
         show_progress = False
     elif total_length > (40 * 1000):
         show_progress = True


Test patch:
Repository: pypa/pip

Issue:
pip6.0.4 can not work under python3.4, windows7 64bit.
use" pip list" command,  met a error:

``` python
Traceback (most recent call last):
  File "C:\Python34\Scripts\pip-script.py", line 9, in <module>
    load_entry_point('pip==6.0.4', 'console_scripts', 'pip')()
  File "C:\Python34\lib\site-packages\pip-6.0.4-py3.4.egg\pip\__init__.py", line
 217, in main
    return command.main(cmd_args)
  File "C:\Python34\lib\site-packages\pip-6.0.4-py3.4.egg\pip\basecommand.py", l
ine 122, in main
    write_debug_log = check_path_owner(debug_log_path, os.geteuid())
AttributeError: 'module' object has no attribute 'geteuid'
```

other commands can not work also.



Discussion:

Resolving patch:
diff --git a/pip/utils/filesystem.py b/pip/utils/filesystem.py
--- a/pip/utils/filesystem.py
+++ b/pip/utils/filesystem.py
@@ -1,9 +1,15 @@
+import os
 import os.path
 
 from pip.compat import get_path_uid
 
 
 def check_path_owner(path, uid):
+    # If we don't have a way to check the effective uid of this process, then
+    # we'll just assume that we own the directory.
+    if not hasattr(os, "geteuid"):
+        return True
+
     previous = None
     while path != previous:
         if os.path.lexists(path):


Test patch:
Repository: pypa/pip

Issue:
pip self check fails to handle first run correctly
The following will be seen on any non-virtualenv invocation of pip with --verbose:

```
Traceback (most recent call last):
  File ".../lib/python2.7/site-packages/pip/utils/outdated.py", line 115, in pip_version_check
    state.save(pypi_version, current_time)
  File ".../lib/python2.7/site-packages/pip/utils/outdated.py", line 62, in save
    with open(self.statefile_path) as statefile:
IOError: [Errno 2] No such file or directory: '.../Library/Caches/pip/selfcheck.json'
```

Because on the first run of the outdated.py code, that file doesn't exist. PR incoming.



Discussion:

Resolving patch:
diff --git a/pip/utils/outdated.py b/pip/utils/outdated.py
--- a/pip/utils/outdated.py
+++ b/pip/utils/outdated.py
@@ -73,8 +73,11 @@ def save(self, pypi_version, current_time):
 
         # Attempt to write out our version check file
         with lockfile.LockFile(self.statefile_path):
-            with open(self.statefile_path) as statefile:
-                state = json.load(statefile)
+            if os.path.exists(self.statefile_path):
+                with open(self.statefile_path) as statefile:
+                    state = json.load(statefile)
+            else:
+                state = {}
 
             state[sys.prefix] = {
                 "last_check": current_time.strftime(SELFCHECK_DATE_FMT),


Test patch:
diff --git a/tests/unit/test_unit_outdated.py b/tests/unit/test_unit_outdated.py
--- a/tests/unit/test_unit_outdated.py
+++ b/tests/unit/test_unit_outdated.py
@@ -131,6 +131,7 @@ def fake_lock(filename):
     monkeypatch.setattr(outdated, "check_path_owner", lambda p: True)
 
     monkeypatch.setattr(lockfile, 'LockFile', fake_lock)
+    monkeypatch.setattr(os.path, "exists", lambda p: True)
 
     monkeypatch.setattr(outdated, 'running_under_virtualenv',
                         pretend.call_recorder(lambda: False))
Repository: pypa/pip

Issue:
pip.utils.filesystem.check_path_owner should treat group membership properly
I have two users who share same .pip/cache directory: `a` and `b`. Both users are members of the group `pip`. There is third user, `pip` who is also member of group `pip` and that user handles all download and caching for users a and b. `.pip/cache` directory configured to have group writeable permission and sticky bit, to make sure all newly created files and folders are owned by group `pip`. 

Function [check_path_owner](https://github.com/pypa/pip/blob/6.0.6/pip/utils/filesystem.py#L7) only checks if owner is same user, but it is somewhat wrong. You should check group membership as well. 

Another option, is to create new command-line option, which will allow to ignore this check. 

Either solution will work.



Discussion:
I think checking group is good too. Better yet would be generalizing it so that it actually checks permissions. Possibly even supporting a read only cache mode. 

> On Feb 2, 2015, at 1:19 PM, Aleks Bunin notifications@github.com wrote:
> 
> I have two users who share same .pip/cache directory: a and b. Both users are members of the group pip. There is third user, pip who is also member of group pip and that user handles all download and caching for users a and b. .pip/cache directory configured to have group writeable permission and sticky bit, to make sure all newly created files and folders are owned by group pip.
> 
> Function check_path_owner only checks if owner is same user, but it is somewhat wrong. You should check group membership as well.
> 
> Another option, is to create new command-line option, which will allow to ignore this check.
> 
> Either solution will work.
> 
> —
> Reply to this email directly or view it on GitHub.


Resolving patch:
diff --git a/pip/utils/filesystem.py b/pip/utils/filesystem.py
--- a/pip/utils/filesystem.py
+++ b/pip/utils/filesystem.py
@@ -13,12 +13,16 @@ def check_path_owner(path):
     previous = None
     while path != previous:
         if os.path.lexists(path):
-            # Actually do the ownership check
-            try:
-                if get_path_uid(path) != os.geteuid():
+            # Check if path is writable by current user.
+            if os.geteuid() == 0:
+                # Special handling for root user in order to handle properly
+                # cases where users use sudo without -H flag.
+                try:
+                    path_uid = get_path_uid(path)
+                except OSError:
                     return False
-            except OSError:
-                return False
-            return True
+                return path_uid == 0
+            else:
+                return os.access(path, os.W_OK)
         else:
             previous, path = path, os.path.dirname(path)


Test patch:
Repository: pypa/pip

Issue:
pip prints too many blank line when installing packages
When you have 20+ packages in your requirements file it looks odd. Here is sample output (last regular output, and then blank lines and then message about successful installation of packages. 

```
    changing mode of /path/to/script/name to 775




















































Successfully installed Jinja2-2.7.3 MarkupSafe-0.23 Pygments-2.0.2 Sphinx-1.2.3 argparse-1.3.0 backports.ssl-match-hostname-3.4.0.2 beautifulsoup4-4.3.2 certifi-14.5.14 cov-core-1.15.0 coverage-3.7.1 docutils-0.12 fallocate-1.4.0 ipdb-0.8 ipython-3.0.0rc1 jsonschema-2.4.0 keyring-5.3 matplotlib-1.4.3 mistune-0.5 mock-1.0.1 mpld3-0.2 secretpackage-5.0b0 nose-1.3.4 numexpr-2.4 numpy-1.9.1 packaging-15.0 pbr-0.10.7 pexpect-3.3 plumbum-1.4.2 pssh-2.3.1 psutil-2.2.1 ptyprocess-0.4 py-1.4.26 pygments-q-0.5 pyparsing-2.0.3 pytest-2.6.4 pytest-capturelog-0.7 pytest-cov-1.8.1 pytest-pyq-1.1 pytest-timeout-0.4 python-dateutil-2.4.0 python-gitlab-0.8 pytz-2014.10 pyzmq-14.5.0 requests-2.5.3 six-1.9.0 stevedore-1.2.0 tailer-0.3 terminado-0.5 tornado-4.1 tox-1.9.0 virtualenv-12.0.7 virtualenv-clone-0.2.5 virtualenvwrapper-4.3.2 wheel-0.24.0
```

```
# pip --version
pip 6.0.8 from ...
```

I can reproduce this when installing from requirements file on OS X and Linux from wheels. This problem started for me when I upgraded from pip 1.5.6 to pip 6.0.8.



Discussion:

Resolving patch:
diff --git a/pip/wheel.py b/pip/wheel.py
--- a/pip/wheel.py
+++ b/pip/wheel.py
@@ -13,6 +13,7 @@
 import shutil
 import stat
 import sys
+import warnings
 
 from base64 import urlsafe_b64encode
 from email.parser import Parser
@@ -23,7 +24,7 @@
 from pip.locations import distutils_scheme
 from pip import pep425tags
 from pip.utils import (call_subprocess, normalize_path, make_path_relative,
-                       captured_stdout, remove_tracebacks)
+                       captured_stdout)
 from pip.utils.logging import indent_log
 from pip._vendor.distlib.scripts import ScriptMaker
 from pip._vendor import pkg_resources
@@ -157,8 +158,10 @@ def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None,
     # Compile all of the pyc files that we're going to be installing
     if pycompile:
         with captured_stdout() as stdout:
-            compileall.compile_dir(source, force=True, quiet=True)
-        logger.info(remove_tracebacks(stdout.getvalue()))
+            with warnings.catch_warnings():
+                warnings.filterwarnings('ignore')
+                compileall.compile_dir(source, force=True, quiet=True)
+        logger.debug(stdout.getvalue())
 
     def normpath(src, p):
         return make_path_relative(src, p).replace(os.path.sep, '/')


Test patch: