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: Fix verdi config set when setting list option #6166

Merged
merged 1 commit into from
Nov 2, 2023
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
4 changes: 4 additions & 0 deletions aiida/cmdline/commands/cmd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def verdi_config_set(ctx, option, value, globally, append, remove):

List values are split by whitespace, e.g. "a b" becomes ["a", "b"].
"""
import typing

from aiida.common.exceptions import ConfigurationError
from aiida.manage.configuration import Config, Profile

Expand Down Expand Up @@ -146,6 +148,8 @@ def verdi_config_set(ctx, option, value, globally, append, remove):
value = list(set(current + [value]))
else:
value = [item for item in current if item != value]
elif option.valid_type == typing.List[str]:
value = [value]

# Set the specified option
try:
Expand Down
2 changes: 1 addition & 1 deletion aiida/manage/configuration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def validate_caching_identifier_pattern(cls, value: List[str]) -> List[str]:
return value


class GlobalOptionsSchema(ProfileOptionsSchema):
class GlobalOptionsSchema(ProfileOptionsSchema, defer_build=True):
"""Schema for the global options of an AiiDA instance."""
autofill__user__email: Optional[str] = Field(
None, description='Default user email to use when creating new profiles.'
Expand Down
16 changes: 10 additions & 6 deletions tests/cmdline/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ def test_config_set_option_no_profile(run_cli_command, empty_config):
assert str(config.get_option(option_name, scope=None)) == option_value


def test_config_set_option(run_cli_command, config_with_profile_factory):
@pytest.mark.parametrize('option_name, is_list', (
('storage.sandbox', False),
('caching.enabled_for', True),
))
def test_config_set_option(run_cli_command, config_with_profile_factory, option_name, is_list):
"""Test the `verdi config set` command when setting an option."""
config = config_with_profile_factory()

option_name = 'daemon.timeout'
option_values = [str(10), str(20)]

for option_value in option_values:
for option_value in ['value0', 'value1']:
options = ['config', 'set', option_name, option_value]
run_cli_command(cmd_verdi.verdi, options, use_subprocess=False)
assert str(config.get_option(option_name, scope=get_profile().name)) == option_value
if is_list:
assert config.get_option(option_name, scope=get_profile().name) == [option_value]
else:
assert str(config.get_option(option_name, scope=get_profile().name)) == option_value


def test_config_append_option(run_cli_command, config_with_profile_factory):
Expand Down
Loading