diff --git a/docs/source/reference/command_line.rst b/docs/source/reference/command_line.rst index 962282b502..9d427f993c 100644 --- a/docs/source/reference/command_line.rst +++ b/docs/source/reference/command_line.rst @@ -324,29 +324,28 @@ Below is a list with all available subcommands. Set up a new profile as automatically as possible. - This command aims making setting up a new profile as easy as possible. It intentionally - provides a limited amount of options to customize the profile and by default does not - require any options to be specified at all. For full control, please use the command - `verdi profile setup` instead. - - The main goal for this command is to setup a profile with minimal requirements to make - it easy to install AiiDA and get started as quickly as possible. Therefore, by default, - the created profile uses the `core.sqlite_dos` storage plugin which does not require any - services, such as PostgreSQL and RabbitMQ are not required. This _does_ mean, however, - that not all functionality of AiiDA is available, most notably running the daemon and - submitting processes to said daemon. + This command aims to make setting up a new profile as easy as possible. It intentionally + provides only a limited amount of options to customize the profile and by default does + not require any options to be specified at all. For full control, please use `verdi + profile setup`. + + After running `verdi presto` you can immediately start using AiiDA without additional + setup. The created profile uses the `core.sqlite_dos` storage plugin which does not + require any services, such as PostgreSQL and RabbitMQ. This _does_ mean, however, + that not all functionality of AiiDA is available, most notably running the daemon and + submitting processes to said daemon. The command performs the following actions: * Create a new profile that is set as the new default - * Create a default user for the profile (email can be configured through options) + * Create a default user for the profile (email can be configured through option the `--email` option) * Set up the localhost as a `Computer` and configure it * Set a number of configuration options with sensible defaults Options: - --profile-name TEXT The name of the profile. By default generates a name that does not - already exist and starts with `presto`. [default: (dynamic)] - --email TEXT The email of the default user. [default: aiida@localhost] + --profile-name TEXT Name of the profile. By default, a unique name starting with + `presto` is automatically generated. [default: (dynamic)] + --email TEXT Email of the default user. [default: aiida@localhost] --help Show this message and exit. diff --git a/src/aiida/cmdline/commands/cmd_presto.py b/src/aiida/cmdline/commands/cmd_presto.py index 9460dd154f..d0dfcedc6c 100644 --- a/src/aiida/cmdline/commands/cmd_presto.py +++ b/src/aiida/cmdline/commands/cmd_presto.py @@ -23,7 +23,7 @@ DEFAULT_PROFILE_NAME_PREFIX: str = 'presto' -def default_profile_name(): +def get_default_presto_profile_name(): from aiida.manage import get_config profile_names = get_config().profile_names @@ -44,36 +44,35 @@ def default_profile_name(): @verdi.command('presto') @click.option( '--profile-name', - default=lambda: default_profile_name(), + default=lambda: get_default_presto_profile_name(), show_default=True, - help='The name of the profile. By default generates a name that does not already exist and starts with ' - f'`{DEFAULT_PROFILE_NAME_PREFIX}`.', + help=f'Name of the profile. By default, a unique name starting with `{DEFAULT_PROFILE_NAME_PREFIX}` is ' + 'automatically generated.', ) @click.option( '--email', default=get_config_option('autofill.user.email') or 'aiida@localhost', show_default=True, - help='The email of the default user.', + help='Email of the default user.', ) @click.pass_context def verdi_presto(ctx, profile_name, email): """Set up a new profile as automatically as possible. - This command aims making setting up a new profile as easy as possible. It intentionally provides a limited amount of - options to customize the profile and by default does not require any options to be specified at all. For full - control, please use the command `verdi profile setup` instead. + This command aims to make setting up a new profile as easy as possible. It intentionally provides only a limited + amount of options to customize the profile and by default does not require any options to be specified at all. For + full control, please use `verdi profile setup`. - The main goal for this command is to setup a profile with minimal requirements to make it easy to install AiiDA and - get started as quickly as possible. Therefore, by default, the created profile uses the `core.sqlite_dos` storage - plugin which does not require any services, such as PostgreSQL and RabbitMQ are not required. This _does_ mean, - however, that not all functionality of AiiDA is available, most notably running the daemon and submitting processes - to said daemon. + After running `verdi presto` you can immediately start using AiiDA without additional setup. The created profile + uses the `core.sqlite_dos` storage plugin which does not require any services, such as PostgreSQL and RabbitMQ. + This _does_ mean, however, that not all functionality of AiiDA is available, most notably running the daemon and + submitting processes to said daemon. The command performs the following actions: \b * Create a new profile that is set as the new default - * Create a default user for the profile (email can be configured through options) + * Create a default user for the profile (email can be configured through option the `--email` option) * Set up the localhost as a `Computer` and configure it * Set a number of configuration options with sensible defaults @@ -113,8 +112,8 @@ def verdi_presto(ctx, profile_name, email): ctx.obj.config.set_default_profile(profile.name, overwrite=True) ctx.obj.config.store() - echo.echo_info(f'Loaded newly created profile `{profile.name}`.') load_profile(profile.name, allow_switch=True) + echo.echo_info(f'Loaded newly created profile `{profile.name}`.') filepath_scratch = pathlib.Path(ctx.obj.config.dirpath) / 'scratch' / profile.name diff --git a/src/aiida/cmdline/commands/cmd_profile.py b/src/aiida/cmdline/commands/cmd_profile.py index e95df78ed3..0d22b9025b 100644 --- a/src/aiida/cmdline/commands/cmd_profile.py +++ b/src/aiida/cmdline/commands/cmd_profile.py @@ -116,7 +116,10 @@ def profile_list(): echo.echo_report(f'configuration folder: {config.dirpath}') if not config.profiles: - echo.echo_warning('no profiles configured: run `verdi presto` to create one') + echo.echo_warning( + 'no profiles configured: Run `verdi presto` to automatically setup a profile using all defaults or use ' + '`verdi profile setup` for more control.' + ) else: sort = lambda profile: profile.name # noqa: E731 highlight = lambda profile: profile.name == config.default_profile_name # noqa: E731 diff --git a/src/aiida/manage/configuration/__init__.py b/src/aiida/manage/configuration/__init__.py index 1000af54bf..7227281507 100644 --- a/src/aiida/manage/configuration/__init__.py +++ b/src/aiida/manage/configuration/__init__.py @@ -188,8 +188,7 @@ def profile_context(profile: 'Profile' | str | None = None, allow_switch=False) manager = get_manager() current_profile = manager.get_profile() - manager.load_profile(profile, allow_switch) - yield profile + yield manager.load_profile(profile, allow_switch) if current_profile is None: manager.unload_profile() else: diff --git a/tests/cmdline/commands/test_presto.py b/tests/cmdline/commands/test_presto.py index efe7bf8bbe..dae90ed07f 100644 --- a/tests/cmdline/commands/test_presto.py +++ b/tests/cmdline/commands/test_presto.py @@ -1,8 +1,10 @@ """Tests for ``verdi presto``.""" import pytest -from aiida.cmdline.commands.cmd_presto import default_profile_name, verdi_presto +from aiida.cmdline.commands.cmd_presto import get_default_presto_profile_name, verdi_presto +from aiida.manage.configuration import profile_context from aiida.manage.configuration.config import Config +from aiida.orm import Computer @pytest.mark.parametrize( @@ -15,17 +17,23 @@ (['presto', 'main', 'presto-2', 'sqlite'], 'presto-3'), ), ) -def test_default_profile_name(monkeypatch, profile_names, expected): +def test_get_default_presto_profile_name(monkeypatch, profile_names, expected): """Test the dynamic default profile function.""" def get_profile_names(self): return profile_names monkeypatch.setattr(Config, 'profile_names', property(get_profile_names)) - assert default_profile_name() == expected + assert get_default_presto_profile_name() == expected +@pytest.mark.usefixtures('aiida_config_tmp') def test_presto(run_cli_command): """Test the ``verdi presto``.""" - result = run_cli_command(verdi_presto, use_subprocess=False) + result = run_cli_command(verdi_presto) assert 'Created new profile `presto`.' in result.output + + with profile_context('presto', allow_switch=True) as profile: + assert profile.name == 'presto' + localhost = Computer.collection.get(label='localhost') + assert localhost.is_configured