prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Deprecated distutils bdist_wininst is going to be removed
  I proposed to remove the bdist_winstinst command from distutils in Python 3.9:
  
  * https://bugs.python.org/issue39541
  * https://discuss.python.org/t/remove-distutils-bdist-wininst-command/3115
  * https://github.com/python/cpython/pull/18329
  
  Problem: setuptools always uses it on all platforms at: setuptools/command/install_scripts.py, line 35:
  
  ```
    bw_cmd = self.get_finalized_command("bdist_wininst")
  ```
  
  See #857 which is a closed duplicated which proposed different options to fix the issue.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `setuptools/command/install_scripts.py`
  Content:
  ```
  1 from distutils import log
  2 import distutils.command.install_scripts as orig
  3 import os
  4 import sys
  5 
  6 from pkg_resources import Distribution, PathMetadata, ensure_directory
  7 
  8 
  9 class install_scripts(orig.install_scripts):
  10     """Do normal script install, plus any egg_info wrapper scripts"""
  11 
  12     def initialize_options(self):
  13         orig.install_scripts.initialize_options(self)
  14         self.no_ep = False
  15 
  16     def run(self):
  17         import setuptools.command.easy_install as ei
  18 
  19         self.run_command("egg_info")
  20         if self.distribution.scripts:
  21             orig.install_scripts.run(self)  # run first to set up self.outfiles
  22         else:
  23             self.outfiles = []
  24         if self.no_ep:
  25             # don't install entry point scripts into .egg file!
  26             return
  27 
  28         ei_cmd = self.get_finalized_command("egg_info")
  29         dist = Distribution(
  30             ei_cmd.egg_base, PathMetadata(ei_cmd.egg_base, ei_cmd.egg_info),
  31             ei_cmd.egg_name, ei_cmd.egg_version,
  32         )
  33         bs_cmd = self.get_finalized_command('build_scripts')
  34         exec_param = getattr(bs_cmd, 'executable', None)
  35         bw_cmd = self.get_finalized_command("bdist_wininst")
  36         is_wininst = getattr(bw_cmd, '_is_running', False)
  37         writer = ei.ScriptWriter
  38         if is_wininst:
  39             exec_param = "python.exe"
  40             writer = ei.WindowsScriptWriter
  41         if exec_param == sys.executable:
  42             # In case the path to the Python executable contains a space, wrap
  43             # it so it's not split up.
  44             exec_param = [exec_param]
  45         # resolve the writer to the environment
  46         writer = writer.best()
  47         cmd = writer.command_spec_class.best().from_param(exec_param)
  48         for args in writer.get_args(dist, cmd.as_header()):
  49             self.write_script(*args)
  50 
  51     def write_script(self, script_name, contents, mode="t", *ignored):
  52         """Write an executable file to the scripts directory"""
  53         from setuptools.command.easy_install import chmod, current_umask
  54 
  55         log.info("Installing %s script to %s", script_name, self.install_dir)
  56         target = os.path.join(self.install_dir, script_name)
  57         self.outfiles.append(target)
  58 
  59         mask = current_umask()
  60         if not self.dry_run:
  61             ensure_directory(target)
  62             f = open(target, "w" + mode)
  63             f.write(contents)
  64             f.close()
  65             chmod(target, 0o777 - mask)
  66
  ```
  --- 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/setuptools/command/install_scripts.py b/setuptools/command/install_scripts.py
  --- a/setuptools/command/install_scripts.py
  +++ b/setuptools/command/install_scripts.py
  @@ -32,8 +32,11 @@
           )
           bs_cmd = self.get_finalized_command('build_scripts')
           exec_param = getattr(bs_cmd, 'executable', None)
  -        bw_cmd = self.get_finalized_command("bdist_wininst")
  -        is_wininst = getattr(bw_cmd, '_is_running', False)
  +        try:
  +            bw_cmd = self.get_finalized_command("bdist_wininst")
  +            is_wininst = getattr(bw_cmd, '_is_running', False)
  +        except ImportError:
  +            is_wininst = False
           writer = ei.ScriptWriter
           if is_wininst:
               exec_param = "python.exe"
  
verification_info: {"golden_diff": "diff --git a/setuptools/command/install_scripts.py b/setuptools/command/install_scripts.py\n--- a/setuptools/command/install_scripts.py\n+++ b/setuptools/command/install_scripts.py\n@@ -32,8 +32,11 @@\n         )\n         bs_cmd = self.get_finalized_command('build_scripts')\n         exec_param = getattr(bs_cmd, 'executable', None)\n-        bw_cmd = self.get_finalized_command(\"bdist_wininst\")\n-        is_wininst = getattr(bw_cmd, '_is_running', False)\n+        try:\n+            bw_cmd = self.get_finalized_command(\"bdist_wininst\")\n+            is_wininst = getattr(bw_cmd, '_is_running', False)\n+        except ImportError:\n+            is_wininst = False\n         writer = ei.ScriptWriter\n         if is_wininst:\n             exec_param = \"python.exe\"\n", "issue": "Deprecated distutils bdist_wininst is going to be removed\nI proposed to remove the bdist_winstinst command from distutils in Python 3.9:\r\n\r\n* https://bugs.python.org/issue39541\r\n* https://discuss.python.org/t/remove-distutils-bdist-wininst-command/3115\r\n* https://github.com/python/cpython/pull/18329\r\n\r\nProblem: setuptools always uses it on all platforms at: setuptools/command/install_scripts.py, line 35:\r\n\r\n```\r\n  bw_cmd = self.get_finalized_command(\"bdist_wininst\")\r\n```\r\n\r\nSee #857 which is a closed duplicated which proposed different options to fix the issue.\n", "before_files": [{"content": "from distutils import log\nimport distutils.command.install_scripts as orig\nimport os\nimport sys\n\nfrom pkg_resources import Distribution, PathMetadata, ensure_directory\n\n\nclass install_scripts(orig.install_scripts):\n    \"\"\"Do normal script install, plus any egg_info wrapper scripts\"\"\"\n\n    def initialize_options(self):\n        orig.install_scripts.initialize_options(self)\n        self.no_ep = False\n\n    def run(self):\n        import setuptools.command.easy_install as ei\n\n        self.run_command(\"egg_info\")\n        if self.distribution.scripts:\n            orig.install_scripts.run(self)  # run first to set up self.outfiles\n        else:\n            self.outfiles = []\n        if self.no_ep:\n            # don't install entry point scripts into .egg file!\n            return\n\n        ei_cmd = self.get_finalized_command(\"egg_info\")\n        dist = Distribution(\n            ei_cmd.egg_base, PathMetadata(ei_cmd.egg_base, ei_cmd.egg_info),\n            ei_cmd.egg_name, ei_cmd.egg_version,\n        )\n        bs_cmd = self.get_finalized_command('build_scripts')\n        exec_param = getattr(bs_cmd, 'executable', None)\n        bw_cmd = self.get_finalized_command(\"bdist_wininst\")\n        is_wininst = getattr(bw_cmd, '_is_running', False)\n        writer = ei.ScriptWriter\n        if is_wininst:\n            exec_param = \"python.exe\"\n            writer = ei.WindowsScriptWriter\n        if exec_param == sys.executable:\n            # In case the path to the Python executable contains a space, wrap\n            # it so it's not split up.\n            exec_param = [exec_param]\n        # resolve the writer to the environment\n        writer = writer.best()\n        cmd = writer.command_spec_class.best().from_param(exec_param)\n        for args in writer.get_args(dist, cmd.as_header()):\n            self.write_script(*args)\n\n    def write_script(self, script_name, contents, mode=\"t\", *ignored):\n        \"\"\"Write an executable file to the scripts directory\"\"\"\n        from setuptools.command.easy_install import chmod, current_umask\n\n        log.info(\"Installing %s script to %s\", script_name, self.install_dir)\n        target = os.path.join(self.install_dir, script_name)\n        self.outfiles.append(target)\n\n        mask = current_umask()\n        if not self.dry_run:\n            ensure_directory(target)\n            f = open(target, \"w\" + mode)\n            f.write(contents)\n            f.close()\n            chmod(target, 0o777 - mask)\n", "path": "setuptools/command/install_scripts.py"}], "after_files": [{"content": "from distutils import log\nimport distutils.command.install_scripts as orig\nimport os\nimport sys\n\nfrom pkg_resources import Distribution, PathMetadata, ensure_directory\n\n\nclass install_scripts(orig.install_scripts):\n    \"\"\"Do normal script install, plus any egg_info wrapper scripts\"\"\"\n\n    def initialize_options(self):\n        orig.install_scripts.initialize_options(self)\n        self.no_ep = False\n\n    def run(self):\n        import setuptools.command.easy_install as ei\n\n        self.run_command(\"egg_info\")\n        if self.distribution.scripts:\n            orig.install_scripts.run(self)  # run first to set up self.outfiles\n        else:\n            self.outfiles = []\n        if self.no_ep:\n            # don't install entry point scripts into .egg file!\n            return\n\n        ei_cmd = self.get_finalized_command(\"egg_info\")\n        dist = Distribution(\n            ei_cmd.egg_base, PathMetadata(ei_cmd.egg_base, ei_cmd.egg_info),\n            ei_cmd.egg_name, ei_cmd.egg_version,\n        )\n        bs_cmd = self.get_finalized_command('build_scripts')\n        exec_param = getattr(bs_cmd, 'executable', None)\n        try:\n            bw_cmd = self.get_finalized_command(\"bdist_wininst\")\n            is_wininst = getattr(bw_cmd, '_is_running', False)\n        except ImportError:\n            is_wininst = False\n        writer = ei.ScriptWriter\n        if is_wininst:\n            exec_param = \"python.exe\"\n            writer = ei.WindowsScriptWriter\n        if exec_param == sys.executable:\n            # In case the path to the Python executable contains a space, wrap\n            # it so it's not split up.\n            exec_param = [exec_param]\n        # resolve the writer to the environment\n        writer = writer.best()\n        cmd = writer.command_spec_class.best().from_param(exec_param)\n        for args in writer.get_args(dist, cmd.as_header()):\n            self.write_script(*args)\n\n    def write_script(self, script_name, contents, mode=\"t\", *ignored):\n        \"\"\"Write an executable file to the scripts directory\"\"\"\n        from setuptools.command.easy_install import chmod, current_umask\n\n        log.info(\"Installing %s script to %s\", script_name, self.install_dir)\n        target = os.path.join(self.install_dir, script_name)\n        self.outfiles.append(target)\n\n        mask = current_umask()\n        if not self.dry_run:\n            ensure_directory(target)\n            f = open(target, \"w\" + mode)\n            f.write(contents)\n            f.close()\n            chmod(target, 0o777 - mask)\n", "path": "setuptools/command/install_scripts.py"}]}