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

Issue:
Traceback if any uppercase command entered.
c:\Python34\Scripts>pip3.exe -V
pip 1.5.2 from C:\Python34\lib\site-packages (python 3.4)
Windows 7.1

c:\Python34\Scripts>pip3.exe LIST
Traceback (most recent call last):
  File "C:\Python34\lib\runpy.py", line 171, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python34\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\Python34\Scripts\pip3.exe__main__.py", line 9, in <module>
  File "C:\Python34\lib\site-packages\pip__init__.py", line 177, in main
    cmd_name, cmd_args = parseopts(initial_args)
  File "C:\Python34\lib\site-packages\pip__init__.py", line 156, in parseopts
    cmd_args.remove(args_else[0].lower())
ValueError: list.remove(x): x not in list

This was confirmed in response to my query on the main python mailing list.



Discussion:

Resolving patch:
diff --git a/pip/__init__.py b/pip/__init__.py
--- a/pip/__init__.py
+++ b/pip/__init__.py
@@ -149,11 +149,11 @@ def parseopts(args):
         sys.exit()
 
     # the subcommand name
-    cmd_name = args_else[0].lower()
+    cmd_name = args_else[0]
 
     # all the args without the subcommand
     cmd_args = args[:]
-    cmd_args.remove(args_else[0].lower())
+    cmd_args.remove(args_else[0])
 
     if cmd_name not in commands:
         guess = get_similar_commands(cmd_name)
diff --git a/pip/commands/__init__.py b/pip/commands/__init__.py
--- a/pip/commands/__init__.py
+++ b/pip/commands/__init__.py
@@ -67,14 +67,14 @@ def get_similar_commands(name):
     """Command name auto-correct."""
     from difflib import get_close_matches
 
+    name = name.lower()
+
     close_commands = get_close_matches(name, commands.keys())
 
     if close_commands:
-        guess = close_commands[0]
+        return close_commands[0]
     else:
-        guess = False
-
-    return guess
+        return False
 
 
 def _sort_commands(cmddict, order):


Test patch:
Repository: pypa/pip

Issue:
Avoid dynamically creating new classes all the time



Discussion:
I'm actually testing to see if this code is still required at all or not. It was added to work around a requests bug.


Resolving patch:
diff --git a/pip/download.py b/pip/download.py
--- a/pip/download.py
+++ b/pip/download.py
@@ -144,35 +144,6 @@ def parse_credentials(self, netloc):
         return None, None
 
 
-class LocalFSResponse(object):
-
-    def __init__(self, fileobj):
-        self.fileobj = fileobj
-
-    def __getattr__(self, name):
-        return getattr(self.fileobj, name)
-
-    def read(self, amt=None, decode_content=None, cache_content=False):
-        return self.fileobj.read(amt)
-
-    # Insert Hacks to Make Cookie Jar work w/ Requests
-    @property
-    def _original_response(self):
-        class FakeMessage(object):
-            def getheaders(self, header):
-                return []
-
-            def get_all(self, header, default):
-                return []
-
-        class FakeResponse(object):
-            @property
-            def msg(self):
-                return FakeMessage()
-
-        return FakeResponse()
-
-
 class LocalFSAdapter(BaseAdapter):
 
     def send(self, request, stream=None, timeout=None, verify=None, cert=None,
@@ -207,7 +178,7 @@ def send(self, request, stream=None, timeout=None, verify=None, cert=None,
                 "Last-Modified": modified,
             })
 
-            resp.raw = LocalFSResponse(open(pathname, "rb"))
+            resp.raw = open(pathname, "rb")
             resp.close = resp.raw.close
 
         return resp


Test patch:
Repository: pypa/pip

Issue:
'pip freeze' fails with BadCommand if vcs program is not found
Although mechanisms are in place to catch errors in the get_src_requirement() path, a BadCommand exception reaches the top-level and makes pip unusable if any package is found that has a .git directory and 'git' is not installed (or not in path).

I think this should be caught and a warning displayed in [pip.vcs:get_src_requirement()](https://github.com/pypa/pip/blob/3e7c94e9/pip/vcs/__init__.py#L246) instead, allowing the program to continue.

```
> python -m pip -v freeze
Cannot find command 'git'
Exception information:
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pip\basecommand.py", line 139, in main
    status = self.run(options, args)
  File "C:\Python27\lib\site-packages\pip\commands\freeze.py", line 73, in run
    req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
  File "C:\Python27\lib\site-packages\pip\__init__.py", line 181, in from_dist
    req = get_src_requirement(dist, location, find_tags)
  File "C:\Python27\lib\site-packages\pip\vcs\__init__.py", line 249, in get_src_requirement
    return version_control().get_src_requirement(dist, location, find_tags)
  File "C:\Python27\lib\site-packages\pip\vcs\git.py", line 155, in get_src_requirement
    repo = self.get_url(location)
  File "C:\Python27\lib\site-packages\pip\vcs\git.py", line 123, in get_url
    [self.cmd, 'config', 'remote.origin.url'],
  File "C:\Python27\lib\site-packages\pip\vcs\__init__.py", line 110, in cmd
    command = find_command(self.name)
  File "C:\Python27\lib\site-packages\pip\util.py", line 107, in find_command
    raise BadCommand('Cannot find command %r' % cmd)
BadCommand: Cannot find command 'git'
```



Discussion:

Resolving patch:
diff --git a/pip/vcs/__init__.py b/pip/vcs/__init__.py
--- a/pip/vcs/__init__.py
+++ b/pip/vcs/__init__.py
@@ -4,6 +4,7 @@
 import shutil
 
 from pip.compat import urlparse, urllib
+from pip.exceptions import BadCommand
 from pip.log import logger
 from pip.util import (display_path, backup_dir, find_command,
                       rmtree, ask_path_exists)
@@ -242,7 +243,15 @@ def get_src_requirement(self, dist, location, find_tags=False):
 def get_src_requirement(dist, location, find_tags):
     version_control = vcs.get_backend_from_location(location)
     if version_control:
-        return version_control().get_src_requirement(dist, location, find_tags)
+        try:
+            return version_control().get_src_requirement(dist,
+                                                         location,
+                                                         find_tags)
+        except BadCommand:
+            logger.warn('cannot determine version of editable source in %s '
+                        '(%s command not found in path)' % (
+                            location, version_control.name))
+            return dist.as_requirement()
     logger.warn(
         'cannot determine version of editable source in %s (is not SVN '
         'checkout, Git clone, Mercurial clone or Bazaar branch)' % location


Test patch:
Repository: pypa/pip

Issue:
Attempt to use the system provided CA Bundle
Right now we're just using the bundled CA Bundle that comes with pip, however it would be nice if we could try to use the OS CA Bundle if one exists in a form that we can consume. One of the most common patches against pip/requests in downstream is this so a lot of people are going to be doing this anyways. Perhaps with a flag to force it one way or another?



Discussion:
In downstream distributions we patch requests/certs.py::where() to return the proper path for the distribution.  In upstream pip you'd probably have to monkeypatch that function.


Resolving patch:
diff --git a/pip/cmdoptions.py b/pip/cmdoptions.py
--- a/pip/cmdoptions.py
+++ b/pip/cmdoptions.py
@@ -10,7 +10,7 @@
 import copy
 from optparse import OptionGroup, SUPPRESS_HELP, Option
 from pip.locations import (
-    USER_CACHE_DIR, build_prefix, default_log_file, src_prefix,
+    CA_BUNDLE_PATH, USER_CACHE_DIR, build_prefix, default_log_file, src_prefix,
 )
 
 
@@ -164,7 +164,7 @@ def make(self):
     '--cert',
     dest='cert',
     type='str',
-    default='',
+    default=CA_BUNDLE_PATH,
     metavar='path',
     help="Path to alternate CA bundle.")
 
diff --git a/pip/locations.py b/pip/locations.py
--- a/pip/locations.py
+++ b/pip/locations.py
@@ -2,6 +2,7 @@
 
 import getpass
 import os
+import os.path
 import site
 import sys
 import tempfile
@@ -11,12 +12,46 @@
 
 from pip import appdirs
 from pip.compat import get_path_uid
+
 import pip.exceptions
 
 
 # Hack for flake8
 install
 
+
+# CA Bundle Locations
+CA_BUNDLE_PATHS = [
+    # Debian/Ubuntu/Gentoo etc.
+    "/etc/ssl/certs/ca-certificates.crt",
+
+    # Fedora/RHEL
+    "/etc/pki/tls/certs/ca-bundle.crt",
+
+    # OpenSUSE
+    "/etc/ssl/ca-bundle.pem",
+
+    # OpenBSD
+    "/etc/ssl/cert.pem",
+
+    # FreeBSD/DragonFly
+    "/usr/local/share/certs/ca-root-nss.crt",
+
+    # Homebrew on OSX
+    "/usr/local/etc/openssl/cert.pem",
+]
+
+# Attempt to locate a CA Bundle that we can pass into requests, we have a list
+# of possible ones from various systems. If we cannot find one then we'll set
+# this to None so that we default to whatever requests is setup to handle.
+#
+# Note to Downstream: If you wish to disable this autodetection and simply use
+#                     whatever requests does (likely you've already patched
+#                     requests.certs.where()) then simply edit this line so
+#                     that it reads ``CA_BUNDLE_PATH = None``.
+CA_BUNDLE_PATH = next((x for x in CA_BUNDLE_PATHS if os.path.exists(x)), None)
+
+
 # Application Directories
 USER_CACHE_DIR = appdirs.user_cache_dir("pip")
 


Test patch:
Repository: pypa/pip

Issue:
Allow ZIP64 when downloading 
When doing a pip install --download, I ran into a problem when trying to zip a huge package.

Is there any harm in allowing ZIP64?

In req.py line 562 adding allowZip64=True

```
zip = zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED, allowZip64=True)
```

Is there any harm in making this change?  I think it won't affect how it zips when below the limit of standard zip.



Discussion:
LGTM

Any thoughts on this?  Any downsides?

I can't think of any! Can you send a PR? 


Resolving patch:
diff --git a/pip/req/req_install.py b/pip/req/req_install.py
--- a/pip/req/req_install.py
+++ b/pip/req/req_install.py
@@ -680,7 +680,10 @@ def archive(self, build_dir):
                 )
                 shutil.move(archive_path, dest_file)
         if create_archive:
-            zip = zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED)
+            zip = zipfile.ZipFile(
+                archive_path, 'w', zipfile.ZIP_DEFLATED,
+                allowZip64=True
+            )
             dir = os.path.normcase(os.path.abspath(self.source_dir))
             for dirpath, dirnames, filenames in os.walk(dir):
                 if 'pip-egg-info' in dirnames:
diff --git a/pip/util.py b/pip/util.py
--- a/pip/util.py
+++ b/pip/util.py
@@ -501,7 +501,7 @@ def unzip_file(filename, location, flatten=True):
         os.makedirs(location)
     zipfp = open(filename, 'rb')
     try:
-        zip = zipfile.ZipFile(zipfp)
+        zip = zipfile.ZipFile(zipfp, allowZip64=True)
         leading = has_leading_dir(zip.namelist()) and flatten
         for info in zip.infolist():
             name = info.filename


Test patch:
Repository: pypa/pip

Issue:
Handle <base> in line with HTML spec
Per spec, the first base element _with a href attribute_ provides the document base URL.

Therefore, the following currently gives the wrong result: `<base><base href="http://example.com/">`. Currently pip finds the first one and then concludes there's no URL so falls back to the document URL; it should find the second and ues that.



Discussion:

Resolving patch:
diff --git a/pip/index.py b/pip/index.py
--- a/pip/index.py
+++ b/pip/index.py
@@ -820,9 +820,12 @@ def api_version(self):
     @property
     def base_url(self):
         if not hasattr(self, "_base_url"):
-            base = self.parsed.find(".//base")
-            if base is not None and base.get("href"):
-                self._base_url = base.get("href")
+            bases = [
+                x for x in self.parsed.findall(".//base")
+                if x.get("href") is not None
+            ]
+            if bases and bases[0].get("href"):
+                self._base_url = bases[0].get("href")
             else:
                 self._base_url = self.url
         return self._base_url


Test patch:
diff --git a/tests/unit/test_index.py b/tests/unit/test_index.py
--- a/tests/unit/test_index.py
+++ b/tests/unit/test_index.py
@@ -1,3 +1,5 @@
+import pytest
+
 from pip.download import PipSession
 from pip.index import package_to_requirement, HTMLPage
 from pip.index import PackageFinder, Link, INSTALLED_VERSION
@@ -80,3 +82,27 @@ def test_ext_fragment(self):
 
     def test_ext_query(self):
         assert '.whl' == Link('http://yo/wheel.whl?a=b').ext
+
+
+@pytest.mark.parametrize(
+    ("html", "url", "expected"),
+    [
+        ("<html></html>", "https://example.com/", "https://example.com/"),
+        (
+            "<html><head>"
+            "<base href=\"https://foo.example.com/\">"
+            "</head></html>",
+            "https://example.com/",
+            "https://foo.example.com/",
+        ),
+        (
+            "<html><head>"
+            "<base><base href=\"https://foo.example.com/\">"
+            "</head></html>",
+            "https://example.com/",
+            "https://foo.example.com/",
+        ),
+    ],
+)
+def test_base_url(html, url, expected):
+    assert HTMLPage(html, url).base_url == expected
Repository: pypa/pip

Issue:
git --download with non-editable git+ssh fails
Hi,

when I call:
$ pip install --download requirements/sdists -r requirements/pip_local.txt

I'm getting the following error:

Downloading/unpacking rukzuklib from git+ssh://xxx@xxx@master (from -r requirements/pip_local.txt (line 14))
  Cloning ssh://xxx@xxx (to master) to /tmp/pip-5eeyys-export
  Running setup.py egg_info for package xxx
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
    IOError: [Errno 2] No such file or directory: 'xxx/env/build/xxx/setup.py'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

IOError: [Errno 2] No such file or directory: '/xxx/env/build/xxx/setup.py'

It seems that it is downloaded to the wrong folder. When I add an -e to the  requirements/pip_local.txt it works.
Any ideas?

PS: I'm using pip 1.3.1 and distribute==0.7.3



Discussion:
This is an awful lot like #798.


Resolving patch:
diff --git a/pip/req/req_set.py b/pip/req/req_set.py
--- a/pip/req/req_set.py
+++ b/pip/req/req_set.py
@@ -507,11 +507,7 @@ def unpack_url(self, link, location, download_dir=None,
 
         # non-editable vcs urls
         if is_vcs_url(link):
-            if only_download:
-                loc = download_dir
-            else:
-                loc = location
-            unpack_vcs_link(link, loc, only_download)
+            unpack_vcs_link(link, location, only_download)
 
         # file urls
         elif is_file_url(link):


Test patch:
diff --git a/tests/functional/test_install_download.py b/tests/functional/test_install_download.py
--- a/tests/functional/test_install_download.py
+++ b/tests/functional/test_install_download.py
@@ -125,3 +125,17 @@ def test_download_should_skip_existing_files(script):
     assert Path('scratch') / 'INITools-0.1.tar.gz' not in result.files_created
     assert script.site_packages / 'initools' not in result.files_created
     assert script.site_packages / 'openid' not in result.files_created
+
+
+def test_download_vcs_link(script):
+    """
+    It should allow -d flag for vcs links, regression test for issue #798.
+    """
+    result = script.pip(
+        'install', '-d', '.', 'git+git://github.com/pypa/pip-test-package.git'
+    )
+    assert (
+        Path('scratch') / 'pip-test-package-0.1.1.zip'
+        in result.files_created
+    )
+    assert script.site_packages / 'piptestpackage' not in result.files_created
Repository: pypa/pip

Issue:
"pip list -f" lists files which are not locatable
The combination of the "location" and the file paths reported by "pip list -f" does not result in the location of a file. There is an implied "egg-info" or "dist-info" directory level which is not displayed. This applies to both egg and wheel - the latter has code which appears to explicitly mutate the path to make it not be correct.

I intend to fix this by re-rooting the files to match the location element, thus allowing os.path.join(location, filename) to produce a valid file path.



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
@@ -57,12 +57,14 @@ def search_packages_info(query):
                 lines = dist.get_metadata_lines('RECORD')
                 paths = [l.split(',')[0] for l in lines]
                 paths = [os.path.join(dist.location, p) for p in paths]
-                file_list = [os.path.relpath(p, dist.egg_info)
-                             for p in paths]
+                file_list = [os.path.relpath(p, dist.location) for p in paths]
         else:
             # Otherwise use pip's log for .egg-info's
             if dist.has_metadata('installed-files.txt'):
-                file_list = dist.get_metadata_lines('installed-files.txt')
+                paths = dist.get_metadata_lines('installed-files.txt')
+                paths = [os.path.join(dist.egg_info, p) for p in paths]
+                file_list = [os.path.relpath(p, dist.location) for p in paths]
+
         # use and short-circuit to check for None
         package['files'] = file_list and sorted(file_list)
         yield package


Test patch:
Repository: pypa/pip

Issue:
pip fails because of space in user name on Windows in temp/pip-build-username
Hi,

I'm trying to install scipy using pip on Windows 7. I have all the requirements as far as I can see (mingw, blas etc.) and that part works fine. It runs into trouble when it's trying to pass to gfortran.exe the path to the temp folder containing scipy. My Windows username has a space in it so gfortran breaks it apart there and gets confused. To fix it, the paths should be quoted.

Here's pip's output: https://gist.github.com/matham/6ef04526db4b3dce66ba

The relevant lines are:

```
gfortran.exe:f77: c:\users\matthe~1\appdata\local\temp\pip-build-User Name\scipy\scipy\_build_utils\src\wrap_dummy_g77_abi.f
gfortran.exe: error: c:\users\matthe~1\appdata\local\temp\pip-build-User: No such file or directory
gfortran.exe: error: Name\scipy\scipy\_build_utils\src\wrap_dummy_g77_abi.f: No such file or directory
```

Note, I replaced my name in the path with User Name.



Discussion:

Resolving patch:
diff --git a/pip/locations.py b/pip/locations.py
--- a/pip/locations.py
+++ b/pip/locations.py
@@ -62,7 +62,7 @@ def __get_username():
 def _get_build_prefix():
     """ Returns a safe build_prefix """
     path = os.path.join(tempfile.gettempdir(), 'pip_build_%s' %
-        __get_username())
+        __get_username().replace(' ', '_'))
     if sys.platform == 'win32':
         """ on windows(tested on 7) temp dirs are isolated """
         return path


Test patch:
Repository: pypa/pip

Issue:
Use of uninitialised variable in pip/commands/list.py
The BestVersionAlreadyInstalled case of find_packages_latests_versions() does not set the variable remote_version_parsed, thus it could be used uninitialised.



Discussion:

Resolving patch:
diff --git a/pip/commands/list.py b/pip/commands/list.py
--- a/pip/commands/list.py
+++ b/pip/commands/list.py
@@ -4,7 +4,7 @@
 import warnings
 
 from pip.basecommand import Command
-from pip.exceptions import DistributionNotFound, BestVersionAlreadyInstalled
+from pip.exceptions import DistributionNotFound
 from pip.index import PackageFinder
 from pip.req import InstallRequirement
 from pip.utils import get_installed_distributions, dist_is_editable
@@ -150,8 +150,6 @@ def find_packages_latests_versions(self, options):
                         continue
                 except DistributionNotFound:
                     continue
-                except BestVersionAlreadyInstalled:
-                    remote_version = req.installed_version
                 else:
                     # It might be a good idea that link or finder had a public
                     # method that returned version


Test patch:
Repository: pypa/pip

Issue:
reverse the deprecation of --build and --no-clean
see discussion in #906



Discussion:

Resolving patch:
diff --git a/pip/commands/install.py b/pip/commands/install.py
--- a/pip/commands/install.py
+++ b/pip/commands/install.py
@@ -7,8 +7,7 @@
 import warnings
 
 from pip.req import InstallRequirement, RequirementSet, parse_requirements
-from pip.locations import (virtualenv_no_global, distutils_scheme,
-                           build_prefix)
+from pip.locations import virtualenv_no_global, distutils_scheme
 from pip.basecommand import Command
 from pip.index import PackageFinder
 from pip.exceptions import (
@@ -199,13 +198,11 @@ def run(self, options, args):
 
         if (
             options.no_install or
-            options.no_download or
-            (options.build_dir != build_prefix) or
-            options.no_clean
+            options.no_download
         ):
             warnings.warn(
-                "--no-install, --no-download, --build, and --no-clean are "
-                "deprecated. See https://github.com/pypa/pip/issues/906.",
+                "--no-install and --no-download are deprecated. "
+                "See https://github.com/pypa/pip/issues/906.",
                 RemovedInPip7Warning,
             )
 


Test patch:
Repository: pypa/pip

Issue:
Cannot access file exception after missing egg-info warning
I haven't found any reference to this issue through searching, so I'm submitting it here.
https://mail.python.org/pipermail/distutils-sig/2013-August/022528.html

I have a reproduction case installing the awacs library:
`Could not find .egg-info directory in install record for awacs==0.4.2`

which then causes the exception attempting to remove the install-record.txt file.
This was with pip 1.5.6 (on Windows 8)



Discussion:
Couple notes:
- For now the setuptools change that removed the .egg-info directory from the record file has been reverted: https://bitbucket.org/pypa/setuptools/issue/262
- But the change may have to be restored later as it's claimed that directories aren't allowed in the record file: https://bitbucket.org/pypa/setuptools/issue/118/

I've taken a look in the code and found the source of the warning message seems to be that pip relies on the egg-info directory being present in the record file:

https://github.com/pypa/pip/blob/develop/pip/req/req_install.py#L801

```
 f = open(record_filename)
for line in f:
    line = line.strip()
    if line.endswith('.egg-info'):
        egg_info_dir = prepend_root(line)
        break
else:
    logger.warning('Could not find .egg-info directory in install record for '
            '%s', self,)
```

If the "no directories in record file" change goes back in we'll need to change this to something like:

```
    try:
        offset = line.find('.egg-info/PKG-INFO')
    except:
        pass
    else:
        egg_info_dir = prepend_root(line[:offset+len('.egg-info')])
        break
```

I'll produce a pull request in a bit.


Resolving patch:
diff --git a/pip/req/req_install.py b/pip/req/req_install.py
--- a/pip/req/req_install.py
+++ b/pip/req/req_install.py
@@ -797,9 +797,9 @@ def prepend_root(path):
 
             f = open(record_filename)
             for line in f:
-                line = line.strip()
-                if line.endswith('.egg-info'):
-                    egg_info_dir = prepend_root(line)
+                directory = os.path.dirname(line)
+                if directory.endswith('.egg-info'):
+                    egg_info_dir = prepend_root(directory)
                     break
             else:
                 logger.warning(


Test patch: