MCPcopy Index your code
hub / github.com/python/cpython / _parse_args

Function _parse_args

Lib/test/libregrtest/cmdline.py:444–595  ·  view source on GitHub ↗
(args, **kwargs)

Source from the content-addressed store, hash-verified

442
443
444def _parse_args(args, **kwargs):
445 # Defaults
446 ns = Namespace()
447 for k, v in kwargs.items():
448 if not hasattr(ns, k):
449 raise TypeError('%r is an invalid keyword argument '
450 'for this function' % k)
451 setattr(ns, k, v)
452
453 parser = _create_parser()
454 # Issue #14191: argparse doesn't support "intermixed" positional and
455 # optional arguments. Use parse_known_args() as workaround.
456 ns.args = parser.parse_known_args(args=args, namespace=ns)[1]
457 for arg in ns.args:
458 if arg.startswith('-'):
459 parser.error("unrecognized arguments: %s" % arg)
460
461 if ns.timeout is not None:
462 # Support "--timeout=" (no value) so Makefile.pre.pre TESTTIMEOUT
463 # can be used by "make buildbottest" and "make test".
464 if ns.timeout != "":
465 try:
466 ns.timeout = float(ns.timeout)
467 except ValueError:
468 parser.error(f"invalid timeout value: {ns.timeout!r}")
469 else:
470 ns.timeout = None
471
472 # Continuous Integration (CI): common options for fast/slow CI modes
473 if ns.slow_ci or ns.fast_ci:
474 # Similar to options:
475 # -j0 --randomize --fail-env-changed --rerun --slowest --verbose3
476 if ns.use_mp is None:
477 ns.use_mp = 0
478 ns.randomize = True
479 ns.fail_env_changed = True
480 if ns.python is None:
481 ns.rerun = True
482 ns.print_slow = True
483 if not ns.verbose:
484 ns.verbose3 = True
485 else:
486 # --verbose has the priority over --verbose3
487 pass
488 else:
489 ns._add_python_opts = False
490
491 # --singleprocess overrides -jN option
492 if ns.single_process:
493 ns.use_mp = None
494
495 # When both --slow-ci and --fast-ci options are present,
496 # --slow-ci has the priority
497 if ns.slow_ci:
498 # Similar to: -u "all" --timeout=1200
499 if ns.use is None:
500 ns.use = []
501 ns.use[:0] = [('all', None)]

Callers 1

mainFunction · 0.70

Calls 10

parse_known_argsMethod · 0.80
NamespaceClass · 0.70
_create_parserFunction · 0.70
itemsMethod · 0.45
startswithMethod · 0.45
errorMethod · 0.45
splitMethod · 0.45
clearMethod · 0.45
popMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…