prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  `distutils` submodules being loaded from the stdlib
  It seems the issue is that `distutils.sysconfig` is being loaded from the stdlib, even though [the distutils hack has an explicit check that submodules are loaded from the locally-bundled copy](https://github.com/pypa/setuptools/blob/dd5a2cec373ffe7eefc087c1cd06fb4e491a7e88/_distutils_hack/__init__.py#L55-L57).
  
  _Originally posted by @jaraco in https://github.com/pypa/distutils/issues/16#issuecomment-980043534_
  `distutils` submodules being loaded from the stdlib
  It seems the issue is that `distutils.sysconfig` is being loaded from the stdlib, even though [the distutils hack has an explicit check that submodules are loaded from the locally-bundled copy](https://github.com/pypa/setuptools/blob/dd5a2cec373ffe7eefc087c1cd06fb4e491a7e88/_distutils_hack/__init__.py#L55-L57).
  
  _Originally posted by @jaraco in https://github.com/pypa/distutils/issues/16#issuecomment-980043534_
  
  </issue>
  <code>
  [start of _distutils_hack/__init__.py]
  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 warnings.filterwarnings('ignore',
  12                         r'.+ distutils\b.+ deprecated',
  13                         DeprecationWarning)
  14 
  15 
  16 def warn_distutils_present():
  17     if 'distutils' not in sys.modules:
  18         return
  19     if is_pypy and sys.version_info < (3, 7):
  20         # PyPy for 3.6 unconditionally imports distutils, so bypass the warning
  21         # https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
  22         return
  23     warnings.warn(
  24         "Distutils was imported before Setuptools, but importing Setuptools "
  25         "also replaces the `distutils` module in `sys.modules`. This may lead "
  26         "to undesirable behaviors or errors. To avoid these issues, avoid "
  27         "using distutils directly, ensure that setuptools is installed in the "
  28         "traditional way (e.g. not an editable install), and/or make sure "
  29         "that setuptools is always imported before distutils.")
  30 
  31 
  32 def clear_distutils():
  33     if 'distutils' not in sys.modules:
  34         return
  35     warnings.warn("Setuptools is replacing distutils.")
  36     mods = [name for name in sys.modules if re.match(r'distutils\b', name)]
  37     for name in mods:
  38         del sys.modules[name]
  39 
  40 
  41 def enabled():
  42     """
  43     Allow selection of distutils by environment variable.
  44     """
  45     which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
  46     return which == 'local'
  47 
  48 
  49 def ensure_local_distutils():
  50     clear_distutils()
  51     distutils = importlib.import_module('setuptools._distutils')
  52     distutils.__name__ = 'distutils'
  53     sys.modules['distutils'] = distutils
  54 
  55     # sanity check that submodules load as expected
  56     core = importlib.import_module('distutils.core')
  57     assert '_distutils' in core.__file__, core.__file__
  58 
  59 
  60 def do_override():
  61     """
  62     Ensure that the local copy of distutils is preferred over stdlib.
  63 
  64     See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
  65     for more motivation.
  66     """
  67     if enabled():
  68         warn_distutils_present()
  69         ensure_local_distutils()
  70 
  71 
  72 class DistutilsMetaFinder:
  73     def find_spec(self, fullname, path, target=None):
  74         if path is not None:
  75             return
  76 
  77         method_name = 'spec_for_{fullname}'.format(**locals())
  78         method = getattr(self, method_name, lambda: None)
  79         return method()
  80 
  81     def spec_for_distutils(self):
  82         import importlib.abc
  83         import importlib.util
  84 
  85         class DistutilsLoader(importlib.abc.Loader):
  86 
  87             def create_module(self, spec):
  88                 return importlib.import_module('setuptools._distutils')
  89 
  90             def exec_module(self, module):
  91                 pass
  92 
  93         return importlib.util.spec_from_loader('distutils', DistutilsLoader())
  94 
  95     def spec_for_pip(self):
  96         """
  97         Ensure stdlib distutils when running under pip.
  98         See pypa/pip#8761 for rationale.
  99         """
  100         if self.pip_imported_during_build():
  101             return
  102         clear_distutils()
  103         self.spec_for_distutils = lambda: None
  104 
  105     @staticmethod
  106     def pip_imported_during_build():
  107         """
  108         Detect if pip is being imported in a build script. Ref #2355.
  109         """
  110         import traceback
  111         return any(
  112             frame.f_globals['__file__'].endswith('setup.py')
  113             for frame, line in traceback.walk_stack(None)
  114         )
  115 
  116 
  117 DISTUTILS_FINDER = DistutilsMetaFinder()
  118 
  119 
  120 def add_shim():
  121     sys.meta_path.insert(0, DISTUTILS_FINDER)
  122 
  123 
  124 def remove_shim():
  125     try:
  126         sys.meta_path.remove(DISTUTILS_FINDER)
  127     except ValueError:
  128         pass
  129
  [end of _distutils_hack/__init__.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py
  --- a/_distutils_hack/__init__.py
  +++ b/_distutils_hack/__init__.py
  @@ -48,11 +48,15 @@
   
   def ensure_local_distutils():
       clear_distutils()
  -    distutils = importlib.import_module('setuptools._distutils')
  -    distutils.__name__ = 'distutils'
  -    sys.modules['distutils'] = distutils
   
  -    # sanity check that submodules load as expected
  +    # With the DistutilsMetaFinder in place,
  +    # perform an import to cause distutils to be
  +    # loaded from setuptools._distutils. Ref #2906.
  +    add_shim()
  +    importlib.import_module('distutils')
  +    remove_shim()
  +
  +    # check that submodules load as expected
       core = importlib.import_module('distutils.core')
       assert '_distutils' in core.__file__, core.__file__
  
verification_info: {"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@@ -48,11 +48,15 @@\n \n def 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+    # With the DistutilsMetaFinder in place,\n+    # perform an import to cause distutils to be\n+    # loaded from setuptools._distutils. Ref #2906.\n+    add_shim()\n+    importlib.import_module('distutils')\n+    remove_shim()\n+\n+    # check that submodules load as expected\n     core = importlib.import_module('distutils.core')\n     assert '_distutils' in core.__file__, core.__file__\n", "issue": "`distutils` submodules being loaded from the stdlib\nIt seems the issue is that `distutils.sysconfig` is being loaded from the stdlib, even though [the distutils hack has an explicit check that submodules are loaded from the locally-bundled copy](https://github.com/pypa/setuptools/blob/dd5a2cec373ffe7eefc087c1cd06fb4e491a7e88/_distutils_hack/__init__.py#L55-L57).\r\n\r\n_Originally posted by @jaraco in https://github.com/pypa/distutils/issues/16#issuecomment-980043534_\n`distutils` submodules being loaded from the stdlib\nIt seems the issue is that `distutils.sysconfig` is being loaded from the stdlib, even though [the distutils hack has an explicit check that submodules are loaded from the locally-bundled copy](https://github.com/pypa/setuptools/blob/dd5a2cec373ffe7eefc087c1cd06fb4e491a7e88/_distutils_hack/__init__.py#L55-L57).\r\n\r\n_Originally posted by @jaraco in https://github.com/pypa/distutils/issues/16#issuecomment-980043534_\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\nwarnings.filterwarnings('ignore',\n                        r'.+ distutils\\b.+ deprecated',\n                        DeprecationWarning)\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 \"\n        \"that 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:\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.abc\n        import importlib.util\n\n        class DistutilsLoader(importlib.abc.Loader):\n\n            def create_module(self, spec):\n                return importlib.import_module('setuptools._distutils')\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        if self.pip_imported_during_build():\n            return\n        clear_distutils()\n        self.spec_for_distutils = lambda: None\n\n    @staticmethod\n    def pip_imported_during_build():\n        \"\"\"\n        Detect if pip is being imported in a build script. Ref #2355.\n        \"\"\"\n        import traceback\n        return any(\n            frame.f_globals['__file__'].endswith('setup.py')\n            for frame, line in traceback.walk_stack(None)\n        )\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"}]}