(self, args: list[str], opts: argparse.Namespace)
| 44 | return "Run the spider defined in the given file" |
| 45 | |
| 46 | def run(self, args: list[str], opts: argparse.Namespace) -> None: |
| 47 | if len(args) != 1: |
| 48 | raise UsageError |
| 49 | filename = Path(args[0]) |
| 50 | if not filename.exists(): |
| 51 | raise UsageError(f"File not found: {filename}\n") |
| 52 | try: |
| 53 | module = _import_file(filename) |
| 54 | except (ImportError, ValueError) as e: |
| 55 | raise UsageError(f"Unable to load {str(filename)!r}: {e}\n") from e |
| 56 | spclasses = list(iter_spider_classes(module)) |
| 57 | if not spclasses: |
| 58 | raise UsageError(f"No spider found in file: {filename}\n") |
| 59 | spidercls = spclasses.pop() |
| 60 | |
| 61 | assert self.crawler_process |
| 62 | self.crawler_process.crawl(spidercls, **opts.spargs) |
| 63 | self.crawler_process.start() |
| 64 | |
| 65 | if self.crawler_process.bootstrap_failed: |
| 66 | self.exitcode = 1 |
nothing calls this directly
no test coverage detected