Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sphuber committed Apr 27, 2024
1 parent 65f53e9 commit c0d9b66
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 37 deletions.
29 changes: 14 additions & 15 deletions docs/source/reference/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 14 additions & 15 deletions src/aiida/cmdline/commands/cmd_presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/aiida/cmdline/commands/cmd_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/aiida/manage/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 12 additions & 4 deletions tests/cmdline/commands/test_presto.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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

0 comments on commit c0d9b66

Please sign in to comment.