We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
AssertionError no _distutils when running get-pip with Setuptools and USE_DISTUTILS=local
Somehow related: Since `setuptools` v60 at least on Debian running `get-pip.py` over an existing `pip` + `setuptools` fails, when the Debian `python3-distutils` package is installed, e.g. as dependency of the Python development headers package:
```
/usr/local/lib/python3.9/dist-packages/_distutils_hack/__init__.py:24: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.
  warnings.warn(
/usr/local/lib/python3.9/dist-packages/_distutils_hack/__init__.py:36: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")
Traceback (most recent call last):
  File "/tmp/DietPi-Software/./get-pip.py", line 27081, in <module>
    main()
  File "/tmp/DietPi-Software/./get-pip.py", line 139, in main
    bootstrap(tmpdir=tmpdir)
  File "/tmp/DietPi-Software/./get-pip.py", line 120, in bootstrap
    args = determine_pip_install_arguments()
  File "/tmp/DietPi-Software/./get-pip.py", line 65, in determine_pip_install_arguments
    import setuptools  # noqa
  File "/usr/local/lib/python3.9/dist-packages/setuptools/__init__.py", line 8, in <module>
    import _distutils_hack.override  # noqa: F401
  File "/usr/local/lib/python3.9/dist-packages/_distutils_hack/override.py", line 1, in <module>
    __import__('_distutils_hack').do_override()
  File "/usr/local/lib/python3.9/dist-packages/_distutils_hack/__init__.py", line 73, in do_override
    ensure_local_distutils()
  File "/usr/local/lib/python3.9/dist-packages/_distutils_hack/__init__.py", line 61, in ensure_local_distutils
    assert '_distutils' in core.__file__, core.__file__
AssertionError: /usr/lib/python3.9/distutils/core.py
```
This `_distutils_hack` comes from `get-pip.py`. Looks like removing any use and detangling `distutils` from `pip` in favour of `setuptools` would solve both issues.

_Originally posted by @MichaIng in https://github.com/pypa/pip/issues/10742#issuecomment-1003741034_

--- 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 # don't import any costly modules
2 import sys
3 import os
4 
5 
6 is_pypy = '__pypy__' in sys.builtin_module_names
7 
8 
9 def warn_distutils_present():
10     if 'distutils' not in sys.modules:
11         return
12     if is_pypy and sys.version_info < (3, 7):
13         # PyPy for 3.6 unconditionally imports distutils, so bypass the warning
14         # https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
15         return
16     import warnings
17     warnings.warn(
18         "Distutils was imported before Setuptools, but importing Setuptools "
19         "also replaces the `distutils` module in `sys.modules`. This may lead "
20         "to undesirable behaviors or errors. To avoid these issues, avoid "
21         "using distutils directly, ensure that setuptools is installed in the "
22         "traditional way (e.g. not an editable install), and/or make sure "
23         "that setuptools is always imported before distutils.")
24 
25 
26 def clear_distutils():
27     if 'distutils' not in sys.modules:
28         return
29     import warnings
30     warnings.warn("Setuptools is replacing distutils.")
31     mods = [
32         name for name in sys.modules
33         if name == "distutils" or name.startswith("distutils.")
34     ]
35     for name in mods:
36         del sys.modules[name]
37 
38 
39 def enabled():
40     """
41     Allow selection of distutils by environment variable.
42     """
43     which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')
44     return which == 'local'
45 
46 
47 def ensure_local_distutils():
48     import importlib
49     clear_distutils()
50 
51     # With the DistutilsMetaFinder in place,
52     # perform an import to cause distutils to be
53     # loaded from setuptools._distutils. Ref #2906.
54     with shim():
55         importlib.import_module('distutils')
56 
57     # check that submodules load as expected
58     core = importlib.import_module('distutils.core')
59     assert '_distutils' in core.__file__, core.__file__
60 
61 
62 def do_override():
63     """
64     Ensure that the local copy of distutils is preferred over stdlib.
65 
66     See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
67     for more motivation.
68     """
69     if enabled():
70         warn_distutils_present()
71         ensure_local_distutils()
72 
73 
74 class _TrivialRe:
75     def __init__(self, *patterns):
76         self._patterns = patterns
77 
78     def match(self, string):
79         return all(pat in string for pat in self._patterns)
80 
81 
82 class DistutilsMetaFinder:
83     def find_spec(self, fullname, path, target=None):
84         if path is not None:
85             return
86 
87         method_name = 'spec_for_{fullname}'.format(**locals())
88         method = getattr(self, method_name, lambda: None)
89         return method()
90 
91     def spec_for_distutils(self):
92         import importlib
93         import importlib.abc
94         import importlib.util
95         import warnings
96 
97         # warnings.filterwarnings() imports the re module
98         warnings._add_filter(
99             'ignore',
100             _TrivialRe("distutils", "deprecated"),
101             DeprecationWarning,
102             None,
103             0,
104             append=True
105         )
106 
107         try:
108             mod = importlib.import_module('setuptools._distutils')
109         except Exception:
110             # There are a couple of cases where setuptools._distutils
111             # may not be present:
112             # - An older Setuptools without a local distutils is
113             #   taking precedence. Ref #2957.
114             # - Path manipulation during sitecustomize removes
115             #   setuptools from the path but only after the hook
116             #   has been loaded. Ref #2980.
117             # In either case, fall back to stdlib behavior.
118             return
119 
120         class DistutilsLoader(importlib.abc.Loader):
121 
122             def create_module(self, spec):
123                 return mod
124 
125             def exec_module(self, module):
126                 pass
127 
128         return importlib.util.spec_from_loader(
129             'distutils', DistutilsLoader(), origin=mod.__file__
130         )
131 
132     def spec_for_pip(self):
133         """
134         Ensure stdlib distutils when running under pip.
135         See pypa/pip#8761 for rationale.
136         """
137         if self.pip_imported_during_build():
138             return
139         if self.is_get_pip():
140             return
141         clear_distutils()
142         self.spec_for_distutils = lambda: None
143 
144     @classmethod
145     def pip_imported_during_build(cls):
146         """
147         Detect if pip is being imported in a build script. Ref #2355.
148         """
149         import traceback
150         return any(
151             cls.frame_file_is_setup(frame)
152             for frame, line in traceback.walk_stack(None)
153         )
154 
155     @classmethod
156     def is_get_pip(cls):
157         """
158         Detect if get-pip is being invoked. Ref #2993.
159         """
160         try:
161             import __main__
162             return os.path.basename(__main__.__file__) == 'get-pip.py'
163         except AttributeError:
164             pass
165 
166     @staticmethod
167     def frame_file_is_setup(frame):
168         """
169         Return True if the indicated frame suggests a setup.py file.
170         """
171         # some frames may not have __file__ (#2940)
172         return frame.f_globals.get('__file__', '').endswith('setup.py')
173 
174 
175 DISTUTILS_FINDER = DistutilsMetaFinder()
176 
177 
178 def add_shim():
179     DISTUTILS_FINDER in sys.meta_path or insert_shim()
180 
181 
182 class shim:
183     def __enter__(self):
184         insert_shim()
185 
186     def __exit__(self, exc, value, tb):
187         remove_shim()
188 
189 
190 def insert_shim():
191     sys.meta_path.insert(0, DISTUTILS_FINDER)
192 
193 
194 def remove_shim():
195     try:
196         sys.meta_path.remove(DISTUTILS_FINDER)
197     except ValueError:
198         pass
199
```
--- 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
@@ -136,11 +136,36 @@
         """
         if self.pip_imported_during_build():
             return
-        if self.is_get_pip():
-            return
         clear_distutils()
         self.spec_for_distutils = lambda: None
 
+    def spec_for_setuptools(self):
+        """
+        get-pip imports setuptools solely for the purpose of
+        determining if it's installed. In this case, provide
+        a stubbed spec to represent setuptools being present
+        without invoking any behavior.
+
+        Workaround for pypa/get-pip#137.
+        """
+        if not self.is_get_pip():
+            return
+
+        import importlib
+
+        class StubbedLoader(importlib.abc.Loader):
+
+            def create_module(self, spec):
+                import types
+                return types.ModuleType('setuptools')
+
+            def exec_module(self, module):
+                pass
+
+        return importlib.util.spec_from_loader(
+            'setuptools', StubbedLoader(),
+        )
+
     @classmethod
     def pip_imported_during_build(cls):
         """

{"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@@ -136,11 +136,36 @@\n         \"\"\"\n         if self.pip_imported_during_build():\n             return\n-        if self.is_get_pip():\n-            return\n         clear_distutils()\n         self.spec_for_distutils = lambda: None\n \n+    def spec_for_setuptools(self):\n+        \"\"\"\n+        get-pip imports setuptools solely for the purpose of\n+        determining if it's installed. In this case, provide\n+        a stubbed spec to represent setuptools being present\n+        without invoking any behavior.\n+\n+        Workaround for pypa/get-pip#137.\n+        \"\"\"\n+        if not self.is_get_pip():\n+            return\n+\n+        import importlib\n+\n+        class StubbedLoader(importlib.abc.Loader):\n+\n+            def create_module(self, spec):\n+                import types\n+                return types.ModuleType('setuptools')\n+\n+            def exec_module(self, module):\n+                pass\n+\n+        return importlib.util.spec_from_loader(\n+            'setuptools', StubbedLoader(),\n+        )\n+\n     @classmethod\n     def pip_imported_during_build(cls):\n         \"\"\"\n", "issue": "AssertionError no _distutils when running get-pip with Setuptools and USE_DISTUTILS=local\nSomehow related: Since `setuptools` v60 at least on Debian running `get-pip.py` over an existing `pip` + `setuptools` fails, when the Debian `python3-distutils` package is installed, e.g. as dependency of the Python development headers package:\r\n```\r\n/usr/local/lib/python3.9/dist-packages/_distutils_hack/__init__.py:24: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.\r\n  warnings.warn(\r\n/usr/local/lib/python3.9/dist-packages/_distutils_hack/__init__.py:36: UserWarning: Setuptools is replacing distutils.\r\n  warnings.warn(\"Setuptools is replacing distutils.\")\r\nTraceback (most recent call last):\r\n  File \"/tmp/DietPi-Software/./get-pip.py\", line 27081, in <module>\r\n    main()\r\n  File \"/tmp/DietPi-Software/./get-pip.py\", line 139, in main\r\n    bootstrap(tmpdir=tmpdir)\r\n  File \"/tmp/DietPi-Software/./get-pip.py\", line 120, in bootstrap\r\n    args = determine_pip_install_arguments()\r\n  File \"/tmp/DietPi-Software/./get-pip.py\", line 65, in determine_pip_install_arguments\r\n    import setuptools  # noqa\r\n  File \"/usr/local/lib/python3.9/dist-packages/setuptools/__init__.py\", line 8, in <module>\r\n    import _distutils_hack.override  # noqa: F401\r\n  File \"/usr/local/lib/python3.9/dist-packages/_distutils_hack/override.py\", line 1, in <module>\r\n    __import__('_distutils_hack').do_override()\r\n  File \"/usr/local/lib/python3.9/dist-packages/_distutils_hack/__init__.py\", line 73, in do_override\r\n    ensure_local_distutils()\r\n  File \"/usr/local/lib/python3.9/dist-packages/_distutils_hack/__init__.py\", line 61, in ensure_local_distutils\r\n    assert '_distutils' in core.__file__, core.__file__\r\nAssertionError: /usr/lib/python3.9/distutils/core.py\r\n```\r\nThis `_distutils_hack` comes from `get-pip.py`. Looks like removing any use and detangling `distutils` from `pip` in favour of `setuptools` would solve both issues.\r\n\r\n_Originally posted by @MichaIng in https://github.com/pypa/pip/issues/10742#issuecomment-1003741034_\n", "before_files": [{"content": "# don't import any costly modules\nimport sys\nimport os\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    import warnings\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 \"\n        \"that setuptools is always imported before distutils.\")\n\n\ndef clear_distutils():\n    if 'distutils' not in sys.modules:\n        return\n    import warnings\n    warnings.warn(\"Setuptools is replacing distutils.\")\n    mods = [\n        name for name in sys.modules\n        if name == \"distutils\" or name.startswith(\"distutils.\")\n    ]\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    import importlib\n    clear_distutils()\n\n    # With the DistutilsMetaFinder in place,\n    # perform an import to cause distutils to be\n    # loaded from setuptools._distutils. Ref #2906.\n    with shim():\n        importlib.import_module('distutils')\n\n    # 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 _TrivialRe:\n    def __init__(self, *patterns):\n        self._patterns = patterns\n\n    def match(self, string):\n        return all(pat in string for pat in self._patterns)\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\n        import importlib.abc\n        import importlib.util\n        import warnings\n\n        # warnings.filterwarnings() imports the re module\n        warnings._add_filter(\n            'ignore',\n            _TrivialRe(\"distutils\", \"deprecated\"),\n            DeprecationWarning,\n            None,\n            0,\n            append=True\n        )\n\n        try:\n            mod = importlib.import_module('setuptools._distutils')\n        except Exception:\n            # There are a couple of cases where setuptools._distutils\n            # may not be present:\n            # - An older Setuptools without a local distutils is\n            #   taking precedence. Ref #2957.\n            # - Path manipulation during sitecustomize removes\n            #   setuptools from the path but only after the hook\n            #   has been loaded. Ref #2980.\n            # In either case, fall back to stdlib behavior.\n            return\n\n        class DistutilsLoader(importlib.abc.Loader):\n\n            def create_module(self, spec):\n                return mod\n\n            def exec_module(self, module):\n                pass\n\n        return importlib.util.spec_from_loader(\n            'distutils', DistutilsLoader(), origin=mod.__file__\n        )\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        if self.pip_imported_during_build():\n            return\n        if self.is_get_pip():\n            return\n        clear_distutils()\n        self.spec_for_distutils = lambda: None\n\n    @classmethod\n    def pip_imported_during_build(cls):\n        \"\"\"\n        Detect if pip is being imported in a build script. Ref #2355.\n        \"\"\"\n        import traceback\n        return any(\n            cls.frame_file_is_setup(frame)\n            for frame, line in traceback.walk_stack(None)\n        )\n\n    @classmethod\n    def is_get_pip(cls):\n        \"\"\"\n        Detect if get-pip is being invoked. Ref #2993.\n        \"\"\"\n        try:\n            import __main__\n            return os.path.basename(__main__.__file__) == 'get-pip.py'\n        except AttributeError:\n            pass\n\n    @staticmethod\n    def frame_file_is_setup(frame):\n        \"\"\"\n        Return True if the indicated frame suggests a setup.py file.\n        \"\"\"\n        # some frames may not have __file__ (#2940)\n        return frame.f_globals.get('__file__', '').endswith('setup.py')\n\n\nDISTUTILS_FINDER = DistutilsMetaFinder()\n\n\ndef add_shim():\n    DISTUTILS_FINDER in sys.meta_path or insert_shim()\n\n\nclass shim:\n    def __enter__(self):\n        insert_shim()\n\n    def __exit__(self, exc, value, tb):\n        remove_shim()\n\n\ndef insert_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"}], "after_files": [{"content": "# don't import any costly modules\nimport sys\nimport os\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    import warnings\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 \"\n        \"that setuptools is always imported before distutils.\")\n\n\ndef clear_distutils():\n    if 'distutils' not in sys.modules:\n        return\n    import warnings\n    warnings.warn(\"Setuptools is replacing distutils.\")\n    mods = [\n        name for name in sys.modules\n        if name == \"distutils\" or name.startswith(\"distutils.\")\n    ]\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    import importlib\n    clear_distutils()\n\n    # With the DistutilsMetaFinder in place,\n    # perform an import to cause distutils to be\n    # loaded from setuptools._distutils. Ref #2906.\n    with shim():\n        importlib.import_module('distutils')\n\n    # 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 _TrivialRe:\n    def __init__(self, *patterns):\n        self._patterns = patterns\n\n    def match(self, string):\n        return all(pat in string for pat in self._patterns)\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\n        import importlib.abc\n        import importlib.util\n        import warnings\n\n        # warnings.filterwarnings() imports the re module\n        warnings._add_filter(\n            'ignore',\n            _TrivialRe(\"distutils\", \"deprecated\"),\n            DeprecationWarning,\n            None,\n            0,\n            append=True\n        )\n\n        try:\n            mod = importlib.import_module('setuptools._distutils')\n        except Exception:\n            # There are a couple of cases where setuptools._distutils\n            # may not be present:\n            # - An older Setuptools without a local distutils is\n            #   taking precedence. Ref #2957.\n            # - Path manipulation during sitecustomize removes\n            #   setuptools from the path but only after the hook\n            #   has been loaded. Ref #2980.\n            # In either case, fall back to stdlib behavior.\n            return\n\n        class DistutilsLoader(importlib.abc.Loader):\n\n            def create_module(self, spec):\n                return mod\n\n            def exec_module(self, module):\n                pass\n\n        return importlib.util.spec_from_loader(\n            'distutils', DistutilsLoader(), origin=mod.__file__\n        )\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        if self.pip_imported_during_build():\n            return\n        clear_distutils()\n        self.spec_for_distutils = lambda: None\n\n    def spec_for_setuptools(self):\n        \"\"\"\n        get-pip imports setuptools solely for the purpose of\n        determining if it's installed. In this case, provide\n        a stubbed spec to represent setuptools being present\n        without invoking any behavior.\n\n        Workaround for pypa/get-pip#137.\n        \"\"\"\n        if not self.is_get_pip():\n            return\n\n        import importlib\n\n        class StubbedLoader(importlib.abc.Loader):\n\n            def create_module(self, spec):\n                import types\n                return types.ModuleType('setuptools')\n\n            def exec_module(self, module):\n                pass\n\n        return importlib.util.spec_from_loader(\n            'setuptools', StubbedLoader(),\n        )\n\n    @classmethod\n    def pip_imported_during_build(cls):\n        \"\"\"\n        Detect if pip is being imported in a build script. Ref #2355.\n        \"\"\"\n        import traceback\n        return any(\n            cls.frame_file_is_setup(frame)\n            for frame, line in traceback.walk_stack(None)\n        )\n\n    @classmethod\n    def is_get_pip(cls):\n        \"\"\"\n        Detect if get-pip is being invoked. Ref #2993.\n        \"\"\"\n        try:\n            import __main__\n            return os.path.basename(__main__.__file__) == 'get-pip.py'\n        except AttributeError:\n            pass\n\n    @staticmethod\n    def frame_file_is_setup(frame):\n        \"\"\"\n        Return True if the indicated frame suggests a setup.py file.\n        \"\"\"\n        # some frames may not have __file__ (#2940)\n        return frame.f_globals.get('__file__', '').endswith('setup.py')\n\n\nDISTUTILS_FINDER = DistutilsMetaFinder()\n\n\ndef add_shim():\n    DISTUTILS_FINDER in sys.meta_path or insert_shim()\n\n\nclass shim:\n    def __enter__(self):\n        insert_shim()\n\n    def __exit__(self, exc, value, tb):\n        remove_shim()\n\n\ndef insert_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"}]}