Skip to content

Commit

Permalink
Remove use of ACCESS_CONTROL_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Nov 15, 2024
1 parent 418cc2a commit d7f3684
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
15 changes: 12 additions & 3 deletions src/aiida/manage/configuration/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from typing import TYPE_CHECKING, Any, Dict, Literal, Mapping, Optional, Type

from aiida.common import exceptions
from aiida.common.lang import type_check
from aiida.manage.configuration.settings import AiiDAConfigPathResolver

from .options import parse_option
Expand Down Expand Up @@ -51,14 +52,13 @@ def __init__(
self, name: str, config: Mapping[str, Any], config_folder: pathlib.Path | None = None, validate: bool = True
):
"""Load a profile with the profile configuration."""
if not isinstance(config, abc.Mapping):
raise TypeError(f'config should be a mapping but is {type(config)}')
_ = type_check(config, abc.Mapping)
if validate and not set(config.keys()).issuperset(self.REQUIRED_KEYS):
raise exceptions.ConfigurationError(
f'profile {name!r} configuration does not contain all required keys: {self.REQUIRED_KEYS}'
)

self._name = name
self._name: str = name
self._attributes: Dict[str, Any] = deepcopy(config)

# Create a default UUID if not specified
Expand Down Expand Up @@ -88,6 +88,15 @@ def uuid(self) -> str:
def uuid(self, value: str) -> None:
self._attributes[self.KEY_UUID] = value

@property
def config_path_resolver(self) -> AiiDAConfigPathResolver:
"""The config_path_resolver property."""
return self._config_path_resolver

@config_path_resolver.setter
def config_path_resolver(self, value):
self._config_path_resolver = value

@property
def default_user_email(self) -> Optional[str]:
"""Return the default user email."""
Expand Down
12 changes: 6 additions & 6 deletions src/aiida/manage/configuration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
# Assign defaults which may be overriden in set_configuration_directory() below
glb_aiida_config_folder: pathlib.Path = pathlib.Path(DEFAULT_AIIDA_PATH).expanduser() / DEFAULT_CONFIG_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 = glb_aiida_config_folder / DEFAULT_ACCESS_CONTROL_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


@final
class AiiDAConfigPathResolver:
Expand Down Expand Up @@ -101,8 +101,8 @@ 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 ``glb_aiida_config_folder``. If none of them
contain one, the last path defined in the environment variable considered is used.
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.
:returns: The path of the configuration directory.
Expand Down Expand Up @@ -153,7 +153,7 @@ 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 glb_aiida_config_folder
global glb_aiida_config_folder # noqa: PLW0603
glb_aiida_config_folder = aiida_config_folder or get_configuration_directory()

create_instance_directories(glb_aiida_config_folder)
Expand Down
8 changes: 3 additions & 5 deletions src/aiida/manage/profile_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from aiida.common.lang import type_check
from aiida.manage.configuration import Profile


@typing.final
class ProfileAccessManager:
"""Class to manage access to a profile.
Expand All @@ -45,12 +45,10 @@ def __init__(self, profile: Profile):
:param profile: the profile whose access to manage.
"""
from aiida.manage.configuration.settings import ACCESS_CONTROL_DIR

type_check(profile, Profile)
_ = type_check(profile, Profile)
self.profile = profile
self.process = psutil.Process(os.getpid())
self._dirpath_records = ACCESS_CONTROL_DIR / profile.name
self._dirpath_records = profile.config_path_resolver.access_control_dir / profile.name
self._dirpath_records.mkdir(exist_ok=True)

def request_access(self) -> None:
Expand Down

0 comments on commit d7f3684

Please sign in to comment.