Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: verdi profile setdefault to set-default #6426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions docs/source/reference/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,13 @@ Below is a list with all available subcommands.
--help Show this message and exit.

Commands:
delete Delete one or more profiles.
list Display a list of all available profiles.
setdefault Set a profile as the default one.
setup Set up a new profile.
show Show details for a profile.
delete Delete one or more profiles.
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 (use `verdi profile set-
default`).
setup Set up a new profile.
show Show details for a profile.


.. _reference:command-line:verdi-quicksetup:
Expand Down
17 changes: 14 additions & 3 deletions src/aiida/cmdline/commands/cmd_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
echo.echo_success(f'Created new profile `{profile.name}`.')

if set_as_default:
ctx.invoke(profile_setdefault, profile=profile)
ctx.invoke(profile_set_default, profile=profile)

Check warning on line 81 in src/aiida/cmdline/commands/cmd_profile.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/cmdline/commands/cmd_profile.py#L81

Added line #L81 was not covered by tests


@verdi_profile.group(
Expand Down Expand Up @@ -147,10 +147,21 @@
echo.echo_dictionary(config, fmt='yaml')


@verdi_profile.command('setdefault')
@verdi_profile.command('setdefault', deprecated='Please use `verdi profile set-default` instead.')
@arguments.PROFILE(required=True, default=None)
def profile_setdefault(profile):
"""Set a profile as the default one."""
"""Set a profile as the default profile (use `verdi profile set-default`)."""
_profile_set_default(profile)

Check warning on line 154 in src/aiida/cmdline/commands/cmd_profile.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/cmdline/commands/cmd_profile.py#L154

Added line #L154 was not covered by tests


@verdi_profile.command('set-default')
@arguments.PROFILE(required=True, default=None)
def profile_set_default(profile):
"""Set a profile as the default profile."""
_profile_set_default(profile)

Check warning on line 161 in src/aiida/cmdline/commands/cmd_profile.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/cmdline/commands/cmd_profile.py#L161

Added line #L161 was not covered by tests


def _profile_set_default(profile):
try:
config = get_config()
except (exceptions.MissingConfigurationError, exceptions.ConfigurationError) as exception:
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/cmdline/commands/cmd_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def user_list():
@click.option(
'--set-default',
prompt='Set as default?',
help='Set the user as the default user for the current profile.',
help='Set the user as the default user.',
is_flag=True,
cls=options.interactive.InteractiveOption,
contextual_default=lambda ctx: ctx.params['user'].is_default,
Expand Down
18 changes: 16 additions & 2 deletions tests/cmdline/commands/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _factory(**kwargs):

@pytest.mark.parametrize(
'command',
(cmd_profile.profile_list, cmd_profile.profile_setdefault, cmd_profile.profile_delete, cmd_profile.profile_show),
(cmd_profile.profile_list, cmd_profile.profile_set_default, cmd_profile.profile_delete, cmd_profile.profile_show),
)
def test_help(run_cli_command, command):
"""Tests help text for all ``verdi profile`` commands."""
Expand All @@ -73,7 +73,21 @@ def test_list(run_cli_command, mock_profiles):
def test_setdefault(run_cli_command, mock_profiles):
"""Test the ``verdi profile setdefault`` command."""
profile_list = mock_profiles()
run_cli_command(cmd_profile.profile_setdefault, [profile_list[1]], use_subprocess=False)
setdefault_result = run_cli_command(cmd_profile.profile_setdefault, [profile_list[1]], use_subprocess=False)
result = run_cli_command(cmd_profile.profile_list, use_subprocess=False)

assert 'Report: configuration folder:' in result.output
assert f'* {profile_list[1]}' in result.output

# test if deprecation warning is printed
assert 'Deprecated:' in setdefault_result.output
assert 'Deprecated:' in setdefault_result.stderr


def test_set_default(run_cli_command, mock_profiles):
"""Test the ``verdi profile set-default`` command."""
profile_list = mock_profiles()
run_cli_command(cmd_profile.profile_set_default, [profile_list[1]], use_subprocess=False)
result = run_cli_command(cmd_profile.profile_list, use_subprocess=False)

assert 'Report: configuration folder:' in result.output
Expand Down
Loading