MCPcopy
hub / github.com/scrapy/scrapy / _import_file

Function _import_file

scrapy/commands/runspider.py:19–29  ·  view source on GitHub ↗
(filepath: str | PathLike[str])

Source from the content-addressed store, hash-verified

17
18
19def _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
32class Command(BaseRunSpiderCommand):

Callers 1

runMethod · 0.85

Calls 1

popMethod · 0.45

Tested by

no test coverage detected