From c8104dab1f370fec9d809de1a151b2dd40d00094 Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Thu, 24 Feb 2022 20:15:39 +0100 Subject: [PATCH] CLI: add `--test-profile` flag to `verdi setup/quicksetup` This new flag allows to designate a new profile that is created to be a test profile, which means it can be used to run the test suite. --- .github/config/profile.yaml | 1 + aiida/cmdline/commands/cmd_setup.py | 8 ++++++-- aiida/cmdline/params/options/commands/setup.py | 6 ++++++ aiida/manage/configuration/profile.py | 8 ++++++++ aiida/manage/tests/main.py | 4 +++- docs/source/reference/command_line.rst | 4 ++++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/config/profile.yaml b/.github/config/profile.yaml index 478b7d1233..84bdab3e91 100644 --- a/.github/config/profile.yaml +++ b/.github/config/profile.yaml @@ -18,3 +18,4 @@ broker_host: 127.0.0.1 broker_port: 5672 broker_virtual_host: '' repository: /tmp/test_repository_test_aiida/ +test_profile: true diff --git a/aiida/cmdline/commands/cmd_setup.py b/aiida/cmdline/commands/cmd_setup.py index 7795a7c616..5dc552517c 100644 --- a/aiida/cmdline/commands/cmd_setup.py +++ b/aiida/cmdline/commands/cmd_setup.py @@ -39,11 +39,12 @@ @options_setup.SETUP_BROKER_PORT() @options_setup.SETUP_BROKER_VIRTUAL_HOST() @options_setup.SETUP_REPOSITORY_URI() +@options_setup.SETUP_TEST_PROFILE() @options.CONFIG_FILE() def setup( non_interactive, profile: Profile, email, first_name, last_name, institution, db_engine, db_backend, db_host, db_port, db_name, db_username, db_password, broker_protocol, broker_username, broker_password, broker_host, - broker_port, broker_virtual_host, repository + broker_port, broker_virtual_host, repository, test_profile ): """Setup a new profile. @@ -74,6 +75,7 @@ def setup( 'broker_virtual_host': broker_virtual_host, } ) + profile.is_test_profile = test_profile config = get_config() @@ -142,12 +144,13 @@ def setup( @options_setup.QUICKSETUP_BROKER_PORT() @options_setup.QUICKSETUP_BROKER_VIRTUAL_HOST() @options_setup.QUICKSETUP_REPOSITORY_URI() +@options_setup.QUICKSETUP_TEST_PROFILE() @options.CONFIG_FILE() @click.pass_context def quicksetup( ctx, non_interactive, profile, email, first_name, last_name, institution, db_engine, db_backend, db_host, db_port, db_name, db_username, db_password, su_db_name, su_db_username, su_db_password, broker_protocol, broker_username, - broker_password, broker_host, broker_port, broker_virtual_host, repository + broker_password, broker_host, broker_port, broker_virtual_host, repository, test_profile ): """Setup a new profile in a fully automated fashion.""" # pylint: disable=too-many-arguments,too-many-locals @@ -202,5 +205,6 @@ def quicksetup( 'broker_port': broker_port, 'broker_virtual_host': broker_virtual_host, 'repository': repository, + 'test_profile': test_profile, } ctx.invoke(setup, **setup_parameters) diff --git a/aiida/cmdline/params/options/commands/setup.py b/aiida/cmdline/params/options/commands/setup.py index 14881ecf09..13132b95e7 100644 --- a/aiida/cmdline/params/options/commands/setup.py +++ b/aiida/cmdline/params/options/commands/setup.py @@ -360,3 +360,9 @@ def get_quicksetup_password(ctx, param, value): # pylint: disable=unused-argume contextual_default=get_repository_uri_default, cls=options.interactive.InteractiveOption ) + +SETUP_TEST_PROFILE = options.OverridableOption( + '--test-profile', is_flag=True, help='Designate the profile to be used for running the test suite only.' +) + +QUICKSETUP_TEST_PROFILE = SETUP_TEST_PROFILE.clone() diff --git a/aiida/manage/configuration/profile.py b/aiida/manage/configuration/profile.py index e46358e6b5..fc5e9d96b4 100644 --- a/aiida/manage/configuration/profile.py +++ b/aiida/manage/configuration/profile.py @@ -204,6 +204,14 @@ def is_test_profile(self) -> bool: # a test profile as that can unintentionally clear the database. return self._attributes.get(self.KEY_TEST_PROFILE, False) is True + @is_test_profile.setter + def is_test_profile(self, value: bool) -> None: + """Set whether the profile is a test profile. + + :param value: boolean indicating whether this profile is a test profile. + """ + self._attributes[self.KEY_TEST_PROFILE] = value + @property def repository_path(self) -> pathlib.Path: """Return the absolute path of the repository configured for this profile. diff --git a/aiida/manage/tests/main.py b/aiida/manage/tests/main.py index 450c8a0450..a1000e5884 100644 --- a/aiida/manage/tests/main.py +++ b/aiida/manage/tests/main.py @@ -52,7 +52,8 @@ 'broker_password': 'guest', 'broker_host': '127.0.0.1', 'broker_port': 5672, - 'broker_virtual_host': '' + 'broker_virtual_host': '', + 'test_profile': True, } @@ -251,6 +252,7 @@ def profile_dictionary(self): Used to set up AiiDA profile from self.profile_info dictionary. """ dictionary = { + 'test_profile': True, 'storage': { 'backend': self.profile_info.get('storage_backend'), 'config': { diff --git a/docs/source/reference/command_line.rst b/docs/source/reference/command_line.rst index 1a42cef636..7043a13b40 100644 --- a/docs/source/reference/command_line.rst +++ b/docs/source/reference/command_line.rst @@ -399,6 +399,8 @@ Below is a list with all available subcommands. --broker-virtual-host TEXT Name of the virtual host for the message broker without 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. --config FILEORURL Load option values from configuration file in yaml format (local path or URL). --help Show this message and exit. @@ -497,6 +499,8 @@ Below is a list with all available subcommands. --broker-virtual-host TEXT Name of the virtual host for the message broker without leading forward slash. [required] --repository DIRECTORY Absolute path to the file repository. + --test-profile Designate the profile to be used for running the test + suite only. --config FILEORURL Load option values from configuration file in yaml format (local path or URL). --help Show this message and exit.