From 4131a25ae9eccd72d076315a3179f5b9e9f27b30 Mon Sep 17 00:00:00 2001 From: superstar54 Date: Tue, 7 Oct 2025 11:12:06 +0200 Subject: [PATCH 1/3] cli: make top-level `verdi` pluginable via entry points - Declare the `verdi` Click group with `cls=Pluginable` and `entry_point_group="aiida.cmdline.verdi"`. - Enables external packages to contribute first-level commands (e.g. `verdi gui`, `verdi restapi`) without touching aiida-core. - Mirrors the same pattern used by `verdi data`. --- docs/source/reference/command_line.rst | 16 ++++++---------- src/aiida/cmdline/commands/cmd_verdi.py | 6 ++++-- src/aiida/cmdline/utils/pluginable.py | 2 +- src/aiida/plugins/entry_point.py | 1 + 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/docs/source/reference/command_line.rst b/docs/source/reference/command_line.rst index 1629f43a2e..2a85592330 100644 --- a/docs/source/reference/command_line.rst +++ b/docs/source/reference/command_line.rst @@ -80,8 +80,7 @@ Below is a list with all available subcommands. list List the available codes. relabel Relabel a code. reveal Reveal one or more hidden codes in `verdi code list`. - setup Setup a new code (use `verdi code create`). (DEPRECATED: Please use `verdi - code create` instead.) + setup (Deprecated) Setup a new code (use `verdi code create`). show Display detailed information for a code. test Run tests for the given code to check whether it is usable. @@ -402,8 +401,7 @@ Below is a list with all available subcommands. dump Dump all data in an AiiDA profile's storage to disk. list Display a list of all available profiles. set-default Set a profile as the default profile. - setdefault Set a profile as the default profile. (DEPRECATED: Please use `verdi - profile set-default` instead.) + setdefault (Deprecated) Set a profile as the default profile. setup Set up a new profile. show Show details for a profile. @@ -417,9 +415,7 @@ Below is a list with all available subcommands. Usage: [OPTIONS] - Setup a new profile in a fully automated fashion. (DEPRECATED: This command is - deprecated. For a fully automated alternative, use `verdi presto --use-postgres` - instead. For full control, use `verdi profile setup core.psql_dos`.) + (Deprecated) Setup a new profile in a fully automated fashion. Options: -n, --non-interactive / -I, --interactive @@ -457,7 +453,7 @@ Below is a list with all available subcommands. --broker-host HOSTNAME Hostname for the message broker. [default: 127.0.0.1] --broker-port INTEGER Port for the message broker. [default: 5672] --broker-virtual-host TEXT Name of the virtual host for the message broker without - leading forward slash. [default: ""] + leading forward slash. --repository DIRECTORY Absolute path to the file repository. --test-profile Designate the profile to be used for running the test suite only. @@ -523,10 +519,10 @@ Below is a list with all available subcommands. Usage: [OPTIONS] - Setup a new profile (use `verdi profile setup`). + (Deprecated) Setup a new profile (use `verdi profile setup`). This method assumes that an empty PSQL database has been created and that the database - user has been created. (DEPRECATED: Please use `verdi profile setup` instead.) + user has been created. Options: -n, --non-interactive / -I, --interactive diff --git a/src/aiida/cmdline/commands/cmd_verdi.py b/src/aiida/cmdline/commands/cmd_verdi.py index c67b4b017a..8fb264ffe3 100644 --- a/src/aiida/cmdline/commands/cmd_verdi.py +++ b/src/aiida/cmdline/commands/cmd_verdi.py @@ -12,12 +12,14 @@ from aiida import __version__ -from ..groups import VerdiCommandGroup from ..params import options, types +from ..utils.pluginable import Pluginable # Pass the version explicitly to ``version_option`` otherwise editable installs can show the wrong version number -@click.group(cls=VerdiCommandGroup, context_settings={'help_option_names': ['--help', '-h']}) +@click.group( + cls=Pluginable, entry_point_group='aiida.cmdline.verdi', context_settings={'help_option_names': ['--help', '-h']} +) @options.PROFILE(type=types.ProfileParamType(load_profile=True), expose_value=False) @options.VERBOSITY() @click.version_option(__version__, package_name='aiida_core', message='AiiDA version %(version)s') diff --git a/src/aiida/cmdline/utils/pluginable.py b/src/aiida/cmdline/utils/pluginable.py index ce7925ce05..c909cc3e3c 100644 --- a/src/aiida/cmdline/utils/pluginable.py +++ b/src/aiida/cmdline/utils/pluginable.py @@ -29,7 +29,7 @@ def list_commands(self, ctx): if not self._exclude_external_plugins: subcommands.extend(get_entry_point_names(self._entry_point_group)) - return subcommands + return sorted(subcommands) def get_command(self, ctx, name): """Try to load a subcommand from entry points, else defer to super.""" diff --git a/src/aiida/plugins/entry_point.py b/src/aiida/plugins/entry_point.py index 7ec26a4c34..055bb1fa36 100644 --- a/src/aiida/plugins/entry_point.py +++ b/src/aiida/plugins/entry_point.py @@ -87,6 +87,7 @@ class EntryPointFormat(enum.Enum): 'aiida.cmdline.computer.configure': 'aiida.cmdline.computer.configure', 'aiida.cmdline.data': 'aiida.cmdline.data', 'aiida.cmdline.data.structure.import': 'aiida.cmdline.data.structure.import', + 'aiida.cmdline.verdi': 'aiida.cmdline.verdi', 'aiida.data': 'aiida.orm.nodes.data', 'aiida.groups': 'aiida.orm.groups', 'aiida.orm': 'aiida.orm', From 6e634506e397e26ccdc7082082109d224a2ee055 Mon Sep 17 00:00:00 2001 From: superstar54 Date: Tue, 7 Oct 2025 12:16:30 +0200 Subject: [PATCH 2/3] Fix wrong import in conftest --- tests/conftest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 8915b24173..d449bbbab0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -765,8 +765,7 @@ def run_cli_command_runner(command, parameters, user_input, initialize_ctx_obj, """Run CLI command through ``click.testing.CliRunner``.""" from click.testing import CliRunner - from aiida.cmdline.commands.cmd_verdi import VerdiCommandGroup - from aiida.cmdline.groups.verdi import LazyVerdiObjAttributeDict + from aiida.cmdline.groups.verdi import LazyVerdiObjAttributeDict, VerdiCommandGroup if initialize_ctx_obj: config = get_config() From 746d10e3cd049ad0fde5d7b1b946121d55594c5a Mon Sep 17 00:00:00 2001 From: superstar54 Date: Tue, 7 Oct 2025 19:21:10 +0200 Subject: [PATCH 3/3] Revert doc --- docs/source/reference/command_line.rst | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/source/reference/command_line.rst b/docs/source/reference/command_line.rst index 2a85592330..1629f43a2e 100644 --- a/docs/source/reference/command_line.rst +++ b/docs/source/reference/command_line.rst @@ -80,7 +80,8 @@ Below is a list with all available subcommands. list List the available codes. relabel Relabel a code. reveal Reveal one or more hidden codes in `verdi code list`. - setup (Deprecated) Setup a new code (use `verdi code create`). + setup Setup a new code (use `verdi code create`). (DEPRECATED: Please use `verdi + code create` instead.) show Display detailed information for a code. test Run tests for the given code to check whether it is usable. @@ -401,7 +402,8 @@ Below is a list with all available subcommands. dump Dump all data in an AiiDA profile's storage to disk. list Display a list of all available profiles. set-default Set a profile as the default profile. - setdefault (Deprecated) Set a profile as the default profile. + setdefault Set a profile as the default profile. (DEPRECATED: Please use `verdi + profile set-default` instead.) setup Set up a new profile. show Show details for a profile. @@ -415,7 +417,9 @@ Below is a list with all available subcommands. Usage: [OPTIONS] - (Deprecated) Setup a new profile in a fully automated fashion. + Setup a new profile in a fully automated fashion. (DEPRECATED: This command is + deprecated. For a fully automated alternative, use `verdi presto --use-postgres` + instead. For full control, use `verdi profile setup core.psql_dos`.) Options: -n, --non-interactive / -I, --interactive @@ -453,7 +457,7 @@ Below is a list with all available subcommands. --broker-host HOSTNAME Hostname for the message broker. [default: 127.0.0.1] --broker-port INTEGER Port for the message broker. [default: 5672] --broker-virtual-host TEXT Name of the virtual host for the message broker without - leading forward slash. + leading forward slash. [default: ""] --repository DIRECTORY Absolute path to the file repository. --test-profile Designate the profile to be used for running the test suite only. @@ -519,10 +523,10 @@ Below is a list with all available subcommands. Usage: [OPTIONS] - (Deprecated) Setup a new profile (use `verdi profile setup`). + Setup a new profile (use `verdi profile setup`). This method assumes that an empty PSQL database has been created and that the database - user has been created. + user has been created. (DEPRECATED: Please use `verdi profile setup` instead.) Options: -n, --non-interactive / -I, --interactive