We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Debian-specific behavior lost when Setuptools adopts distutils
`pip install -e $PACKAGE_PATH` installs commands to /usr/bin and not /usr/local/bin on Ubuntu as it did in the past.

`pip install $PACKAGE_PATH` continues to install to /usr/local/bin as expected.

Openstack downstream has temporarily capped setuptools until we know if this is expected behaviour or not.  Please see http://lists.openstack.org/pipermail/openstack-discuss/2020-July/015779.html for more context.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `_distutils_hack/__init__.py`
Content:
```
1 import sys
2 import os
3 import re
4 import importlib
5 import warnings
6 
7 
8 is_pypy = '__pypy__' in sys.builtin_module_names
9 
10 
11 def warn_distutils_present():
12     if 'distutils' not in sys.modules:
13         return
14     if is_pypy and sys.version_info < (3, 7):
15         # PyPy for 3.6 unconditionally imports distutils, so bypass the warning
16         # https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
17         return
18     warnings.warn(
19         "Distutils was imported before Setuptools, but importing Setuptools "
20         "also replaces the `distutils` module in `sys.modules`. This may lead "
21         "to undesirable behaviors or errors. To avoid these issues, avoid "
22         "using distutils directly, ensure that setuptools is installed in the "
23         "traditional way (e.g. not an editable install), and/or make sure that "
24         "setuptools is always imported before distutils.")
25 
26 
27 def clear_distutils():
28     if 'distutils' not in sys.modules:
29         return
30     warnings.warn("Setuptools is replacing distutils.")
31     mods = [name for name in sys.modules if re.match(r'distutils\b', name)]
32     for name in mods:
33         del sys.modules[name]
34 
35 
36 def enabled():
37     """
38     Allow selection of distutils by environment variable.
39     """
40     which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
41     return which == 'local'
42 
43 
44 def ensure_local_distutils():
45     clear_distutils()
46     distutils = importlib.import_module('setuptools._distutils')
47     distutils.__name__ = 'distutils'
48     sys.modules['distutils'] = distutils
49 
50     # sanity check that submodules load as expected
51     core = importlib.import_module('distutils.core')
52     assert '_distutils' in core.__file__, core.__file__
53 
54 
55 def do_override():
56     """
57     Ensure that the local copy of distutils is preferred over stdlib.
58 
59     See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
60     for more motivation.
61     """
62     if enabled():
63         warn_distutils_present()
64         ensure_local_distutils()
65 
66 
67 class DistutilsMetaFinder:
68     def find_spec(self, fullname, path, target=None):
69         if path is not None or fullname != "distutils":
70             return None
71 
72         return self.get_distutils_spec()
73 
74     def get_distutils_spec(self):
75         import importlib.util
76 
77         class DistutilsLoader(importlib.util.abc.Loader):
78 
79             def create_module(self, spec):
80                 return importlib.import_module('._distutils', 'setuptools')
81 
82             def exec_module(self, module):
83                 pass
84 
85         return importlib.util.spec_from_loader('distutils', DistutilsLoader())
86 
87 
88 DISTUTILS_FINDER = DistutilsMetaFinder()
89 
90 
91 def add_shim():
92     sys.meta_path.insert(0, DISTUTILS_FINDER)
93 
94 
95 def remove_shim():
96     try:
97         sys.meta_path.remove(DISTUTILS_FINDER)
98     except ValueError:
99         pass
100
```

Path: `setup.py`
Content:
```
1 #!/usr/bin/env python
2 """
3 Distutils setup file, used to install or test 'setuptools'
4 """
5 
6 import os
7 import sys
8 import textwrap
9 
10 import setuptools
11 from setuptools.command.install import install
12 
13 here = os.path.dirname(__file__)
14 
15 
16 def require_metadata():
17     "Prevent improper installs without necessary metadata. See #659"
18     egg_info_dir = os.path.join(here, 'setuptools.egg-info')
19     if not os.path.exists(egg_info_dir):
20         msg = (
21             "Cannot build setuptools without metadata. "
22             "Run `bootstrap.py`."
23         )
24         raise RuntimeError(msg)
25 
26 
27 def read_commands():
28     command_ns = {}
29     cmd_module_path = 'setuptools/command/__init__.py'
30     init_path = os.path.join(here, cmd_module_path)
31     with open(init_path) as init_file:
32         exec(init_file.read(), command_ns)
33     return command_ns['__all__']
34 
35 
36 def _gen_console_scripts():
37     yield "easy_install = setuptools.command.easy_install:main"
38 
39     # Gentoo distributions manage the python-version-specific scripts
40     # themselves, so those platforms define an environment variable to
41     # suppress the creation of the version-specific scripts.
42     var_names = (
43         'SETUPTOOLS_DISABLE_VERSIONED_EASY_INSTALL_SCRIPT',
44         'DISTRIBUTE_DISABLE_VERSIONED_EASY_INSTALL_SCRIPT',
45     )
46     if any(os.environ.get(var) not in (None, "", "0") for var in var_names):
47         return
48     tmpl = "easy_install-{shortver} = setuptools.command.easy_install:main"
49     yield tmpl.format(shortver='{}.{}'.format(*sys.version_info))
50 
51 
52 package_data = dict(
53     setuptools=['script (dev).tmpl', 'script.tmpl', 'site-patch.py'],
54 )
55 
56 force_windows_specific_files = (
57     os.environ.get("SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES", "1").lower()
58     not in ("", "0", "false", "no")
59 )
60 
61 include_windows_files = (
62     sys.platform == 'win32' or
63     os.name == 'java' and os._name == 'nt' or
64     force_windows_specific_files
65 )
66 
67 if include_windows_files:
68     package_data.setdefault('setuptools', []).extend(['*.exe'])
69     package_data.setdefault('setuptools.command', []).extend(['*.xml'])
70 
71 needs_wheel = set(['release', 'bdist_wheel']).intersection(sys.argv)
72 wheel = ['wheel'] if needs_wheel else []
73 
74 
75 def pypi_link(pkg_filename):
76     """
77     Given the filename, including md5 fragment, construct the
78     dependency link for PyPI.
79     """
80     root = 'https://files.pythonhosted.org/packages/source'
81     name, sep, rest = pkg_filename.partition('-')
82     parts = root, name[0], name, pkg_filename
83     return '/'.join(parts)
84 
85 
86 class install_with_pth(install):
87     """
88     Custom install command to install a .pth file for distutils patching.
89 
90     This hack is necessary because there's no standard way to install behavior
91     on startup (and it's debatable if there should be one). This hack (ab)uses
92     the `extra_path` behavior in Setuptools to install a `.pth` file with
93     implicit behavior on startup to give higher precedence to the local version
94     of `distutils` over the version from the standard library.
95 
96     Please do not replicate this behavior.
97     """
98 
99     _pth_name = 'distutils-precedence'
100     _pth_contents = textwrap.dedent("""
101         import os
102         enabled = os.environ.get('SETUPTOOLS_USE_DISTUTILS') == 'local'
103         enabled and __import__('_distutils_hack').add_shim()
104         """).lstrip().replace('\n', '; ')
105 
106     def initialize_options(self):
107         install.initialize_options(self)
108         self.extra_path = self._pth_name, self._pth_contents
109 
110     def finalize_options(self):
111         install.finalize_options(self)
112         self._restore_install_lib()
113 
114     def _restore_install_lib(self):
115         """
116         Undo secondary effect of `extra_path` adding to `install_lib`
117         """
118         suffix = os.path.relpath(self.install_lib, self.install_libbase)
119 
120         if suffix.strip() == self._pth_contents.strip():
121             self.install_lib = self.install_libbase
122 
123 
124 setup_params = dict(
125     src_root=None,
126     cmdclass={'install': install_with_pth},
127     package_data=package_data,
128     entry_points={
129         "distutils.commands": [
130             "%(cmd)s = setuptools.command.%(cmd)s:%(cmd)s" % locals()
131             for cmd in read_commands()
132         ],
133         "setuptools.finalize_distribution_options": [
134             "parent_finalize = setuptools.dist:_Distribution.finalize_options",
135             "keywords = setuptools.dist:Distribution._finalize_setup_keywords",
136             "2to3_doctests = "
137             "setuptools.dist:Distribution._finalize_2to3_doctests",
138         ],
139         "distutils.setup_keywords": [
140             "eager_resources        = setuptools.dist:assert_string_list",
141             "namespace_packages     = setuptools.dist:check_nsp",
142             "extras_require         = setuptools.dist:check_extras",
143             "install_requires       = setuptools.dist:check_requirements",
144             "tests_require          = setuptools.dist:check_requirements",
145             "setup_requires         = setuptools.dist:check_requirements",
146             "python_requires        = setuptools.dist:check_specifier",
147             "entry_points           = setuptools.dist:check_entry_points",
148             "test_suite             = setuptools.dist:check_test_suite",
149             "zip_safe               = setuptools.dist:assert_bool",
150             "package_data           = setuptools.dist:check_package_data",
151             "exclude_package_data   = setuptools.dist:check_package_data",
152             "include_package_data   = setuptools.dist:assert_bool",
153             "packages               = setuptools.dist:check_packages",
154             "dependency_links       = setuptools.dist:assert_string_list",
155             "test_loader            = setuptools.dist:check_importable",
156             "test_runner            = setuptools.dist:check_importable",
157             "use_2to3               = setuptools.dist:assert_bool",
158             "convert_2to3_doctests  = setuptools.dist:assert_string_list",
159             "use_2to3_fixers        = setuptools.dist:assert_string_list",
160             "use_2to3_exclude_fixers = setuptools.dist:assert_string_list",
161         ],
162         "egg_info.writers": [
163             "PKG-INFO = setuptools.command.egg_info:write_pkg_info",
164             "requires.txt = setuptools.command.egg_info:write_requirements",
165             "entry_points.txt = setuptools.command.egg_info:write_entries",
166             "eager_resources.txt = setuptools.command.egg_info:overwrite_arg",
167             (
168                 "namespace_packages.txt = "
169                 "setuptools.command.egg_info:overwrite_arg"
170             ),
171             "top_level.txt = setuptools.command.egg_info:write_toplevel_names",
172             "depends.txt = setuptools.command.egg_info:warn_depends_obsolete",
173             "dependency_links.txt = setuptools.command.egg_info:overwrite_arg",
174         ],
175         "console_scripts": list(_gen_console_scripts()),
176         "setuptools.installation":
177             ['eggsecutable = setuptools.command.easy_install:bootstrap'],
178     },
179     dependency_links=[
180         pypi_link(
181             'certifi-2016.9.26.tar.gz#md5=baa81e951a29958563689d868ef1064d',
182         ),
183         pypi_link(
184             'wincertstore-0.2.zip#md5=ae728f2f007185648d0c7a8679b361e2',
185         ),
186     ],
187     setup_requires=[
188     ] + wheel,
189 )
190 
191 if __name__ == '__main__':
192     # allow setup.py to run from another directory
193     here and os.chdir(here)
194     require_metadata()
195     dist = setuptools.setup(**setup_params)
196
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py
--- a/_distutils_hack/__init__.py
+++ b/_distutils_hack/__init__.py
@@ -37,7 +37,7 @@
     """
     Allow selection of distutils by environment variable.
     """
-    which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
+    which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')
     return which == 'local'
 
 
@@ -66,12 +66,14 @@
 
 class DistutilsMetaFinder:
     def find_spec(self, fullname, path, target=None):
-        if path is not None or fullname != "distutils":
-            return None
+        if path is not None:
+            return
 
-        return self.get_distutils_spec()
+        method_name = 'spec_for_{fullname}'.format(**locals())
+        method = getattr(self, method_name, lambda: None)
+        return method()
 
-    def get_distutils_spec(self):
+    def spec_for_distutils(self):
         import importlib.util
 
         class DistutilsLoader(importlib.util.abc.Loader):
@@ -84,6 +86,14 @@
 
         return importlib.util.spec_from_loader('distutils', DistutilsLoader())
 
+    def spec_for_pip(self):
+        """
+        Ensure stdlib distutils when running under pip.
+        See pypa/pip#8761 for rationale.
+        """
+        clear_distutils()
+        self.spec_for_distutils = lambda: None
+
 
 DISTUTILS_FINDER = DistutilsMetaFinder()
 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -99,7 +99,8 @@
     _pth_name = 'distutils-precedence'
     _pth_contents = textwrap.dedent("""
         import os
-        enabled = os.environ.get('SETUPTOOLS_USE_DISTUTILS') == 'local'
+        var = 'SETUPTOOLS_USE_DISTUTILS'
+        enabled = os.environ.get(var, 'local') == 'local'
         enabled and __import__('_distutils_hack').add_shim()
         """).lstrip().replace('\n', '; ')

{"golden_diff": "diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py\n--- a/_distutils_hack/__init__.py\n+++ b/_distutils_hack/__init__.py\n@@ -37,7 +37,7 @@\n     \"\"\"\n     Allow selection of distutils by environment variable.\n     \"\"\"\n-    which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')\n+    which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')\n     return which == 'local'\n \n \n@@ -66,12 +66,14 @@\n \n class DistutilsMetaFinder:\n     def find_spec(self, fullname, path, target=None):\n-        if path is not None or fullname != \"distutils\":\n-            return None\n+        if path is not None:\n+            return\n \n-        return self.get_distutils_spec()\n+        method_name = 'spec_for_{fullname}'.format(**locals())\n+        method = getattr(self, method_name, lambda: None)\n+        return method()\n \n-    def get_distutils_spec(self):\n+    def spec_for_distutils(self):\n         import importlib.util\n \n         class DistutilsLoader(importlib.util.abc.Loader):\n@@ -84,6 +86,14 @@\n \n         return importlib.util.spec_from_loader('distutils', DistutilsLoader())\n \n+    def spec_for_pip(self):\n+        \"\"\"\n+        Ensure stdlib distutils when running under pip.\n+        See pypa/pip#8761 for rationale.\n+        \"\"\"\n+        clear_distutils()\n+        self.spec_for_distutils = lambda: None\n+\n \n DISTUTILS_FINDER = DistutilsMetaFinder()\n \ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -99,7 +99,8 @@\n     _pth_name = 'distutils-precedence'\n     _pth_contents = textwrap.dedent(\"\"\"\n         import os\n-        enabled = os.environ.get('SETUPTOOLS_USE_DISTUTILS') == 'local'\n+        var = 'SETUPTOOLS_USE_DISTUTILS'\n+        enabled = os.environ.get(var, 'local') == 'local'\n         enabled and __import__('_distutils_hack').add_shim()\n         \"\"\").lstrip().replace('\\n', '; ')\n", "issue": "Debian-specific behavior lost when Setuptools adopts distutils\n`pip install -e $PACKAGE_PATH` installs commands to /usr/bin and not /usr/local/bin on Ubuntu as it did in the past.\r\n\r\n`pip install $PACKAGE_PATH` continues to install to /usr/local/bin as expected.\r\n\r\nOpenstack downstream has temporarily capped setuptools until we know if this is expected behaviour or not.  Please see http://lists.openstack.org/pipermail/openstack-discuss/2020-July/015779.html for more context.\n", "before_files": [{"content": "import sys\nimport os\nimport re\nimport importlib\nimport warnings\n\n\nis_pypy = '__pypy__' in sys.builtin_module_names\n\n\ndef warn_distutils_present():\n    if 'distutils' not in sys.modules:\n        return\n    if is_pypy and sys.version_info < (3, 7):\n        # PyPy for 3.6 unconditionally imports distutils, so bypass the warning\n        # https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250\n        return\n    warnings.warn(\n        \"Distutils was imported before Setuptools, but importing Setuptools \"\n        \"also replaces the `distutils` module in `sys.modules`. This may lead \"\n        \"to undesirable behaviors or errors. To avoid these issues, avoid \"\n        \"using distutils directly, ensure that setuptools is installed in the \"\n        \"traditional way (e.g. not an editable install), and/or make sure that \"\n        \"setuptools is always imported before distutils.\")\n\n\ndef clear_distutils():\n    if 'distutils' not in sys.modules:\n        return\n    warnings.warn(\"Setuptools is replacing distutils.\")\n    mods = [name for name in sys.modules if re.match(r'distutils\\b', name)]\n    for name in mods:\n        del sys.modules[name]\n\n\ndef enabled():\n    \"\"\"\n    Allow selection of distutils by environment variable.\n    \"\"\"\n    which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')\n    return which == 'local'\n\n\ndef ensure_local_distutils():\n    clear_distutils()\n    distutils = importlib.import_module('setuptools._distutils')\n    distutils.__name__ = 'distutils'\n    sys.modules['distutils'] = distutils\n\n    # sanity check that submodules load as expected\n    core = importlib.import_module('distutils.core')\n    assert '_distutils' in core.__file__, core.__file__\n\n\ndef do_override():\n    \"\"\"\n    Ensure that the local copy of distutils is preferred over stdlib.\n\n    See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401\n    for more motivation.\n    \"\"\"\n    if enabled():\n        warn_distutils_present()\n        ensure_local_distutils()\n\n\nclass DistutilsMetaFinder:\n    def find_spec(self, fullname, path, target=None):\n        if path is not None or fullname != \"distutils\":\n            return None\n\n        return self.get_distutils_spec()\n\n    def get_distutils_spec(self):\n        import importlib.util\n\n        class DistutilsLoader(importlib.util.abc.Loader):\n\n            def create_module(self, spec):\n                return importlib.import_module('._distutils', 'setuptools')\n\n            def exec_module(self, module):\n                pass\n\n        return importlib.util.spec_from_loader('distutils', DistutilsLoader())\n\n\nDISTUTILS_FINDER = DistutilsMetaFinder()\n\n\ndef add_shim():\n    sys.meta_path.insert(0, DISTUTILS_FINDER)\n\n\ndef remove_shim():\n    try:\n        sys.meta_path.remove(DISTUTILS_FINDER)\n    except ValueError:\n        pass\n", "path": "_distutils_hack/__init__.py"}, {"content": "#!/usr/bin/env python\n\"\"\"\nDistutils setup file, used to install or test 'setuptools'\n\"\"\"\n\nimport os\nimport sys\nimport textwrap\n\nimport setuptools\nfrom setuptools.command.install import install\n\nhere = os.path.dirname(__file__)\n\n\ndef require_metadata():\n    \"Prevent improper installs without necessary metadata. See #659\"\n    egg_info_dir = os.path.join(here, 'setuptools.egg-info')\n    if not os.path.exists(egg_info_dir):\n        msg = (\n            \"Cannot build setuptools without metadata. \"\n            \"Run `bootstrap.py`.\"\n        )\n        raise RuntimeError(msg)\n\n\ndef read_commands():\n    command_ns = {}\n    cmd_module_path = 'setuptools/command/__init__.py'\n    init_path = os.path.join(here, cmd_module_path)\n    with open(init_path) as init_file:\n        exec(init_file.read(), command_ns)\n    return command_ns['__all__']\n\n\ndef _gen_console_scripts():\n    yield \"easy_install = setuptools.command.easy_install:main\"\n\n    # Gentoo distributions manage the python-version-specific scripts\n    # themselves, so those platforms define an environment variable to\n    # suppress the creation of the version-specific scripts.\n    var_names = (\n        'SETUPTOOLS_DISABLE_VERSIONED_EASY_INSTALL_SCRIPT',\n        'DISTRIBUTE_DISABLE_VERSIONED_EASY_INSTALL_SCRIPT',\n    )\n    if any(os.environ.get(var) not in (None, \"\", \"0\") for var in var_names):\n        return\n    tmpl = \"easy_install-{shortver} = setuptools.command.easy_install:main\"\n    yield tmpl.format(shortver='{}.{}'.format(*sys.version_info))\n\n\npackage_data = dict(\n    setuptools=['script (dev).tmpl', 'script.tmpl', 'site-patch.py'],\n)\n\nforce_windows_specific_files = (\n    os.environ.get(\"SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES\", \"1\").lower()\n    not in (\"\", \"0\", \"false\", \"no\")\n)\n\ninclude_windows_files = (\n    sys.platform == 'win32' or\n    os.name == 'java' and os._name == 'nt' or\n    force_windows_specific_files\n)\n\nif include_windows_files:\n    package_data.setdefault('setuptools', []).extend(['*.exe'])\n    package_data.setdefault('setuptools.command', []).extend(['*.xml'])\n\nneeds_wheel = set(['release', 'bdist_wheel']).intersection(sys.argv)\nwheel = ['wheel'] if needs_wheel else []\n\n\ndef pypi_link(pkg_filename):\n    \"\"\"\n    Given the filename, including md5 fragment, construct the\n    dependency link for PyPI.\n    \"\"\"\n    root = 'https://files.pythonhosted.org/packages/source'\n    name, sep, rest = pkg_filename.partition('-')\n    parts = root, name[0], name, pkg_filename\n    return '/'.join(parts)\n\n\nclass install_with_pth(install):\n    \"\"\"\n    Custom install command to install a .pth file for distutils patching.\n\n    This hack is necessary because there's no standard way to install behavior\n    on startup (and it's debatable if there should be one). This hack (ab)uses\n    the `extra_path` behavior in Setuptools to install a `.pth` file with\n    implicit behavior on startup to give higher precedence to the local version\n    of `distutils` over the version from the standard library.\n\n    Please do not replicate this behavior.\n    \"\"\"\n\n    _pth_name = 'distutils-precedence'\n    _pth_contents = textwrap.dedent(\"\"\"\n        import os\n        enabled = os.environ.get('SETUPTOOLS_USE_DISTUTILS') == 'local'\n        enabled and __import__('_distutils_hack').add_shim()\n        \"\"\").lstrip().replace('\\n', '; ')\n\n    def initialize_options(self):\n        install.initialize_options(self)\n        self.extra_path = self._pth_name, self._pth_contents\n\n    def finalize_options(self):\n        install.finalize_options(self)\n        self._restore_install_lib()\n\n    def _restore_install_lib(self):\n        \"\"\"\n        Undo secondary effect of `extra_path` adding to `install_lib`\n        \"\"\"\n        suffix = os.path.relpath(self.install_lib, self.install_libbase)\n\n        if suffix.strip() == self._pth_contents.strip():\n            self.install_lib = self.install_libbase\n\n\nsetup_params = dict(\n    src_root=None,\n    cmdclass={'install': install_with_pth},\n    package_data=package_data,\n    entry_points={\n        \"distutils.commands\": [\n            \"%(cmd)s = setuptools.command.%(cmd)s:%(cmd)s\" % locals()\n            for cmd in read_commands()\n        ],\n        \"setuptools.finalize_distribution_options\": [\n            \"parent_finalize = setuptools.dist:_Distribution.finalize_options\",\n            \"keywords = setuptools.dist:Distribution._finalize_setup_keywords\",\n            \"2to3_doctests = \"\n            \"setuptools.dist:Distribution._finalize_2to3_doctests\",\n        ],\n        \"distutils.setup_keywords\": [\n            \"eager_resources        = setuptools.dist:assert_string_list\",\n            \"namespace_packages     = setuptools.dist:check_nsp\",\n            \"extras_require         = setuptools.dist:check_extras\",\n            \"install_requires       = setuptools.dist:check_requirements\",\n            \"tests_require          = setuptools.dist:check_requirements\",\n            \"setup_requires         = setuptools.dist:check_requirements\",\n            \"python_requires        = setuptools.dist:check_specifier\",\n            \"entry_points           = setuptools.dist:check_entry_points\",\n            \"test_suite             = setuptools.dist:check_test_suite\",\n            \"zip_safe               = setuptools.dist:assert_bool\",\n            \"package_data           = setuptools.dist:check_package_data\",\n            \"exclude_package_data   = setuptools.dist:check_package_data\",\n            \"include_package_data   = setuptools.dist:assert_bool\",\n            \"packages               = setuptools.dist:check_packages\",\n            \"dependency_links       = setuptools.dist:assert_string_list\",\n            \"test_loader            = setuptools.dist:check_importable\",\n            \"test_runner            = setuptools.dist:check_importable\",\n            \"use_2to3               = setuptools.dist:assert_bool\",\n            \"convert_2to3_doctests  = setuptools.dist:assert_string_list\",\n            \"use_2to3_fixers        = setuptools.dist:assert_string_list\",\n            \"use_2to3_exclude_fixers = setuptools.dist:assert_string_list\",\n        ],\n        \"egg_info.writers\": [\n            \"PKG-INFO = setuptools.command.egg_info:write_pkg_info\",\n            \"requires.txt = setuptools.command.egg_info:write_requirements\",\n            \"entry_points.txt = setuptools.command.egg_info:write_entries\",\n            \"eager_resources.txt = setuptools.command.egg_info:overwrite_arg\",\n            (\n                \"namespace_packages.txt = \"\n                \"setuptools.command.egg_info:overwrite_arg\"\n            ),\n            \"top_level.txt = setuptools.command.egg_info:write_toplevel_names\",\n            \"depends.txt = setuptools.command.egg_info:warn_depends_obsolete\",\n            \"dependency_links.txt = setuptools.command.egg_info:overwrite_arg\",\n        ],\n        \"console_scripts\": list(_gen_console_scripts()),\n        \"setuptools.installation\":\n            ['eggsecutable = setuptools.command.easy_install:bootstrap'],\n    },\n    dependency_links=[\n        pypi_link(\n            'certifi-2016.9.26.tar.gz#md5=baa81e951a29958563689d868ef1064d',\n        ),\n        pypi_link(\n            'wincertstore-0.2.zip#md5=ae728f2f007185648d0c7a8679b361e2',\n        ),\n    ],\n    setup_requires=[\n    ] + wheel,\n)\n\nif __name__ == '__main__':\n    # allow setup.py to run from another directory\n    here and os.chdir(here)\n    require_metadata()\n    dist = setuptools.setup(**setup_params)\n", "path": "setup.py"}], "after_files": [{"content": "import sys\nimport os\nimport re\nimport importlib\nimport warnings\n\n\nis_pypy = '__pypy__' in sys.builtin_module_names\n\n\ndef warn_distutils_present():\n    if 'distutils' not in sys.modules:\n        return\n    if is_pypy and sys.version_info < (3, 7):\n        # PyPy for 3.6 unconditionally imports distutils, so bypass the warning\n        # https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250\n        return\n    warnings.warn(\n        \"Distutils was imported before Setuptools, but importing Setuptools \"\n        \"also replaces the `distutils` module in `sys.modules`. This may lead \"\n        \"to undesirable behaviors or errors. To avoid these issues, avoid \"\n        \"using distutils directly, ensure that setuptools is installed in the \"\n        \"traditional way (e.g. not an editable install), and/or make sure that \"\n        \"setuptools is always imported before distutils.\")\n\n\ndef clear_distutils():\n    if 'distutils' not in sys.modules:\n        return\n    warnings.warn(\"Setuptools is replacing distutils.\")\n    mods = [name for name in sys.modules if re.match(r'distutils\\b', name)]\n    for name in mods:\n        del sys.modules[name]\n\n\ndef enabled():\n    \"\"\"\n    Allow selection of distutils by environment variable.\n    \"\"\"\n    which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')\n    return which == 'local'\n\n\ndef ensure_local_distutils():\n    clear_distutils()\n    distutils = importlib.import_module('setuptools._distutils')\n    distutils.__name__ = 'distutils'\n    sys.modules['distutils'] = distutils\n\n    # sanity check that submodules load as expected\n    core = importlib.import_module('distutils.core')\n    assert '_distutils' in core.__file__, core.__file__\n\n\ndef do_override():\n    \"\"\"\n    Ensure that the local copy of distutils is preferred over stdlib.\n\n    See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401\n    for more motivation.\n    \"\"\"\n    if enabled():\n        warn_distutils_present()\n        ensure_local_distutils()\n\n\nclass DistutilsMetaFinder:\n    def find_spec(self, fullname, path, target=None):\n        if path is not None:\n            return\n\n        method_name = 'spec_for_{fullname}'.format(**locals())\n        method = getattr(self, method_name, lambda: None)\n        return method()\n\n    def spec_for_distutils(self):\n        import importlib.util\n\n        class DistutilsLoader(importlib.util.abc.Loader):\n\n            def create_module(self, spec):\n                return importlib.import_module('._distutils', 'setuptools')\n\n            def exec_module(self, module):\n                pass\n\n        return importlib.util.spec_from_loader('distutils', DistutilsLoader())\n\n    def spec_for_pip(self):\n        \"\"\"\n        Ensure stdlib distutils when running under pip.\n        See pypa/pip#8761 for rationale.\n        \"\"\"\n        clear_distutils()\n        self.spec_for_distutils = lambda: None\n\n\nDISTUTILS_FINDER = DistutilsMetaFinder()\n\n\ndef add_shim():\n    sys.meta_path.insert(0, DISTUTILS_FINDER)\n\n\ndef remove_shim():\n    try:\n        sys.meta_path.remove(DISTUTILS_FINDER)\n    except ValueError:\n        pass\n", "path": "_distutils_hack/__init__.py"}, {"content": "#!/usr/bin/env python\n\"\"\"\nDistutils setup file, used to install or test 'setuptools'\n\"\"\"\n\nimport os\nimport sys\nimport textwrap\n\nimport setuptools\nfrom setuptools.command.install import install\n\nhere = os.path.dirname(__file__)\n\n\ndef require_metadata():\n    \"Prevent improper installs without necessary metadata. See #659\"\n    egg_info_dir = os.path.join(here, 'setuptools.egg-info')\n    if not os.path.exists(egg_info_dir):\n        msg = (\n            \"Cannot build setuptools without metadata. \"\n            \"Run `bootstrap.py`.\"\n        )\n        raise RuntimeError(msg)\n\n\ndef read_commands():\n    command_ns = {}\n    cmd_module_path = 'setuptools/command/__init__.py'\n    init_path = os.path.join(here, cmd_module_path)\n    with open(init_path) as init_file:\n        exec(init_file.read(), command_ns)\n    return command_ns['__all__']\n\n\ndef _gen_console_scripts():\n    yield \"easy_install = setuptools.command.easy_install:main\"\n\n    # Gentoo distributions manage the python-version-specific scripts\n    # themselves, so those platforms define an environment variable to\n    # suppress the creation of the version-specific scripts.\n    var_names = (\n        'SETUPTOOLS_DISABLE_VERSIONED_EASY_INSTALL_SCRIPT',\n        'DISTRIBUTE_DISABLE_VERSIONED_EASY_INSTALL_SCRIPT',\n    )\n    if any(os.environ.get(var) not in (None, \"\", \"0\") for var in var_names):\n        return\n    tmpl = \"easy_install-{shortver} = setuptools.command.easy_install:main\"\n    yield tmpl.format(shortver='{}.{}'.format(*sys.version_info))\n\n\npackage_data = dict(\n    setuptools=['script (dev).tmpl', 'script.tmpl', 'site-patch.py'],\n)\n\nforce_windows_specific_files = (\n    os.environ.get(\"SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES\", \"1\").lower()\n    not in (\"\", \"0\", \"false\", \"no\")\n)\n\ninclude_windows_files = (\n    sys.platform == 'win32' or\n    os.name == 'java' and os._name == 'nt' or\n    force_windows_specific_files\n)\n\nif include_windows_files:\n    package_data.setdefault('setuptools', []).extend(['*.exe'])\n    package_data.setdefault('setuptools.command', []).extend(['*.xml'])\n\nneeds_wheel = set(['release', 'bdist_wheel']).intersection(sys.argv)\nwheel = ['wheel'] if needs_wheel else []\n\n\ndef pypi_link(pkg_filename):\n    \"\"\"\n    Given the filename, including md5 fragment, construct the\n    dependency link for PyPI.\n    \"\"\"\n    root = 'https://files.pythonhosted.org/packages/source'\n    name, sep, rest = pkg_filename.partition('-')\n    parts = root, name[0], name, pkg_filename\n    return '/'.join(parts)\n\n\nclass install_with_pth(install):\n    \"\"\"\n    Custom install command to install a .pth file for distutils patching.\n\n    This hack is necessary because there's no standard way to install behavior\n    on startup (and it's debatable if there should be one). This hack (ab)uses\n    the `extra_path` behavior in Setuptools to install a `.pth` file with\n    implicit behavior on startup to give higher precedence to the local version\n    of `distutils` over the version from the standard library.\n\n    Please do not replicate this behavior.\n    \"\"\"\n\n    _pth_name = 'distutils-precedence'\n    _pth_contents = textwrap.dedent(\"\"\"\n        import os\n        var = 'SETUPTOOLS_USE_DISTUTILS'\n        enabled = os.environ.get(var, 'local') == 'local'\n        enabled and __import__('_distutils_hack').add_shim()\n        \"\"\").lstrip().replace('\\n', '; ')\n\n    def initialize_options(self):\n        install.initialize_options(self)\n        self.extra_path = self._pth_name, self._pth_contents\n\n    def finalize_options(self):\n        install.finalize_options(self)\n        self._restore_install_lib()\n\n    def _restore_install_lib(self):\n        \"\"\"\n        Undo secondary effect of `extra_path` adding to `install_lib`\n        \"\"\"\n        suffix = os.path.relpath(self.install_lib, self.install_libbase)\n\n        if suffix.strip() == self._pth_contents.strip():\n            self.install_lib = self.install_libbase\n\n\nsetup_params = dict(\n    src_root=None,\n    cmdclass={'install': install_with_pth},\n    package_data=package_data,\n    entry_points={\n        \"distutils.commands\": [\n            \"%(cmd)s = setuptools.command.%(cmd)s:%(cmd)s\" % locals()\n            for cmd in read_commands()\n        ],\n        \"setuptools.finalize_distribution_options\": [\n            \"parent_finalize = setuptools.dist:_Distribution.finalize_options\",\n            \"keywords = setuptools.dist:Distribution._finalize_setup_keywords\",\n            \"2to3_doctests = \"\n            \"setuptools.dist:Distribution._finalize_2to3_doctests\",\n        ],\n        \"distutils.setup_keywords\": [\n            \"eager_resources        = setuptools.dist:assert_string_list\",\n            \"namespace_packages     = setuptools.dist:check_nsp\",\n            \"extras_require         = setuptools.dist:check_extras\",\n            \"install_requires       = setuptools.dist:check_requirements\",\n            \"tests_require          = setuptools.dist:check_requirements\",\n            \"setup_requires         = setuptools.dist:check_requirements\",\n            \"python_requires        = setuptools.dist:check_specifier\",\n            \"entry_points           = setuptools.dist:check_entry_points\",\n            \"test_suite             = setuptools.dist:check_test_suite\",\n            \"zip_safe               = setuptools.dist:assert_bool\",\n            \"package_data           = setuptools.dist:check_package_data\",\n            \"exclude_package_data   = setuptools.dist:check_package_data\",\n            \"include_package_data   = setuptools.dist:assert_bool\",\n            \"packages               = setuptools.dist:check_packages\",\n            \"dependency_links       = setuptools.dist:assert_string_list\",\n            \"test_loader            = setuptools.dist:check_importable\",\n            \"test_runner            = setuptools.dist:check_importable\",\n            \"use_2to3               = setuptools.dist:assert_bool\",\n            \"convert_2to3_doctests  = setuptools.dist:assert_string_list\",\n            \"use_2to3_fixers        = setuptools.dist:assert_string_list\",\n            \"use_2to3_exclude_fixers = setuptools.dist:assert_string_list\",\n        ],\n        \"egg_info.writers\": [\n            \"PKG-INFO = setuptools.command.egg_info:write_pkg_info\",\n            \"requires.txt = setuptools.command.egg_info:write_requirements\",\n            \"entry_points.txt = setuptools.command.egg_info:write_entries\",\n            \"eager_resources.txt = setuptools.command.egg_info:overwrite_arg\",\n            (\n                \"namespace_packages.txt = \"\n                \"setuptools.command.egg_info:overwrite_arg\"\n            ),\n            \"top_level.txt = setuptools.command.egg_info:write_toplevel_names\",\n            \"depends.txt = setuptools.command.egg_info:warn_depends_obsolete\",\n            \"dependency_links.txt = setuptools.command.egg_info:overwrite_arg\",\n        ],\n        \"console_scripts\": list(_gen_console_scripts()),\n        \"setuptools.installation\":\n            ['eggsecutable = setuptools.command.easy_install:bootstrap'],\n    },\n    dependency_links=[\n        pypi_link(\n            'certifi-2016.9.26.tar.gz#md5=baa81e951a29958563689d868ef1064d',\n        ),\n        pypi_link(\n            'wincertstore-0.2.zip#md5=ae728f2f007185648d0c7a8679b361e2',\n        ),\n    ],\n    setup_requires=[\n    ] + wheel,\n)\n\nif __name__ == '__main__':\n    # allow setup.py to run from another directory\n    here and os.chdir(here)\n    require_metadata()\n    dist = setuptools.setup(**setup_params)\n", "path": "setup.py"}]}