Load modular command definitions.
(self)
| 808 | return self._cmd_to_command_sets.get(command_name) |
| 809 | |
| 810 | def _autoload_commands(self) -> None: |
| 811 | """Load modular command definitions.""" |
| 812 | # Search for all subclasses of CommandSet, instantiate them if they weren't already provided in the constructor |
| 813 | all_commandset_defs = CommandSet.__subclasses__() |
| 814 | existing_commandset_types = [type(command_set) for command_set in self._installed_command_sets] |
| 815 | |
| 816 | def load_commandset_by_type(commandset_types: list[type[CommandSet[Any]]]) -> None: |
| 817 | for cmdset_type in commandset_types: |
| 818 | # check if the type has sub-classes. We will only auto-load leaf class types. |
| 819 | subclasses = cmdset_type.__subclasses__() |
| 820 | if subclasses: |
| 821 | load_commandset_by_type(subclasses) |
| 822 | else: |
| 823 | init_sig = inspect.signature(cmdset_type.__init__) |
| 824 | if not ( |
| 825 | cmdset_type in existing_commandset_types |
| 826 | or len(init_sig.parameters) != 1 |
| 827 | or "self" not in init_sig.parameters |
| 828 | ): |
| 829 | cmdset = cmdset_type() |
| 830 | self.register_command_set(cmdset) |
| 831 | |
| 832 | load_commandset_by_type(all_commandset_defs) |
| 833 | |
| 834 | def register_command_set(self, cmdset: CommandSet[Any]) -> None: |
| 835 | """Installs a CommandSet, loading all commands defined in the CommandSet. |