MCPcopy
hub / github.com/scrapy/scrapy / execute

Function execute

scrapy/cmdline.py:169–215  ·  view source on GitHub ↗
(argv: list[str] | None = None, settings: Settings | None = None)

Source from the content-addressed store, hash-verified

167
168
169def execute(argv: list[str] | None = None, settings: Settings | None = None) -> None:
170 if argv is None:
171 argv = sys.argv
172
173 if settings is None:
174 settings = get_project_settings()
175 # set EDITOR from environment if available
176 try:
177 editor = os.environ["EDITOR"]
178 except KeyError:
179 pass
180 else:
181 settings["EDITOR"] = editor
182
183 inproject = inside_project()
184 cmds = _get_commands_dict(settings, inproject)
185 cmdname = _pop_command_name(argv)
186 if not cmdname:
187 _print_commands(settings, inproject)
188 sys.exit(0)
189 elif cmdname not in cmds:
190 _print_unknown_command(settings, cmdname, inproject)
191 sys.exit(2)
192
193 cmd = cmds[cmdname]
194 parser = ScrapyArgumentParser(
195 formatter_class=ScrapyHelpFormatter,
196 usage=f"scrapy {cmdname} {cmd.syntax()}",
197 conflict_handler="resolve",
198 description=cmd.long_desc(),
199 )
200 settings.setdict(cmd.default_settings, priority="command")
201 cmd.settings = settings
202 cmd.add_options(parser)
203 opts, args = parser.parse_known_args(args=argv[1:])
204 _run_print_help(parser, cmd.process_options, args, opts)
205
206 if cmd.requires_crawler_process:
207 if (
208 settings["TWISTED_REACTOR"] == _asyncio_reactor_path
209 and not settings.getbool("FORCE_CRAWLER_PROCESS")
210 ) or not settings.getbool("TWISTED_REACTOR_ENABLED"):
211 cmd.crawler_process = AsyncCrawlerProcess(settings)
212 else:
213 cmd.crawler_process = CrawlerProcess(settings)
214 _run_print_help(parser, _run_command, cmd, args, opts)
215 sys.exit(cmd.exitcode)
216
217
218def _run_command(cmd: ScrapyCommand, args: list[str], opts: argparse.Namespace) -> None:

Callers 2

__main__.pyFile · 0.90
cmdline.pyFile · 0.85

Calls 15

get_project_settingsFunction · 0.90
inside_projectFunction · 0.90
AsyncCrawlerProcessClass · 0.90
CrawlerProcessClass · 0.90
_get_commands_dictFunction · 0.85
_pop_command_nameFunction · 0.85
_print_commandsFunction · 0.85
_print_unknown_commandFunction · 0.85
_run_print_helpFunction · 0.85
setdictMethod · 0.80
syntaxMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…