prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  SystemError: Parent module 'setuptools' not loaded, cannot perform relative import with setuptools 50
  After upgrading setuptools to 50.0 today, the environment fails to locate the entry points as it could not import distutils
  
  ```
  $ python --version
  Python 3.5.1
  $ python -c "import distutils"
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "<frozen importlib._bootstrap>", line 969, in _find_and_load
    File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
    File "<frozen importlib._bootstrap>", line 577, in module_from_spec
    File "/home/gchan/tmp/setuptools-python-3.5/lib/python3.5/site-packages/_distutils_hack/__init__.py", line 82, in create_module
      return importlib.import_module('._distutils', 'setuptools')
    File "/home/gchan/tmp/setuptools-python-3.5/lib64/python3.5/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 981, in _gcd_import
    File "<frozen importlib._bootstrap>", line 931, in _sanity_check
  SystemError: Parent module 'setuptools' not loaded, cannot perform relative import
  ```
  
  The issue could not be found in the python 3.8 environment.  
  
  --- 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', 'local')
  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:
  70             return
  71 
  72         method_name = 'spec_for_{fullname}'.format(**locals())
  73         method = getattr(self, method_name, lambda: None)
  74         return method()
  75 
  76     def spec_for_distutils(self):
  77         import importlib.abc
  78         import importlib.util
  79 
  80         class DistutilsLoader(importlib.abc.Loader):
  81 
  82             def create_module(self, spec):
  83                 return importlib.import_module('._distutils', 'setuptools')
  84 
  85             def exec_module(self, module):
  86                 pass
  87 
  88         return importlib.util.spec_from_loader('distutils', DistutilsLoader())
  89 
  90     def spec_for_pip(self):
  91         """
  92         Ensure stdlib distutils when running under pip.
  93         See pypa/pip#8761 for rationale.
  94         """
  95         clear_distutils()
  96         self.spec_for_distutils = lambda: None
  97 
  98 
  99 DISTUTILS_FINDER = DistutilsMetaFinder()
  100 
  101 
  102 def add_shim():
  103     sys.meta_path.insert(0, DISTUTILS_FINDER)
  104 
  105 
  106 def remove_shim():
  107     try:
  108         sys.meta_path.remove(DISTUTILS_FINDER)
  109     except ValueError:
  110         pass
  111
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py
  --- a/_distutils_hack/__init__.py
  +++ b/_distutils_hack/__init__.py
  @@ -80,7 +80,7 @@
           class DistutilsLoader(importlib.abc.Loader):
   
               def create_module(self, spec):
  -                return importlib.import_module('._distutils', 'setuptools')
  +                return importlib.import_module('setuptools._distutils')
   
               def exec_module(self, module):
                   pass
  
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@@ -80,7 +80,7 @@\n         class DistutilsLoader(importlib.abc.Loader):\n \n             def create_module(self, spec):\n-                return importlib.import_module('._distutils', 'setuptools')\n+                return importlib.import_module('setuptools._distutils')\n \n             def exec_module(self, module):\n                 pass\n", "issue": "SystemError: Parent module 'setuptools' not loaded, cannot perform relative import with setuptools 50\nAfter upgrading setuptools to 50.0 today, the environment fails to locate the entry points as it could not import distutils\r\n\r\n```\r\n$ python --version\r\nPython 3.5.1\r\n$ python -c \"import distutils\"\r\nTraceback (most recent call last):\r\n  File \"<string>\", line 1, in <module>\r\n  File \"<frozen importlib._bootstrap>\", line 969, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 958, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 666, in _load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 577, in module_from_spec\r\n  File \"/home/gchan/tmp/setuptools-python-3.5/lib/python3.5/site-packages/_distutils_hack/__init__.py\", line 82, in create_module\r\n    return importlib.import_module('._distutils', 'setuptools')\r\n  File \"/home/gchan/tmp/setuptools-python-3.5/lib64/python3.5/importlib/__init__.py\", line 126, in import_module\r\n    return _bootstrap._gcd_import(name[level:], package, level)\r\n  File \"<frozen importlib._bootstrap>\", line 981, in _gcd_import\r\n  File \"<frozen importlib._bootstrap>\", line 931, in _sanity_check\r\nSystemError: Parent module 'setuptools' not loaded, cannot perform relative import\r\n```\r\n\r\nThe issue could not be found in the python 3.8 environment.  \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', '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.abc\n        import importlib.util\n\n        class DistutilsLoader(importlib.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"}], "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.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        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"}]}