def project_groups(self) -> Sequence[click.MultiCommand]: """Lazy property which loads all project command groups from the project and the plugins, then combines them with the built-in ones. Built-in commands can be overridden by plugins, which can be overridden by the project's cli.py. """ if not self._metadata: return [] built_in = [ catalog_cli, jupyter_cli, pipeline_cli, project_group, ] plugins = load_entry_points("project") try: project_cli = importlib.import_module( f"{self._metadata.package_name}.cli") # fail gracefully if cli.py does not exist except ModuleNotFoundError: # return only built-in commands and commands from plugins # (plugins can override built-in commands) return [*built_in, *plugins] # fail badly if cli.py exists, but has no `cli` in it if not hasattr(project_cli, "cli"): raise KedroCliError( f"Cannot load commands from {self._metadata.package_name}.cli") user_defined = project_cli.cli # type: ignore # return built-in commands, plugin commands and user defined commands # (overriding happens as follows built-in < plugins < cli.py) return [*built_in, *plugins, user_defined]
def _find_run_command(package_name): try: project_cli = importlib.import_module(f"{package_name}.cli") # fail gracefully if cli.py does not exist except ModuleNotFoundError as exc: if f"{package_name}.cli" not in str(exc): raise plugins = load_entry_points("project") run = _find_run_command_in_plugins(plugins) if plugins else None if run: # use run command from installed plugin if it exists return run # use run command from the framework project from kedro.framework.cli.project import run return run # fail badly if cli.py exists, but has no `cli` in it if not hasattr(project_cli, "cli"): raise KedroCliError(f"Cannot load commands from {package_name}.cli") return project_cli.run
def collect_line_magic(): """Interface function for collecting line magic functions from plugin entry points. """ return load_entry_points("line_magic")
def global_groups(self) -> Sequence[click.MultiCommand]: """Lazy property which loads all global command groups from plugins and combines them with the built-in ones (eventually overriding the built-in ones if they are redefined by plugins). """ return [cli, create_cli, *load_entry_points("global")]