From e5768f6943454564ff2e2627d0a5b351ff71c9fd Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Wed, 20 Nov 2024 01:03:40 +0100 Subject: [PATCH] Explicitly load and set configuration folder in the main module level --- src/aiida/__init__.py | 3 +++ src/aiida/manage/configuration/settings.py | 5 ----- tests/manage/test_caching_config.py | 8 +++++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/aiida/__init__.py b/src/aiida/__init__.py index 743c5009ab..281047e563 100644 --- a/src/aiida/__init__.py +++ b/src/aiida/__init__.py @@ -21,6 +21,7 @@ from aiida.common.log import configure_logging # noqa: F401 from aiida.manage.configuration import get_config_option, get_profile, load_profile, profile_context # noqa: F401 +from aiida.manage.configuration.settings import AiiDAConfigPathResolver __copyright__ = ( 'Copyright (c), This file is part of the AiiDA platform. ' @@ -35,6 +36,8 @@ ) __paper_short__ = 'S. P. Huber et al., Scientific Data 7, 300 (2020).' +# Initialize the configuration directory settings +AiiDAConfigPathResolver.set_configuration_directory() def get_strict_version(): """Return a distutils StrictVersion instance with the current distribution version diff --git a/src/aiida/manage/configuration/settings.py b/src/aiida/manage/configuration/settings.py index 22be2be4ea..13d33fd03e 100644 --- a/src/aiida/manage/configuration/settings.py +++ b/src/aiida/manage/configuration/settings.py @@ -136,8 +136,3 @@ def _get_configuration_directory_from_envvar() -> pathlib.Path: break return dirpath_config or default_dirpath_config - - -# XXX: Can I move this to aiida.__init__??? -# Initialize the configuration directory settings -AiiDAConfigPathResolver.set_configuration_directory() diff --git a/tests/manage/test_caching_config.py b/tests/manage/test_caching_config.py index 5f3b5126eb..21cb504c2b 100644 --- a/tests/manage/test_caching_config.py +++ b/tests/manage/test_caching_config.py @@ -45,7 +45,9 @@ def test_merge_deprecated_yaml(tmp_path): """ from aiida.common.warnings import AiidaDeprecationWarning from aiida.manage import configuration, get_manager - from aiida.manage.configuration import get_config_option, load_profile, settings + from aiida.manage.configuration import get_config_option, load_profile + from aiida.manage.configuration.settings import AiiDAConfigPathResolver + # Store the current configuration instance and config directory path current_config = configuration.CONFIG @@ -57,7 +59,7 @@ def test_merge_deprecated_yaml(tmp_path): configuration.CONFIG = None # Create a temporary folder, set it as the current config directory path - settings.set_configuration_directory(pathlib.Path(tmp_path)) + AiiDAConfigPathResolver.set_configuration_directory(pathlib.Path(tmp_path)) config_dictionary = json.loads( pathlib.Path(__file__) .parent.joinpath('configuration/migrations/test_samples/reference/6.json') @@ -86,7 +88,7 @@ def test_merge_deprecated_yaml(tmp_path): # Reset the config folder path and the config instance. Note this will always be executed after the yield no # matter what happened in the test that used this fixture. get_manager().unload_profile() - settings.set_configuration_directory(current_config_path) + AiiDAConfigPathResolver.set_configuration_directory(current_config_path) configuration.CONFIG = current_config load_profile(current_profile_name)