(filepath: str | PathLike[str])
| 17 | |
| 18 | |
| 19 | def _import_file(filepath: str | PathLike[str]) -> ModuleType: |
| 20 | abspath = Path(filepath).resolve() |
| 21 | if abspath.suffix not in {".py", ".pyw"}: |
| 22 | raise ValueError(f"Not a Python source file: {abspath}") |
| 23 | dirname = str(abspath.parent) |
| 24 | sys.path = [dirname, *sys.path] |
| 25 | try: |
| 26 | module = import_module(abspath.stem) |
| 27 | finally: |
| 28 | sys.path.pop(0) |
| 29 | return module |
| 30 | |
| 31 | |
| 32 | class Command(BaseRunSpiderCommand): |