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

Issue:
DistutilsPlatformError in mingw built Python 2 (msys2)
Trying to do many things using setuptools in a mingw built Python 2 (For example `msys2`'s `mingw-w64-x86_64-python2` fails with this exception:
```pytb
$ python setup.py build_ext
Traceback (most recent call last):
  File "setup.py", line 1, in <module>
    from setuptools import setup, Extension
  File "mingw64/lib/python2.7/site-packages/setuptools/__init__.py", line 160, in <module>
    monkey.patch_all()
  File "mingw64/lib/python2.7/site-packages/setuptools/monkey.py", line 104, in patch_all
    patch_for_msvc_specialized_compiler()
  File "mingw64/lib/python2.7/site-packages/setuptools/monkey.py", line 156, in patch_for_msvc_specialized_compiler
    msvc = import_module('setuptools.msvc')
  File "mingw64/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "mingw64/lib/python2.7/site-packages/setuptools/msvc.py", line 49, in <module>
    from distutils.msvc9compiler import Reg
  File "mingw64/lib/python2.7/distutils/msvc9compiler.py", line 306, in <module>
    raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION)
distutils.errors.DistutilsPlatformError: VC 6.0 is not supported by this module
```

`distutils.msvc9compiler` doesn't like being imported on mingw built Python, and this hack isn't necessary there.

P.S. I'm going to send a PR.


Discussion:

Resolving patch:
diff --git a/setuptools/msvc.py b/setuptools/msvc.py
--- a/setuptools/msvc.py
+++ b/setuptools/msvc.py
@@ -45,9 +45,18 @@ class winreg:
 
     safe_env = dict()
 
+_msvc9_suppress_errors = (
+    # msvc9compiler isn't available on some platforms
+    ImportError,
+    
+    # msvc9compiler raises DistutilsPlatformError in some
+    # environments. See #1118.
+    distutils.errors.DistutilsPlatformError,
+)
+
 try:
     from distutils.msvc9compiler import Reg
-except ImportError:
+except _msvc9_suppress_errors:
     pass
 
 


Test patch:
Repository: pypa/setuptools

Issue:
Excpetion message "No script named ..." in pkg_resources.ResolutionError
We have recently run into this exception when running a script in a package with `PYTHONPATH=.` as part of the unit tests. That causes our package to be imported from the working directory of the repo, which is what we want.

However, `pkg_resources.run_script()` which is used by the generated version of the script does not find the actual version of the script because pkg_resources tries to locate it in the "scripts" directory of the egg metadata directory of the package it has imported. In our `PYTHONPATH=.` case, that is the package in the working directory, which either does not even have a egg metadata directory, or if i create one using "python setup.py egg_info", it has the metadata but not the scripts subdirectory.

With this issue, I do not like to request a solution to this problem, but only a small change that improves the exception message to say where it tried to locate the script. I'll post an according PR soon.

Debugging this to the point to understand where it tried to locate the script has cost me quite some time today. There are tons of occurrences of this issue over the last ten years when you google it, so I'm not alone with this issue (although probably the root causes are different). Having a better exception message helps a lot to understand what's going on, and costs nothing to implement.

BTW, the corresponding issue in our project is pywbem/pywbem#849.



Discussion:

Resolving patch:
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -1513,7 +1513,9 @@ def metadata_listdir(self, name):
     def run_script(self, script_name, namespace):
         script = 'scripts/' + script_name
         if not self.has_metadata(script):
-            raise ResolutionError("No script named %r" % script_name)
+            raise ResolutionError(
+                "No script named %r in 'scripts' directory of metadata "
+                "directory %r" % (script_name, self.egg_info))
         script_text = self.get_metadata(script).replace('\r\n', '\n')
         script_text = script_text.replace('\r', '\n')
         script_filename = self._fn(self.egg_info, script)


Test patch:
Repository: pypa/setuptools

Issue:
Stop patching write_pkg_info?
According to [this comment](https://github.com/pypa/setuptools/blob/89ef5bb7e4812193d6f593d531bad36191517981/setuptools/monkey.py#L114), `write_pkg_info` is only patched because of a bug in 3.2.2. Now that setuptools has dropped support for Python 3.2, maybe that patch is no longer necessary?


Discussion:

Resolving patch:
diff --git a/setuptools/dist.py b/setuptools/dist.py
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -123,15 +123,6 @@ def write_pkg_file(self, file):
             file.write('Provides-Extra: %s\n' % extra)
 
 
-# from Python 3.4
-def write_pkg_info(self, base_dir):
-    """Write the PKG-INFO file into the release tree.
-    """
-    with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
-              encoding='UTF-8') as pkg_info:
-        self.write_pkg_file(pkg_info)
-
-
 sequence = tuple, list
 
 
diff --git a/setuptools/monkey.py b/setuptools/monkey.py
--- a/setuptools/monkey.py
+++ b/setuptools/monkey.py
@@ -87,7 +87,6 @@ def patch_all():
         distutils.config.PyPIRCCommand.DEFAULT_REPOSITORY = warehouse
 
     _patch_distribution_metadata_write_pkg_file()
-    _patch_distribution_metadata_write_pkg_info()
 
     # Install Distribution throughout the distutils
     for module in distutils.dist, distutils.core, distutils.cmd:
@@ -111,21 +110,6 @@ def _patch_distribution_metadata_write_pkg_file():
     )
 
 
-def _patch_distribution_metadata_write_pkg_info():
-    """
-    Workaround issue #197 - Python 3 prior to 3.2.2 uses an environment-local
-    encoding to save the pkg_info. Monkey-patch its write_pkg_info method to
-    correct this undesirable behavior.
-    """
-    environment_local = (3,) <= sys.version_info[:3] < (3, 2, 2)
-    if not environment_local:
-        return
-
-    distutils.dist.DistributionMetadata.write_pkg_info = (
-        setuptools.dist.write_pkg_info
-    )
-
-
 def patch_func(replacement, target_mod, func_name):
     """
     Patch func_name in target_mod with replacement


Test patch:
Repository: pypa/setuptools

Issue:
Py_DEBUG and WITH_PYMALLOC warnings [Windows]
Hi,

I'm on Windows 7 x64, running the latest Python 3.6.5 (64-bit), with setuptools 39.0.1. Each time a setuptools internal function is invoked (for example by running zc.buildout's [bootstrap.py](https://github.com/buildout/buildout/blob/master/bootstrap/bootstrap.py)) and somehow calls ``pep425tags.get_abi_tag``, 2 warnings relative to ``PyDEBUG`` and ``WITH_PYMALLOC`` are raised. I don't remember seeing these warnings with previous versions of ``setuptools`` (I had 36.x if I recall correctly)

I've tried to search issues relative to these warnings but the only I could find are from 2016 and do not seem to be relevant.

Here is a minimal command that triggers the warnings:

```
$ python -c "from setuptools.pep425tags import get_abi_tag; get_abi_tag()"
C:\Python\3.6\lib\site-packages\setuptools\pep425tags.py:89: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
  warn=(impl == 'cp')):
C:\Python\3.6\lib\site-packages\setuptools\pep425tags.py:93: RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
  warn=(impl == 'cp')):
```

I am not sure I fully understand what is going on though, so it may have something to do with my setup. Hopefully this can be reproduced somehow.


Discussion:
I'm assuming you get the same warnings when building a wheel? That code comes from the `wheel` package via `pip` (for manylinux support).
Note: the level has been changed in pip (the code uses `logger.debug`), so I guess we could suppress it too.
Bonjour Benoit,

No, the warnings do not show up when I build a wheel from any of my (pure python) packages using ``python setup.py bdist_wheel``.

From your 2nd comment I understand you would want ``setuptools`` to log this message (and any other warning raised in ``get_abi_tag``) through ``logger.debug`` instead of raising a warning. If so I'll be happy to submit a PR, but you may prefer doing the edits yourself.
Yes, this should use the logging facility from `distutils`: `from distutils import log`, as done in other parts of the code.

Relevant discussion on pip's tracker about the same issue: https://github.com/pypa/pip/issues/3383

Resolving patch:
diff --git a/setuptools/pep425tags.py b/setuptools/pep425tags.py
--- a/setuptools/pep425tags.py
+++ b/setuptools/pep425tags.py
@@ -4,6 +4,7 @@
 from __future__ import absolute_import
 
 import distutils.util
+from distutils import log
 import platform
 import re
 import sys
@@ -69,8 +70,8 @@ def get_flag(var, fallback, expected=True, warn=True):
     val = get_config_var(var)
     if val is None:
         if warn:
-            warnings.warn("Config variable '{0}' is unset, Python ABI tag may "
-                          "be incorrect".format(var), RuntimeWarning, 2)
+            log.debug("Config variable '%s' is unset, Python ABI tag may "
+                      "be incorrect", var)
         return fallback()
     return val == expected
 


Test patch:
Repository: pypa/setuptools

Issue:
pkg_resources.Distribution should provide __dir__
pkg_resources.Distribution uses `__getattr__` to proxy attributes to its _provider attribute; it should also implement its own `__dir__` so that (e.g.) tab-completion works correctly.


Discussion:
Seems like a good idea to me, though I've never done it before. Are there other side-effects?
probably not?

Resolving patch:
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -2667,6 +2667,19 @@ def __getattr__(self, attr):
             raise AttributeError(attr)
         return getattr(self._provider, attr)
 
+    def __dir__(self):
+        return list(
+            set(super(Distribution, self).__dir__())
+            | set(
+                attr for attr in self._provider.__dir__()
+                if not attr.startswith('_')
+            )
+        )
+
+    if not hasattr(object, '__dir__'):
+        # python 2.7 not supported
+        del __dir__
+
     @classmethod
     def from_filename(cls, filename, metadata=None, **kw):
         return cls.from_location(


Test patch:
diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py
--- a/pkg_resources/tests/test_resources.py
+++ b/pkg_resources/tests/test_resources.py
@@ -145,6 +145,35 @@ def testDistroDependsSimple(self):
         for v in "Twisted>=1.5", "Twisted>=1.5\nZConfig>=2.0":
             self.checkRequires(self.distRequires(v), v)
 
+    needs_object_dir = pytest.mark.skipif(
+        not hasattr(object, '__dir__'),
+        reason='object.__dir__ necessary for self.__dir__ implementation',
+    )
+
+    def test_distribution_dir(self):
+        d = pkg_resources.Distribution()
+        dir(d)
+
+    @needs_object_dir
+    def test_distribution_dir_includes_provider_dir(self):
+        d = pkg_resources.Distribution()
+        before = d.__dir__()
+        assert 'test_attr' not in before
+        d._provider.test_attr = None
+        after = d.__dir__()
+        assert len(after) == len(before) + 1
+        assert 'test_attr' in after
+
+    @needs_object_dir
+    def test_distribution_dir_ignores_provider_dir_leading_underscore(self):
+        d = pkg_resources.Distribution()
+        before = d.__dir__()
+        assert '_test_attr' not in before
+        d._provider._test_attr = None
+        after = d.__dir__()
+        assert len(after) == len(before)
+        assert '_test_attr' not in after
+
     def testResolve(self):
         ad = pkg_resources.Environment([])
         ws = WorkingSet([])
Repository: pypa/setuptools

Issue:
URL to Visual Studio download is dead
The url in this message is no longer active:

https://github.com/pypa/setuptools/blob/818ba40529993d8f318fe282bdb8420455dbf926/setuptools/msvc.py#L232-L236

The current best URL is `https://visualstudio.microsoft.com/downloads/` and the title is "Build Tools for Visual Studio"


Discussion:

Resolving patch:
diff --git a/setuptools/msvc.py b/setuptools/msvc.py
--- a/setuptools/msvc.py
+++ b/setuptools/msvc.py
@@ -232,8 +232,7 @@ def _augment_exception(exc, version, arch=''):
         elif version >= 14.0:
             # For VC++ 14.0 Redirect user to Visual C++ Build Tools
             message += (' Get it with "Microsoft Visual C++ Build Tools": '
-                        r'http://landinghub.visualstudio.com/'
-                        'visual-cpp-build-tools')
+                        r'https://visualstudio.microsoft.com/downloads/')
 
     exc.args = (message, )
 


Test patch:
Repository: pypa/setuptools

Issue:
get_requires_for_build_sdist should not require wheel
[get_requires_for_build_sdist](https://github.com/pypa/setuptools/blob/master/setuptools/build_meta.py#L120) also implies [wheel](https://github.com/pypa/setuptools/blob/master/setuptools/build_meta.py#L96) as dependency, even though a wheel is not required to build a source distribution.


Discussion:

Resolving patch:
diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py
--- a/setuptools/build_meta.py
+++ b/setuptools/build_meta.py
@@ -91,9 +91,8 @@ def _fix_config(config_settings):
     return config_settings
 
 
-def _get_build_requires(config_settings):
+def _get_build_requires(config_settings, requirements):
     config_settings = _fix_config(config_settings)
-    requirements = ['setuptools', 'wheel']
 
     sys.argv = sys.argv[:1] + ['egg_info'] + \
         config_settings["--global-option"]
@@ -113,20 +112,20 @@ def _get_immediate_subdirectories(a_dir):
 
 def get_requires_for_build_wheel(config_settings=None):
     config_settings = _fix_config(config_settings)
-    return _get_build_requires(config_settings)
+    return _get_build_requires(config_settings, requirements=['setuptools', 'wheel'])
 
 
 def get_requires_for_build_sdist(config_settings=None):
     config_settings = _fix_config(config_settings)
-    return _get_build_requires(config_settings)
+    return _get_build_requires(config_settings, requirements=['setuptools'])
 
 
 def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
     sys.argv = sys.argv[:1] + ['dist_info', '--egg-base', _to_str(metadata_directory)]
     _run_setup()
-    
+
     dist_info_directory = metadata_directory
-    while True:    
+    while True:
         dist_infos = [f for f in os.listdir(dist_info_directory)
                       if f.endswith('.dist-info')]
 


Test patch:
diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py
--- a/setuptools/tests/test_build_meta.py
+++ b/setuptools/tests/test_build_meta.py
@@ -107,6 +107,12 @@ def test_get_requires_for_build_wheel(build_backend):
     assert sorted(actual) == sorted(expected)
 
 
+def test_get_requires_for_build_sdist(build_backend):
+    actual = build_backend.get_requires_for_build_sdist()
+    expected = ['six', 'setuptools']
+    assert sorted(actual) == sorted(expected)
+
+
 def test_build_wheel(build_backend):
     dist_dir = os.path.abspath('pip-wheel')
     os.makedirs(dist_dir)
Repository: pypa/setuptools

Issue:
Drop use of six.u
Since we no longer support Python 2.6, there's really no reason to use `six.u` anymore, but it is still used in [`easy_install`](https://github.com/pypa/setuptools/blob/5b90a0d9d97f52fc91792a8143670ee1a73f51c5/setuptools/command/easy_install.py#L635):

```python
tmpdir = tempfile.mkdtemp(prefix=six.u("easy_install-"))
```

This can be replaced with a u-prefixed string until we're Python 3-only:

```python
tmpdir = tempfile.mkdtemp(prefix=u"easy_install-")
```


Discussion:

Resolving patch:
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -632,7 +632,7 @@ def check_editable(self, spec):
 
     @contextlib.contextmanager
     def _tmpdir(self):
-        tmpdir = tempfile.mkdtemp(prefix=six.u("easy_install-"))
+        tmpdir = tempfile.mkdtemp(prefix=u"easy_install-")
         try:
             # cast to str as workaround for #709 and #710 and #712
             yield str(tmpdir)


Test patch:
Repository: pypa/setuptools

Issue:
data_files support in setup.cfg
Hello,

I work on a Python project that uses [data_files](https://docs.python.org/2/distutils/setupscript.html#installing-additional-files) in its `setup.py`. While I've moved most of my `setup.py` arguments over to a `setup.cfg` file, I still have `data_files` in `setup.py` because `setup.cfg` doesn't seem to support it.

I could take a stab at a PR to add this support in, but I just wanted to check first. Is this feature missing on purpose, or just hasn't been implemented yet?


Discussion:
@idlesign might know the answer.
Hi. I missed that out indeed. 
It seems that we only can go with a separate `section` to cover `data_files`.
OK, so I'll work on getting a PR together to add this feature in. So in the new `setup.cfg`, `data_files` would look something like this:

```ini
[options.data_files]
share/man/man1 = 
    docs/man/my_script.1.gz
```


Resolving patch:
diff --git a/setuptools/config.py b/setuptools/config.py
--- a/setuptools/config.py
+++ b/setuptools/config.py
@@ -598,3 +598,11 @@ def parse_section_extras_require(self, section_options):
         parse_list = partial(self._parse_list, separator=';')
         self['extras_require'] = self._parse_section_to_dict(
             section_options, parse_list)
+
+    def parse_section_data_files(self, section_options):
+        """Parses `data_files` configuration file section.
+
+        :param dict section_options:
+        """
+        parsed = self._parse_section_to_dict(section_options, self._parse_list)
+        self['data_files'] = [(k, v) for k, v in parsed.items()]


Test patch:
diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py
--- a/setuptools/tests/test_config.py
+++ b/setuptools/tests/test_config.py
@@ -703,6 +703,23 @@ def test_entry_points(self, tmpdir):
         with get_dist(tmpdir) as dist:
             assert dist.entry_points == expected
 
+    def test_data_files(self, tmpdir):
+        fake_env(
+            tmpdir,
+            '[options.data_files]\n'
+            'cfg =\n'
+            '      a/b.conf\n'
+            '      c/d.conf\n'
+            'data = e/f.dat, g/h.dat\n'
+        )
+
+        with get_dist(tmpdir) as dist:
+            expected = [
+                ('cfg', ['a/b.conf', 'c/d.conf']),
+                ('data', ['e/f.dat', 'g/h.dat']),
+            ]
+            assert sorted(dist.data_files) == sorted(expected)
+
 saved_dist_init = _Distribution.__init__
 class TestExternalSetters:
     # During creation of the setuptools Distribution() object, we call
Repository: pypa/setuptools

Issue:
Officially support Python 3.7
- [x] Test against 3.7 (#1514)
- [ ] Add Python 3.7 classifier

@jaraco @pganssle @benoit-pierre: Didn't see another issue to track this. Not sure what else is necessary here to consider this "supported", feel free to edit as necessary.


Discussion:
I think Python 3.7 classifiers is all that is necessary.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -164,6 +164,7 @@ def pypi_link(pkg_filename):
         Programming Language :: Python :: 3.4
         Programming Language :: Python :: 3.5
         Programming Language :: Python :: 3.6
+        Programming Language :: Python :: 3.7
         Topic :: Software Development :: Libraries :: Python Modules
         Topic :: System :: Archiving :: Packaging
         Topic :: System :: Systems Administration


Test patch:
Repository: pypa/setuptools

Issue:
Preserving read-only flags on package data causing access denied when building
I'm working with a read-only source directory on Windows and running into access denied errors when calling `python setup.py bdist_wheel`. I noticed that it was only files included in package_data that were causing this, which helped me track it down to:

[setuptools/setuptools/command/build_py.py](
https://github.com/pypa/setuptools/blob/89155abb4222cf5a9dc81120e5c71e26b5af68f9/setuptools/command/build_py.py#L123)
`outf, copied = self.copy_file(srcfile, target)`

which is slightly different from its distutils version:

[cpython/Lib/distutils/command/build_py.py](
https://github.com/python/cpython/blob/d6345def68d3a0227253da26213dadb247f786db/Lib/distutils/command/build_py.py#L141)
`self.copy_file(os.path.join(src_dir, filename), target, preserve_mode=False)`

So it looks like it comes down to this preserve_mode flag.

I don't know if there is a good reason to preserve things like read-only flags? There's a [comment](https://github.com/python/cpython/blob/d6345def68d3a0227253da26213dadb247f786db/Lib/distutils/command/build_py.py#L74) about preserving mode further up in the distutils code, which seems to suggest not preserving is the way to go.


Discussion:
Let me vote up. I was going to report about this issue, but @miuliano has already done it. 
My version control system keeps all unchecked files in RO mode, so when I build a wheel it copies sources to build folder. But ONLY package data is keeping mode then and build wheel crashes as it can't delete it then.

Resolving patch:
diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py
--- a/setuptools/command/build_py.py
+++ b/setuptools/command/build_py.py
@@ -120,7 +120,7 @@ def build_package_data(self):
                 target = os.path.join(build_dir, filename)
                 self.mkpath(os.path.dirname(target))
                 srcfile = os.path.join(src_dir, filename)
-                outf, copied = self.copy_file(srcfile, target)
+                outf, copied = self.copy_file(srcfile, target, preserve_mode=False)
                 srcfile = os.path.abspath(srcfile)
                 if (copied and
                         srcfile in self.distribution.convert_2to3_doctests):


Test patch: