Skip to content

Commit

Permalink
Rename global AIIDA_CONFIG_FOLDER as lowercase var
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Nov 15, 2024
1 parent 2663d7e commit 418cc2a
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/aiida/cmdline/commands/cmd_presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def detect_postgres_config(
"""
import secrets

from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER
from aiida.manage.configuration.settings import glb_aiida_config_folder
from aiida.manage.external.postgres import Postgres

dbinfo = {
Expand Down Expand Up @@ -98,7 +98,7 @@ def detect_postgres_config(
'database_name': database_name,
'database_username': database_username,
'database_password': database_password,
'repository_uri': f'file://{AIIDA_CONFIG_FOLDER / "repository" / profile_name}',
'repository_uri': f'file://{glb_aiida_config_folder / "repository" / profile_name}',
}


Expand Down
4 changes: 2 additions & 2 deletions src/aiida/cmdline/commands/cmd_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def profile_list():
# This can happen for a fresh install and the `verdi setup` has not yet been run. In this case it is still nice
# to be able to see the configuration directory, for instance for those who have set `AIIDA_PATH`. This way
# they can at least verify that it is correctly set.
from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER
from aiida.manage.configuration.settings import glb_aiida_config_folder

echo.echo_report(f'configuration folder: {AIIDA_CONFIG_FOLDER}')
echo.echo_report(f'configuration folder: {glb_aiida_config_folder}')
echo.echo_critical(str(exception))
else:
echo.echo_report(f'configuration folder: {config.dirpath}')
Expand Down
4 changes: 2 additions & 2 deletions src/aiida/cmdline/commands/cmd_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def verdi_status(print_traceback, no_rmq):
from aiida.common.docs import URL_NO_BROKER
from aiida.common.exceptions import ConfigurationError
from aiida.engine.daemon.client import DaemonException, DaemonNotRunningException
from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER
from aiida.manage.configuration.settings import glb_aiida_config_folder
from aiida.manage.manager import get_manager

exit_code = ExitCode.SUCCESS

print_status(ServiceStatus.UP, 'version', f'AiiDA v{__version__}')
print_status(ServiceStatus.UP, 'config', AIIDA_CONFIG_FOLDER)
print_status(ServiceStatus.UP, 'config', glb_aiida_config_folder)

manager = get_manager()

Expand Down
4 changes: 2 additions & 2 deletions src/aiida/cmdline/params/options/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def get_repository_uri_default(ctx):
"""
import os

from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER
from aiida.manage.configuration.settings import glb_aiida_config_folder

validate_profile_parameter(ctx)

return os.path.join(AIIDA_CONFIG_FOLDER, 'repository', ctx.params['profile'].name)
return os.path.join(glb_aiida_config_folder, 'repository', ctx.params['profile'].name)


def get_quicksetup_repository_uri(ctx, param, value):
Expand Down
4 changes: 2 additions & 2 deletions src/aiida/manage/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@

def get_config_path():
"""Returns path to .aiida configuration directory."""
from .settings import AIIDA_CONFIG_FOLDER, DEFAULT_CONFIG_FILE_NAME
from .settings import glb_aiida_config_folder, DEFAULT_CONFIG_FILE_NAME

return os.path.join(AIIDA_CONFIG_FOLDER, DEFAULT_CONFIG_FILE_NAME)
return os.path.join(glb_aiida_config_folder, DEFAULT_CONFIG_FILE_NAME)


def load_config(create=False) -> 'Config':
Expand Down
18 changes: 9 additions & 9 deletions src/aiida/manage/configuration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
DEFAULT_ACCESS_CONTROL_DIR_NAME = 'access'

# Assign defaults which may be overriden in set_configuration_directory() below
AIIDA_CONFIG_FOLDER: pathlib.Path = pathlib.Path(DEFAULT_AIIDA_PATH).expanduser() / DEFAULT_CONFIG_DIR_NAME
glb_aiida_config_folder: pathlib.Path = pathlib.Path(DEFAULT_AIIDA_PATH).expanduser() / DEFAULT_CONFIG_DIR_NAME

# DAEMON_DIR: pathlib.Path = AIIDA_CONFIG_FOLDER / DEFAULT_DAEMON_DIR_NAME
# DAEMON_DIR: pathlib.Path = glb_aiida_config_folder / DEFAULT_DAEMON_DIR_NAME
# DAEMON_LOG_DIR: pathlib.Path = DAEMON_DIR / DEFAULT_DAEMON_LOG_DIR_NAME
# ACCESS_CONTROL_DIR: pathlib.Path = AIIDA_CONFIG_FOLDER / DEFAULT_ACCESS_CONTROL_DIR_NAME
# ACCESS_CONTROL_DIR: pathlib.Path = glb_aiida_config_folder / DEFAULT_ACCESS_CONTROL_DIR_NAME

@final
class AiiDAConfigPathResolver:
Expand All @@ -42,7 +42,7 @@ class AiiDAConfigPathResolver:

def __init__(self, config_folder: pathlib.Path | None = None) -> None:
if config_folder is None:
self._aiida_path = AIIDA_CONFIG_FOLDER
self._aiida_path = glb_aiida_config_folder
else:
self._aiida_path = config_folder

Expand All @@ -66,7 +66,7 @@ def access_control_dir(self) -> pathlib.Path:
def create_instance_directories(aiida_config_folder: pathlib.Path | None) -> None:
"""Create the base directories required for a new AiiDA instance.
This will create the base AiiDA directory defined by the AIIDA_CONFIG_FOLDER variable, unless it already exists.
This will create the base AiiDA directory defined by the glb_aiida_config_folder variable, unless it already exists.
Subsequently, it will create the daemon directory within it and the daemon log directory.
"""
from aiida.common import ConfigurationError
Expand Down Expand Up @@ -101,7 +101,7 @@ def get_configuration_directory():
The location of the configuration directory is defined following these heuristics in order:
* If the ``AIIDA_PATH`` variable is set, all the paths will be checked to see if they contain a
configuration folder. The first one to be encountered will be set as ``AIIDA_CONFIG_FOLDER``. If none of them
configuration folder. The first one to be encountered will be set as ``glb_aiida_config_folder``. If none of them
contain one, the last path defined in the environment variable considered is used.
* If an existing directory is still not found, the ``DEFAULT_AIIDA_PATH`` is used.
Expand Down Expand Up @@ -153,10 +153,10 @@ def set_configuration_directory(aiida_config_folder: pathlib.Path | None = None)
is returned by ``get_configuration_directory``. If the directory does not exist yet, it is created, together with
all its subdirectories.
"""
global AIIDA_CONFIG_FOLDER
AIIDA_CONFIG_FOLDER = aiida_config_folder or get_configuration_directory()
global glb_aiida_config_folder
glb_aiida_config_folder = aiida_config_folder or get_configuration_directory()

create_instance_directories(AIIDA_CONFIG_FOLDER)
create_instance_directories(glb_aiida_config_folder)


# Initialize the configuration directory settings
Expand Down
4 changes: 2 additions & 2 deletions src/aiida/manage/tests/pytest_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def aiida_instance(

dirpath_config = tmp_path_factory.mktemp('config')
os.environ[settings.DEFAULT_AIIDA_PATH_VARIABLE] = str(dirpath_config)
settings.AIIDA_CONFIG_FOLDER = dirpath_config
settings.glb_aiida_config_folder = dirpath_config
settings.set_configuration_directory()
configuration.CONFIG = configuration.load_config(create=True)

Expand All @@ -191,7 +191,7 @@ def aiida_instance(
else:
os.environ[settings.DEFAULT_AIIDA_PATH_VARIABLE] = current_path_variable

settings.AIIDA_CONFIG_FOLDER = current_config_path
settings.glb_aiida_config_folder = current_config_path
configuration.CONFIG = current_config
if current_profile:
aiida_manager.load_profile(current_profile.name, allow_switch=True)
Expand Down
4 changes: 2 additions & 2 deletions src/aiida/storage/sqlite_dos/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from aiida.common import exceptions
from aiida.common.log import AIIDA_LOGGER
from aiida.manage.configuration.profile import Profile
from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER
from aiida.manage.configuration.settings import glb_aiida_config_folder
from aiida.orm.implementation import BackendEntity
from aiida.storage.log import MIGRATE_LOGGER
from aiida.storage.psql_dos.models.settings import DbSetting
Expand Down Expand Up @@ -203,7 +203,7 @@ class Model(BaseModel, defer_build=True):
filepath: str = Field(
title='Directory of the backend',
description='Filepath of the directory in which to store data for this backend.',
default_factory=lambda: str(AIIDA_CONFIG_FOLDER / 'repository' / f'sqlite_dos_{uuid4().hex}'),
default_factory=lambda: str(glb_aiida_config_folder / 'repository' / f'sqlite_dos_{uuid4().hex}'),
)

@field_validator('filepath')
Expand Down
10 changes: 5 additions & 5 deletions tests/manage/configuration/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_environment_variable_not_set(chdir_tmp_path, monkeypatch):

config_folder = chdir_tmp_path / settings.DEFAULT_CONFIG_DIR_NAME
assert os.path.isdir(config_folder)
assert settings.AIIDA_CONFIG_FOLDER == pathlib.Path(config_folder)
assert settings.glb_aiida_config_folder == pathlib.Path(config_folder)


@pytest.mark.filterwarnings('ignore:Creating AiiDA configuration folder')
Expand All @@ -83,7 +83,7 @@ def test_environment_variable_set_single_path_without_config_folder(tmp_path):
# This should have created the configuration directory in the path
config_folder = tmp_path / settings.DEFAULT_CONFIG_DIR_NAME
assert config_folder.is_dir()
assert settings.AIIDA_CONFIG_FOLDER == config_folder
assert settings.glb_aiida_config_folder == config_folder


@pytest.mark.filterwarnings('ignore:Creating AiiDA configuration folder')
Expand All @@ -99,7 +99,7 @@ def test_environment_variable_set_single_path_with_config_folder(tmp_path):
# This should have created the configuration directory in the path
config_folder = tmp_path / settings.DEFAULT_CONFIG_DIR_NAME
assert config_folder.is_dir()
assert settings.AIIDA_CONFIG_FOLDER == config_folder
assert settings.glb_aiida_config_folder == config_folder


@pytest.mark.filterwarnings('ignore:Creating AiiDA configuration folder')
Expand All @@ -119,7 +119,7 @@ def test_environment_variable_path_including_config_folder(tmp_path):
# This should have created the configuration directory in the pathpath
config_folder = tmp_path / settings.DEFAULT_CONFIG_DIR_NAME
assert config_folder.is_dir()
assert settings.AIIDA_CONFIG_FOLDER == config_folder
assert settings.glb_aiida_config_folder == config_folder


@pytest.mark.filterwarnings('ignore:Creating AiiDA configuration folder')
Expand All @@ -142,7 +142,7 @@ def test_environment_variable_set_multiple_path(tmp_path):
# This should have created the configuration directory in the last path
config_folder = directory_c / settings.DEFAULT_CONFIG_DIR_NAME
assert os.path.isdir(config_folder)
assert settings.AIIDA_CONFIG_FOLDER == config_folder
assert settings.glb_aiida_config_folder == config_folder


def compare_config_in_memory_and_on_disk(config, filepath):
Expand Down
4 changes: 2 additions & 2 deletions tests/manage/test_caching_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_merge_deprecated_yaml(tmp_path):
configuration.CONFIG = None

# Create a temporary folder, set it as the current config directory path
settings.AIIDA_CONFIG_FOLDER = str(tmp_path)
settings.glb_aiida_config_folder = str(tmp_path)
config_dictionary = json.loads(
pathlib.Path(__file__)
.parent.joinpath('configuration/migrations/test_samples/reference/6.json')
Expand Down Expand Up @@ -86,7 +86,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.AIIDA_CONFIG_FOLDER = current_config_path
settings.glb_aiida_config_folder = current_config_path
configuration.CONFIG = current_config
load_profile(current_profile_name)

Expand Down

0 comments on commit 418cc2a

Please sign in to comment.