prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Allow run pyw scripts
  scrapy/commands/runspider.py check for Python script source but it fails to allow .pyw files.
  Check at row 14 is:
  `    if fext != '.py':`
  but it should be:
  `    if fext != '.py' and fext != '.pyw':`
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `scrapy/commands/runspider.py`
  Content:
  ```
  1 import sys
  2 import os
  3 from importlib import import_module
  4 
  5 from scrapy.utils.spider import iter_spider_classes
  6 from scrapy.exceptions import UsageError
  7 from scrapy.commands import BaseRunSpiderCommand
  8 
  9 
  10 def _import_file(filepath):
  11     abspath = os.path.abspath(filepath)
  12     dirname, file = os.path.split(abspath)
  13     fname, fext = os.path.splitext(file)
  14     if fext != '.py':
  15         raise ValueError(f"Not a Python source file: {abspath}")
  16     if dirname:
  17         sys.path = [dirname] + sys.path
  18     try:
  19         module = import_module(fname)
  20     finally:
  21         if dirname:
  22             sys.path.pop(0)
  23     return module
  24 
  25 
  26 class Command(BaseRunSpiderCommand):
  27 
  28     requires_project = False
  29     default_settings = {'SPIDER_LOADER_WARN_ONLY': True}
  30 
  31     def syntax(self):
  32         return "[options] <spider_file>"
  33 
  34     def short_desc(self):
  35         return "Run a self-contained spider (without creating a project)"
  36 
  37     def long_desc(self):
  38         return "Run the spider defined in the given file"
  39 
  40     def run(self, args, opts):
  41         if len(args) != 1:
  42             raise UsageError()
  43         filename = args[0]
  44         if not os.path.exists(filename):
  45             raise UsageError(f"File not found: {filename}\n")
  46         try:
  47             module = _import_file(filename)
  48         except (ImportError, ValueError) as e:
  49             raise UsageError(f"Unable to load {filename!r}: {e}\n")
  50         spclasses = list(iter_spider_classes(module))
  51         if not spclasses:
  52             raise UsageError(f"No spider found in file: {filename}\n")
  53         spidercls = spclasses.pop()
  54 
  55         self.crawler_process.crawl(spidercls, **opts.spargs)
  56         self.crawler_process.start()
  57 
  58         if self.crawler_process.bootstrap_failed:
  59             self.exitcode = 1
  60
  ```
  --- 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/scrapy/commands/runspider.py b/scrapy/commands/runspider.py
  --- a/scrapy/commands/runspider.py
  +++ b/scrapy/commands/runspider.py
  @@ -11,7 +11,7 @@
       abspath = os.path.abspath(filepath)
       dirname, file = os.path.split(abspath)
       fname, fext = os.path.splitext(file)
  -    if fext != '.py':
  +    if fext not in ('.py', '.pyw'):
           raise ValueError(f"Not a Python source file: {abspath}")
       if dirname:
           sys.path = [dirname] + sys.path
  
verification_info: {"golden_diff": "diff --git a/scrapy/commands/runspider.py b/scrapy/commands/runspider.py\n--- a/scrapy/commands/runspider.py\n+++ b/scrapy/commands/runspider.py\n@@ -11,7 +11,7 @@\n     abspath = os.path.abspath(filepath)\n     dirname, file = os.path.split(abspath)\n     fname, fext = os.path.splitext(file)\n-    if fext != '.py':\n+    if fext not in ('.py', '.pyw'):\n         raise ValueError(f\"Not a Python source file: {abspath}\")\n     if dirname:\n         sys.path = [dirname] + sys.path\n", "issue": "Allow run pyw scripts\nscrapy/commands/runspider.py check for Python script source but it fails to allow .pyw files.\r\nCheck at row 14 is:\r\n`    if fext != '.py':`\r\nbut it should be:\r\n`    if fext != '.py' and fext != '.pyw':`\n", "before_files": [{"content": "import sys\nimport os\nfrom importlib import import_module\n\nfrom scrapy.utils.spider import iter_spider_classes\nfrom scrapy.exceptions import UsageError\nfrom scrapy.commands import BaseRunSpiderCommand\n\n\ndef _import_file(filepath):\n    abspath = os.path.abspath(filepath)\n    dirname, file = os.path.split(abspath)\n    fname, fext = os.path.splitext(file)\n    if fext != '.py':\n        raise ValueError(f\"Not a Python source file: {abspath}\")\n    if dirname:\n        sys.path = [dirname] + sys.path\n    try:\n        module = import_module(fname)\n    finally:\n        if dirname:\n            sys.path.pop(0)\n    return module\n\n\nclass Command(BaseRunSpiderCommand):\n\n    requires_project = False\n    default_settings = {'SPIDER_LOADER_WARN_ONLY': True}\n\n    def syntax(self):\n        return \"[options] <spider_file>\"\n\n    def short_desc(self):\n        return \"Run a self-contained spider (without creating a project)\"\n\n    def long_desc(self):\n        return \"Run the spider defined in the given file\"\n\n    def run(self, args, opts):\n        if len(args) != 1:\n            raise UsageError()\n        filename = args[0]\n        if not os.path.exists(filename):\n            raise UsageError(f\"File not found: {filename}\\n\")\n        try:\n            module = _import_file(filename)\n        except (ImportError, ValueError) as e:\n            raise UsageError(f\"Unable to load {filename!r}: {e}\\n\")\n        spclasses = list(iter_spider_classes(module))\n        if not spclasses:\n            raise UsageError(f\"No spider found in file: {filename}\\n\")\n        spidercls = spclasses.pop()\n\n        self.crawler_process.crawl(spidercls, **opts.spargs)\n        self.crawler_process.start()\n\n        if self.crawler_process.bootstrap_failed:\n            self.exitcode = 1\n", "path": "scrapy/commands/runspider.py"}], "after_files": [{"content": "import sys\nimport os\nfrom importlib import import_module\n\nfrom scrapy.utils.spider import iter_spider_classes\nfrom scrapy.exceptions import UsageError\nfrom scrapy.commands import BaseRunSpiderCommand\n\n\ndef _import_file(filepath):\n    abspath = os.path.abspath(filepath)\n    dirname, file = os.path.split(abspath)\n    fname, fext = os.path.splitext(file)\n    if fext not in ('.py', '.pyw'):\n        raise ValueError(f\"Not a Python source file: {abspath}\")\n    if dirname:\n        sys.path = [dirname] + sys.path\n    try:\n        module = import_module(fname)\n    finally:\n        if dirname:\n            sys.path.pop(0)\n    return module\n\n\nclass Command(BaseRunSpiderCommand):\n\n    requires_project = False\n    default_settings = {'SPIDER_LOADER_WARN_ONLY': True}\n\n    def syntax(self):\n        return \"[options] <spider_file>\"\n\n    def short_desc(self):\n        return \"Run a self-contained spider (without creating a project)\"\n\n    def long_desc(self):\n        return \"Run the spider defined in the given file\"\n\n    def run(self, args, opts):\n        if len(args) != 1:\n            raise UsageError()\n        filename = args[0]\n        if not os.path.exists(filename):\n            raise UsageError(f\"File not found: {filename}\\n\")\n        try:\n            module = _import_file(filename)\n        except (ImportError, ValueError) as e:\n            raise UsageError(f\"Unable to load {filename!r}: {e}\\n\")\n        spclasses = list(iter_spider_classes(module))\n        if not spclasses:\n            raise UsageError(f\"No spider found in file: {filename}\\n\")\n        spidercls = spclasses.pop()\n\n        self.crawler_process.crawl(spidercls, **opts.spargs)\n        self.crawler_process.start()\n\n        if self.crawler_process.bootstrap_failed:\n            self.exitcode = 1\n", "path": "scrapy/commands/runspider.py"}]}