Skip to content

Commit

Permalink
part
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Nov 14, 2024
1 parent f7398af commit ec3ebec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
35 changes: 20 additions & 15 deletions src/aiida/manage/configuration/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

from __future__ import annotations

import collections
from collections import abc
import os
import pathlib
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Type
from typing import TYPE_CHECKING, Any, Dict, Literal, Mapping, Optional, Type

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

from .options import parse_option

Expand All @@ -29,26 +30,28 @@
class Profile:
"""Class that models a profile as it is stored in the configuration file of an AiiDA instance."""

KEY_UUID = 'PROFILE_UUID'
KEY_DEFAULT_USER_EMAIL = 'default_user_email'
KEY_STORAGE = 'storage'
KEY_PROCESS = 'process_control'
KEY_STORAGE_BACKEND = 'backend'
KEY_STORAGE_CONFIG = 'config'
KEY_PROCESS_BACKEND = 'backend'
KEY_PROCESS_CONFIG = 'config'
KEY_OPTIONS = 'options'
KEY_TEST_PROFILE = 'test_profile'
KEY_UUID: str = 'PROFILE_UUID'
KEY_DEFAULT_USER_EMAIL: str = 'default_user_email'
KEY_STORAGE: str = 'storage'
KEY_PROCESS: str = 'process_control'
KEY_STORAGE_BACKEND: str = 'backend'
KEY_STORAGE_CONFIG: str = 'config'
KEY_PROCESS_BACKEND: str = 'backend'
KEY_PROCESS_CONFIG: str = 'config'
KEY_OPTIONS: str = 'options'
KEY_TEST_PROFILE: str = 'test_profile'

# keys that are expected to be in the parsed configuration
REQUIRED_KEYS = (
REQUIRED_KEYS: tuple[Literal['storage'], Literal['process_control']] = (
KEY_STORAGE,
KEY_PROCESS,
)

def __init__(self, name: str, config: Mapping[str, Any], validate=True):
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, collections.abc.Mapping):
if not isinstance(config, abc.Mapping):
raise TypeError(f'config should be a mapping but is {type(config)}')
if validate and not set(config.keys()).issuperset(self.REQUIRED_KEYS):
raise exceptions.ConfigurationError(
Expand All @@ -64,6 +67,8 @@ def __init__(self, name: str, config: Mapping[str, Any], validate=True):

self._attributes[self.KEY_UUID] = uuid4().hex

self._config_path_resolver: AiiDAConfigPathResolver = AiiDAConfigPathResolver(config_folder)

def __repr__(self) -> str:
return f'Profile<uuid={self.uuid!r} name={self.name!r}>'

Expand Down
8 changes: 4 additions & 4 deletions src/aiida/manage/configuration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
# 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

DAEMON_DIR: pathlib.Path = 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

# DAEMON_DIR: pathlib.Path = 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
#

@final
class AiiDAConfigPathResolver:
Expand Down

0 comments on commit ec3ebec

Please sign in to comment.