MCPcopy Create free account
hub / github.com/ipython/traitlets / initialize_subcommand

Method initialize_subcommand

traitlets/config/application.py:700–722  ·  view source on GitHub ↗

Initialize a subcommand with argv.

(self, subc: str, argv: ArgvType = None)

Source from the content-addressed store, hash-verified

698
699 @catch_config_error
700 def initialize_subcommand(self, subc: str, argv: ArgvType = None) -> None:
701 """Initialize a subcommand with argv."""
702 val = self.subcommands.get(subc)
703 assert val is not None
704 subapp, _ = val
705
706 if isinstance(subapp, str):
707 subapp = import_item(subapp)
708
709 # Cannot issubclass() on a non-type (SOhttp://stackoverflow.com/questions/8692430)
710 if isinstance(subapp, type) and issubclass(subapp, Application):
711 # Clear existing instances before...
712 self.__class__.clear_instance()
713 # instantiating subapp...
714 self.subapp = subapp.instance(parent=self)
715 elif callable(subapp):
716 # or ask factory to create it...
717 self.subapp = subapp(self)
718 else:
719 raise AssertionError("Invalid mappings for subcommand '%s'!" % subc)
720
721 # ... and finally initialize subapp.
722 self.subapp.initialize(argv)
723
724 def flatten_flags(self) -> tuple[dict[str, t.Any], dict[str, t.Any]]:
725 """Flatten flags and aliases for loaders, so cl-args override as expected.

Callers 1

parse_command_lineMethod · 0.95

Calls 5

import_itemFunction · 0.85
clear_instanceMethod · 0.80
instanceMethod · 0.80
getMethod · 0.45
initializeMethod · 0.45

Tested by

no test coverage detected