aiida.manage.configuration package

Modules related to the configuration of an AiiDA instance.

class aiida.manage.configuration.Config(filepath: str, config: dict, validate: bool = True)[source]

Bases: object

Object that represents the configuration file of an AiiDA instance.

KEY_DEFAULT_PROFILE = 'default_profile'
KEY_OPTIONS = 'options'
KEY_PROFILES = 'profiles'
KEY_SCHEMA = '$schema'
KEY_VERSION = 'CONFIG_VERSION'
KEY_VERSION_CURRENT = 'CURRENT'
KEY_VERSION_OLDEST_COMPATIBLE = 'OLDEST_COMPATIBLE'
__dict__ = mappingproxy({'__module__': 'aiida.manage.configuration.config', '__doc__': 'Object that represents the configuration file of an AiiDA instance.', 'KEY_VERSION': 'CONFIG_VERSION', 'KEY_VERSION_CURRENT': 'CURRENT', 'KEY_VERSION_OLDEST_COMPATIBLE': 'OLDEST_COMPATIBLE', 'KEY_DEFAULT_PROFILE': 'default_profile', 'KEY_PROFILES': 'profiles', 'KEY_OPTIONS': 'options', 'KEY_SCHEMA': '$schema', 'from_file': <classmethod object>, '_backup': <classmethod object>, 'validate': <staticmethod object>, '__init__': <function Config.__init__>, '__eq__': <function Config.__eq__>, '__ne__': <function Config.__ne__>, 'handle_invalid': <function Config.handle_invalid>, 'dictionary': <property object>, 'version': <property object>, 'version_oldest_compatible': <property object>, 'version_settings': <property object>, 'filepath': <property object>, 'dirpath': <property object>, 'default_profile_name': <property object>, 'current_profile': <property object>, 'profile_names': <property object>, 'profiles': <property object>, 'validate_profile': <function Config.validate_profile>, 'get_profile': <function Config.get_profile>, 'add_profile': <function Config.add_profile>, 'update_profile': <function Config.update_profile>, 'remove_profile': <function Config.remove_profile>, 'set_default_profile': <function Config.set_default_profile>, 'options': <property object>, 'set_option': <function Config.set_option>, 'unset_option': <function Config.unset_option>, 'get_option': <function Config.get_option>, 'get_options': <function Config.get_options>, 'store': <function Config.store>, '_atomic_write': <function Config._atomic_write>, '__dict__': <attribute '__dict__' of 'Config' objects>, '__weakref__': <attribute '__weakref__' of 'Config' objects>, '__hash__': None})
__eq__(other)[source]

Two configurations are considered equal, when their dictionaries are equal.

__hash__ = None
__init__(filepath: str, config: dict, validate: bool = True)[source]

Instantiate a configuration object from a configuration dictionary and its filepath.

If an empty dictionary is passed, the constructor will create the skeleton configuration dictionary.

Parameters
  • filepath – the absolute filepath of the configuration file

  • config – the content of the configuration file in dictionary form

  • validate – validate the dictionary against the schema

__module__ = 'aiida.manage.configuration.config'
__ne__(other)[source]

Two configurations are considered unequal, when their dictionaries are unequal.

__weakref__

list of weak references to the object (if defined)

_atomic_write(filepath=None)[source]

Write the config as it is in memory, i.e. the contents of self.dictionary, to disk.

Note

this command will write the config from memory to a temporary file in the same directory as the target file filepath. It will then use os.rename to move the temporary file to filepath which will be overwritten if it already exists. The os.rename is the operation that gives the best guarantee of being atomic within the limitations of the application.

Parameters

filepath – optional filepath to write the contents to, if not specified, the default filename is used.

classmethod _backup(filepath)[source]

Create a backup of the configuration file with the given filepath.

Parameters

filepath – absolute path to the configuration file to backup

Returns

the absolute path of the created backup

add_profile(profile)[source]

Add a profile to the configuration.

Parameters

profile – the profile configuration dictionary

Returns

self

property current_profile

Return the currently loaded profile.

Returns

the current profile or None if not defined

property default_profile_name

Return the default profile name.

Returns

the default profile name or None if not defined

property dictionary

Return the dictionary representation of the config as it would be written to file.

Returns

dictionary representation of config as it should be written to file

property dirpath
property filepath
classmethod from_file(filepath)[source]

Instantiate a configuration object from the contents of a given file.

Note

if the filepath does not exist an empty file will be created with the current default configuration and will be written to disk. If the filepath does already exist but contains a configuration with an outdated schema, the content will be migrated and then written to disk.

Parameters

filepath – the absolute path to the configuration file

Returns

Config instance

get_option(option_name, scope=None, default=True)[source]

Get a configuration option for a certain scope.

Parameters
  • option_name – the name of the configuration option

  • scope – get the option for this profile or globally if not specified

  • default – boolean, If True will return the option default, even if not defined within the given scope

Returns

the option value or None if not set for the given scope

get_options(scope: Optional[str] = None) → Dict[str, Tuple[aiida.manage.configuration.options.Option, str, Any]][source]

Return a dictionary of all option values and their source (‘profile’, ‘global’, or ‘default’).

Parameters

scope – the profile name or globally if not specified

Returns

(option, source, value)

get_profile(name=None)[source]

Return the profile for the given name or the default one if not specified.

Returns

the profile instance or None if it does not exist

Raises

aiida.common.ProfileConfigurationError – if the name is not found in the configuration file

handle_invalid(message)[source]

Handle an incoming invalid configuration dictionary.

The current content of the configuration file will be written to a backup file.

Parameters

message – a string message to echo with describing the infraction

property options
property profile_names

Return the list of profile names.

Returns

list of profile names

property profiles

Return the list of profiles.

Returns

the profiles

Return type

list of Profile instances

remove_profile(name)[source]

Remove a profile from the configuration.

Parameters

name – the name of the profile to remove

Raises

aiida.common.ProfileConfigurationError – if the given profile does not exist

Returns

self

set_default_profile(name, overwrite=False)[source]

Set the given profile as the new default.

Parameters
  • name – name of the profile to set as new default

  • overwrite – when True, set the profile as the new default even if a default profile is already defined

Raises

aiida.common.ProfileConfigurationError – if the given profile does not exist

Returns

self

set_option(option_name, option_value, scope=None, override=True)[source]

Set a configuration option for a certain scope.

Parameters
  • option_name – the name of the configuration option

  • option_value – the option value

  • scope – set the option for this profile or globally if not specified

  • override – boolean, if False, will not override the option if it already exists

Returns

the parsed value (potentially cast to a valid type)

store()[source]

Write the current config to file.

Note

if the configuration file already exists on disk and its contents differ from those in memory, a backup of the original file on disk will be created before overwriting it.

Returns

self

unset_option(option_name: str, scope=None)[source]

Unset a configuration option for a certain scope.

Parameters
  • option_name – the name of the configuration option

  • scope – unset the option for this profile or globally if not specified

update_profile(profile)[source]

Update a profile in the configuration.

Parameters

profile – the profile instance to update

Returns

self

static validate(config: dict, filepath: Optional[str] = None)[source]

Validate a configuration dictionary.

validate_profile(name)[source]

Validate that a profile exists.

Parameters

name – name of the profile:

Raises

aiida.common.ProfileConfigurationError – if the name is not found in the configuration file

property version
property version_oldest_compatible
property version_settings
exception aiida.manage.configuration.ConfigValidationError(message: str, keypath: Sequence[Any] = (), schema: Optional[dict] = None, filepath: Optional[str] = None)[source]

Bases: aiida.common.exceptions.ConfigurationError

Configuration error raised when the file contents fails validation.

__init__(message: str, keypath: Sequence[Any] = (), schema: Optional[dict] = None, filepath: Optional[str] = None)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.manage.configuration.config'
__str__()str[source]

Return str(self).

class aiida.manage.configuration.Option(name: str, schema: Dict[str, Any])[source]

Bases: object

Represent a configuration option schema.

__dict__ = mappingproxy({'__module__': 'aiida.manage.configuration.options', '__doc__': 'Represent a configuration option schema.', '__init__': <function Option.__init__>, '__str__': <function Option.__str__>, 'name': <property object>, 'schema': <property object>, 'valid_type': <property object>, 'default': <property object>, 'description': <property object>, 'global_only': <property object>, 'validate': <function Option.validate>, '__dict__': <attribute '__dict__' of 'Option' objects>, '__weakref__': <attribute '__weakref__' of 'Option' objects>})
__init__(name: str, schema: Dict[str, Any])[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.manage.configuration.options'
__str__()str[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

property default
property description
property global_only
property name
property schema
property valid_type
validate(value: Any, cast: bool = True) → Any[source]

Validate a value

Parameters
  • value – The input value

  • cast – Attempt to cast the value to the required type

Returns

The output value

Raise

ConfigValidationError

class aiida.manage.configuration.Profile(name, attributes, from_config=False)[source]

Bases: object

Class that models a profile as it is stored in the configuration file of an AiiDA instance.

KEY_BROKER_HOST = 'broker_host'
KEY_BROKER_PARAMETERS = 'broker_parameters'
KEY_BROKER_PASSWORD = 'broker_password'
KEY_BROKER_PORT = 'broker_port'
KEY_BROKER_PROTOCOL = 'broker_protocol'
KEY_BROKER_USERNAME = 'broker_username'
KEY_BROKER_VIRTUAL_HOST = 'broker_virtual_host'
KEY_DATABASE_BACKEND = 'AIIDADB_BACKEND'
KEY_DATABASE_ENGINE = 'AIIDADB_ENGINE'
KEY_DATABASE_HOSTNAME = 'AIIDADB_HOST'
KEY_DATABASE_NAME = 'AIIDADB_NAME'
KEY_DATABASE_PASSWORD = 'AIIDADB_PASS'
KEY_DATABASE_PORT = 'AIIDADB_PORT'
KEY_DATABASE_USERNAME = 'AIIDADB_USER'
KEY_DEFAULT_USER = 'default_user_email'
KEY_OPTIONS = 'options'
KEY_REPOSITORY_URI = 'AIIDADB_REPOSITORY_URI'
KEY_UUID = 'PROFILE_UUID'
RMQ_PREFIX = 'aiida-{uuid}'
__dict__ = mappingproxy({'__module__': 'aiida.manage.configuration.profile', '__doc__': 'Class that models a profile as it is stored in the configuration file of an AiiDA instance.', 'RMQ_PREFIX': 'aiida-{uuid}', 'KEY_OPTIONS': 'options', 'KEY_UUID': 'PROFILE_UUID', 'KEY_DEFAULT_USER': 'default_user_email', 'KEY_DATABASE_ENGINE': 'AIIDADB_ENGINE', 'KEY_DATABASE_BACKEND': 'AIIDADB_BACKEND', 'KEY_DATABASE_NAME': 'AIIDADB_NAME', 'KEY_DATABASE_PORT': 'AIIDADB_PORT', 'KEY_DATABASE_HOSTNAME': 'AIIDADB_HOST', 'KEY_DATABASE_USERNAME': 'AIIDADB_USER', 'KEY_DATABASE_PASSWORD': 'AIIDADB_PASS', 'KEY_BROKER_PROTOCOL': 'broker_protocol', 'KEY_BROKER_USERNAME': 'broker_username', 'KEY_BROKER_PASSWORD': 'broker_password', 'KEY_BROKER_HOST': 'broker_host', 'KEY_BROKER_PORT': 'broker_port', 'KEY_BROKER_VIRTUAL_HOST': 'broker_virtual_host', 'KEY_BROKER_PARAMETERS': 'broker_parameters', 'KEY_REPOSITORY_URI': 'AIIDADB_REPOSITORY_URI', '_map_config_to_internal': {'options': 'options', 'PROFILE_UUID': 'uuid', 'default_user_email': 'default_user', 'AIIDADB_ENGINE': 'database_engine', 'AIIDADB_BACKEND': 'database_backend', 'AIIDADB_NAME': 'database_name', 'AIIDADB_PORT': 'database_port', 'AIIDADB_HOST': 'database_hostname', 'AIIDADB_USER': 'database_username', 'AIIDADB_PASS': 'database_password', 'broker_protocol': 'broker_protocol', 'broker_username': 'broker_username', 'broker_password': 'broker_password', 'broker_host': 'broker_host', 'broker_port': 'broker_port', 'broker_virtual_host': 'broker_virtual_host', 'broker_parameters': 'broker_parameters', 'AIIDADB_REPOSITORY_URI': 'repository_uri'}, 'contains_unknown_keys': <classmethod object>, '__init__': <function Profile.__init__>, 'uuid': <property object>, 'default_user': <property object>, 'database_engine': <property object>, 'database_backend': <property object>, 'database_name': <property object>, 'database_port': <property object>, 'database_hostname': <property object>, 'database_username': <property object>, 'database_password': <property object>, 'broker_protocol': <property object>, 'broker_host': <property object>, 'broker_port': <property object>, 'broker_username': <property object>, 'broker_password': <property object>, 'broker_virtual_host': <property object>, 'broker_parameters': <property object>, 'repository_uri': <property object>, 'options': <property object>, 'get_option': <function Profile.get_option>, 'set_option': <function Profile.set_option>, 'unset_option': <function Profile.unset_option>, 'name': <property object>, 'dictionary': <property object>, 'rmq_prefix': <property object>, 'is_test_profile': <property object>, 'repository_path': <property object>, '_parse_repository_uri': <function Profile._parse_repository_uri>, 'get_rmq_url': <function Profile.get_rmq_url>, 'configure_repository': <function Profile.configure_repository>, 'filepaths': <property object>, '__dict__': <attribute '__dict__' of 'Profile' objects>, '__weakref__': <attribute '__weakref__' of 'Profile' objects>})
__init__(name, attributes, from_config=False)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.manage.configuration.profile'
__weakref__

list of weak references to the object (if defined)

_map_config_to_internal = {'AIIDADB_BACKEND': 'database_backend', 'AIIDADB_ENGINE': 'database_engine', 'AIIDADB_HOST': 'database_hostname', 'AIIDADB_NAME': 'database_name', 'AIIDADB_PASS': 'database_password', 'AIIDADB_PORT': 'database_port', 'AIIDADB_REPOSITORY_URI': 'repository_uri', 'AIIDADB_USER': 'database_username', 'PROFILE_UUID': 'uuid', 'broker_host': 'broker_host', 'broker_parameters': 'broker_parameters', 'broker_password': 'broker_password', 'broker_port': 'broker_port', 'broker_protocol': 'broker_protocol', 'broker_username': 'broker_username', 'broker_virtual_host': 'broker_virtual_host', 'default_user_email': 'default_user', 'options': 'options'}
_parse_repository_uri()[source]

This function validates the REPOSITORY_URI, that should be in the format protocol://address

Note

At the moment, only the file protocol is supported.

Returns

a tuple (protocol, address).

property broker_host
property broker_parameters
property broker_password
property broker_port
property broker_protocol
property broker_username
property broker_virtual_host
configure_repository()[source]

Validates the configured repository and in the case of a file system repo makes sure the folder exists.

classmethod contains_unknown_keys(dictionary)[source]

Return whether the profile dictionary contains any unsupported keys.

Parameters

dictionary – a profile dictionary

Returns

boolean, True when the dictionay contains unsupported keys

property database_backend
property database_engine
property database_hostname
property database_name
property database_password
property database_port
property database_username
property default_user
property dictionary

Return the profile attributes as a dictionary with keys as it is stored in the config

Returns

the profile configuration dictionary

property filepaths

Return the filepaths used by this profile.

Returns

a dictionary of filepaths

get_option(option_key, default=None)[source]
get_rmq_url()[source]
property is_test_profile

Return whether the profile is a test profile

Returns

boolean, True if test profile, False otherwise

property name

Return the profile name.

Returns

the profile name

property options
property repository_path

Return the absolute path of the repository configured for this profile.

Returns

absolute filepath of the profile’s file repository

property repository_uri
property rmq_prefix

Return the prefix that should be used for RMQ resources

Returns

the rmq prefix string

set_option(option_key, value, override=True)[source]

Set a configuration option for a certain scope.

Parameters
  • option_key – the key of the configuration option

  • option_value – the option value

  • override – boolean, if False, will not override the option if it already exists

unset_option(option_key)[source]
property uuid

Return the profile uuid.

Returns

string UUID

aiida.manage.configuration.config_schema() → Dict[str, Any][source]

Return the configuration schema.

aiida.manage.configuration.get_config(create=False)[source]

Return the current configuration.

If the configuration has not been loaded yet
  • the configuration is loaded using load_config

  • the global CONFIG variable is set

  • the configuration object is returned

Note: This function will except if no configuration file can be found. Only call this function, if you need information from the configuration file.

Parameters

create (bool) – if True, will create the configuration file if it does not already exist

Returns

the config

Return type

Config

Raises

aiida.common.ConfigurationError – if the configuration file could not be found, read or deserialized

aiida.manage.configuration.get_config_option(option_name)[source]

Return the value for the given configuration option.

This function will attempt to load the value of the option as defined for the current profile or otherwise as defined configuration wide. If no configuration is yet loaded, this function will fall back on the default that may be defined for the option itself. This is useful for options that need to be defined at loading time of AiiDA when no configuration is yet loaded or may not even yet exist. In cases where one expects a profile to be loaded, preference should be given to retrieving the option through the Config instance and its get_option method.

Parameters

option_name (str) – the name of the configuration option

Returns

option value as specified for the profile/configuration if loaded, otherwise option default

aiida.manage.configuration.get_config_path()[source]

Returns path to .aiida configuration directory.

aiida.manage.configuration.get_option(name: str)aiida.manage.configuration.options.Option[source]

Return option.

aiida.manage.configuration.get_option_names() → List[str][source]

Return a list of available option names.

aiida.manage.configuration.load_profile(profile=None)[source]

Load a profile.

Note

if a profile is already loaded and no explicit profile is specified, nothing will be done

Parameters

profile (str) – the name of the profile to load, by default will use the one marked as default in the config

Returns

the loaded Profile instance

Return type

Profile

Raises

aiida.common.exceptions.InvalidOperation – if the backend of another profile has already been loaded

aiida.manage.configuration.parse_option(option_name: str, option_value: Any) → Tuple[aiida.manage.configuration.options.Option, Any][source]

Parse and validate a value for a configuration option.

Parameters
  • option_name – the name of the configuration option

  • option_value – the option value

Returns

a tuple of the option and the parsed value

aiida.manage.configuration.reset_config()[source]

Reset the globally loaded config.

Warning

This is experimental functionality and should for now be used only internally. If the reset is unclean weird unknown side-effects may occur that end up corrupting or destroying data.

Submodules

Module that defines the configuration file of an AiiDA instance and functions to create and load it.

class aiida.manage.configuration.config.Config(filepath: str, config: dict, validate: bool = True)[source]

Bases: object

Object that represents the configuration file of an AiiDA instance.

KEY_DEFAULT_PROFILE = 'default_profile'
KEY_OPTIONS = 'options'
KEY_PROFILES = 'profiles'
KEY_SCHEMA = '$schema'
KEY_VERSION = 'CONFIG_VERSION'
KEY_VERSION_CURRENT = 'CURRENT'
KEY_VERSION_OLDEST_COMPATIBLE = 'OLDEST_COMPATIBLE'
__dict__ = mappingproxy({'__module__': 'aiida.manage.configuration.config', '__doc__': 'Object that represents the configuration file of an AiiDA instance.', 'KEY_VERSION': 'CONFIG_VERSION', 'KEY_VERSION_CURRENT': 'CURRENT', 'KEY_VERSION_OLDEST_COMPATIBLE': 'OLDEST_COMPATIBLE', 'KEY_DEFAULT_PROFILE': 'default_profile', 'KEY_PROFILES': 'profiles', 'KEY_OPTIONS': 'options', 'KEY_SCHEMA': '$schema', 'from_file': <classmethod object>, '_backup': <classmethod object>, 'validate': <staticmethod object>, '__init__': <function Config.__init__>, '__eq__': <function Config.__eq__>, '__ne__': <function Config.__ne__>, 'handle_invalid': <function Config.handle_invalid>, 'dictionary': <property object>, 'version': <property object>, 'version_oldest_compatible': <property object>, 'version_settings': <property object>, 'filepath': <property object>, 'dirpath': <property object>, 'default_profile_name': <property object>, 'current_profile': <property object>, 'profile_names': <property object>, 'profiles': <property object>, 'validate_profile': <function Config.validate_profile>, 'get_profile': <function Config.get_profile>, 'add_profile': <function Config.add_profile>, 'update_profile': <function Config.update_profile>, 'remove_profile': <function Config.remove_profile>, 'set_default_profile': <function Config.set_default_profile>, 'options': <property object>, 'set_option': <function Config.set_option>, 'unset_option': <function Config.unset_option>, 'get_option': <function Config.get_option>, 'get_options': <function Config.get_options>, 'store': <function Config.store>, '_atomic_write': <function Config._atomic_write>, '__dict__': <attribute '__dict__' of 'Config' objects>, '__weakref__': <attribute '__weakref__' of 'Config' objects>, '__hash__': None})
__eq__(other)[source]

Two configurations are considered equal, when their dictionaries are equal.

__hash__ = None
__init__(filepath: str, config: dict, validate: bool = True)[source]

Instantiate a configuration object from a configuration dictionary and its filepath.

If an empty dictionary is passed, the constructor will create the skeleton configuration dictionary.

Parameters
  • filepath – the absolute filepath of the configuration file

  • config – the content of the configuration file in dictionary form

  • validate – validate the dictionary against the schema

__module__ = 'aiida.manage.configuration.config'
__ne__(other)[source]

Two configurations are considered unequal, when their dictionaries are unequal.

__weakref__

list of weak references to the object (if defined)

_atomic_write(filepath=None)[source]

Write the config as it is in memory, i.e. the contents of self.dictionary, to disk.

Note

this command will write the config from memory to a temporary file in the same directory as the target file filepath. It will then use os.rename to move the temporary file to filepath which will be overwritten if it already exists. The os.rename is the operation that gives the best guarantee of being atomic within the limitations of the application.

Parameters

filepath – optional filepath to write the contents to, if not specified, the default filename is used.

classmethod _backup(filepath)[source]

Create a backup of the configuration file with the given filepath.

Parameters

filepath – absolute path to the configuration file to backup

Returns

the absolute path of the created backup

add_profile(profile)[source]

Add a profile to the configuration.

Parameters

profile – the profile configuration dictionary

Returns

self

property current_profile

Return the currently loaded profile.

Returns

the current profile or None if not defined

property default_profile_name

Return the default profile name.

Returns

the default profile name or None if not defined

property dictionary

Return the dictionary representation of the config as it would be written to file.

Returns

dictionary representation of config as it should be written to file

property dirpath
property filepath
classmethod from_file(filepath)[source]

Instantiate a configuration object from the contents of a given file.

Note

if the filepath does not exist an empty file will be created with the current default configuration and will be written to disk. If the filepath does already exist but contains a configuration with an outdated schema, the content will be migrated and then written to disk.

Parameters

filepath – the absolute path to the configuration file

Returns

Config instance

get_option(option_name, scope=None, default=True)[source]

Get a configuration option for a certain scope.

Parameters
  • option_name – the name of the configuration option

  • scope – get the option for this profile or globally if not specified

  • default – boolean, If True will return the option default, even if not defined within the given scope

Returns

the option value or None if not set for the given scope

get_options(scope: Optional[str] = None) → Dict[str, Tuple[aiida.manage.configuration.options.Option, str, Any]][source]

Return a dictionary of all option values and their source (‘profile’, ‘global’, or ‘default’).

Parameters

scope – the profile name or globally if not specified

Returns

(option, source, value)

get_profile(name=None)[source]

Return the profile for the given name or the default one if not specified.

Returns

the profile instance or None if it does not exist

Raises

aiida.common.ProfileConfigurationError – if the name is not found in the configuration file

handle_invalid(message)[source]

Handle an incoming invalid configuration dictionary.

The current content of the configuration file will be written to a backup file.

Parameters

message – a string message to echo with describing the infraction

property options
property profile_names

Return the list of profile names.

Returns

list of profile names

property profiles

Return the list of profiles.

Returns

the profiles

Return type

list of Profile instances

remove_profile(name)[source]

Remove a profile from the configuration.

Parameters

name – the name of the profile to remove

Raises

aiida.common.ProfileConfigurationError – if the given profile does not exist

Returns

self

set_default_profile(name, overwrite=False)[source]

Set the given profile as the new default.

Parameters
  • name – name of the profile to set as new default

  • overwrite – when True, set the profile as the new default even if a default profile is already defined

Raises

aiida.common.ProfileConfigurationError – if the given profile does not exist

Returns

self

set_option(option_name, option_value, scope=None, override=True)[source]

Set a configuration option for a certain scope.

Parameters
  • option_name – the name of the configuration option

  • option_value – the option value

  • scope – set the option for this profile or globally if not specified

  • override – boolean, if False, will not override the option if it already exists

Returns

the parsed value (potentially cast to a valid type)

store()[source]

Write the current config to file.

Note

if the configuration file already exists on disk and its contents differ from those in memory, a backup of the original file on disk will be created before overwriting it.

Returns

self

unset_option(option_name: str, scope=None)[source]

Unset a configuration option for a certain scope.

Parameters
  • option_name – the name of the configuration option

  • scope – unset the option for this profile or globally if not specified

update_profile(profile)[source]

Update a profile in the configuration.

Parameters

profile – the profile instance to update

Returns

self

static validate(config: dict, filepath: Optional[str] = None)[source]

Validate a configuration dictionary.

validate_profile(name)[source]

Validate that a profile exists.

Parameters

name – name of the profile:

Raises

aiida.common.ProfileConfigurationError – if the name is not found in the configuration file

property version
property version_oldest_compatible
property version_settings
exception aiida.manage.configuration.config.ConfigValidationError(message: str, keypath: Sequence[Any] = (), schema: Optional[dict] = None, filepath: Optional[str] = None)[source]

Bases: aiida.common.exceptions.ConfigurationError

Configuration error raised when the file contents fails validation.

__init__(message: str, keypath: Sequence[Any] = (), schema: Optional[dict] = None, filepath: Optional[str] = None)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.manage.configuration.config'
__str__()str[source]

Return str(self).

aiida.manage.configuration.config.config_schema() → Dict[str, Any][source]

Return the configuration schema.

Definition of known configuration options and methods to parse and get option values.

class aiida.manage.configuration.options.Option(name: str, schema: Dict[str, Any])[source]

Bases: object

Represent a configuration option schema.

__dict__ = mappingproxy({'__module__': 'aiida.manage.configuration.options', '__doc__': 'Represent a configuration option schema.', '__init__': <function Option.__init__>, '__str__': <function Option.__str__>, 'name': <property object>, 'schema': <property object>, 'valid_type': <property object>, 'default': <property object>, 'description': <property object>, 'global_only': <property object>, 'validate': <function Option.validate>, '__dict__': <attribute '__dict__' of 'Option' objects>, '__weakref__': <attribute '__weakref__' of 'Option' objects>})
__init__(name: str, schema: Dict[str, Any])[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.manage.configuration.options'
__str__()str[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

property default
property description
property global_only
property name
property schema
property valid_type
validate(value: Any, cast: bool = True) → Any[source]

Validate a value

Parameters
  • value – The input value

  • cast – Attempt to cast the value to the required type

Returns

The output value

Raise

ConfigValidationError

aiida.manage.configuration.options.get_option(name: str)aiida.manage.configuration.options.Option[source]

Return option.

aiida.manage.configuration.options.get_option_names() → List[str][source]

Return a list of available option names.

aiida.manage.configuration.options.parse_option(option_name: str, option_value: Any) → Tuple[aiida.manage.configuration.options.Option, Any][source]

Parse and validate a value for a configuration option.

Parameters
  • option_name – the name of the configuration option

  • option_value – the option value

Returns

a tuple of the option and the parsed value

AiiDA profile related code

class aiida.manage.configuration.profile.Profile(name, attributes, from_config=False)[source]

Bases: object

Class that models a profile as it is stored in the configuration file of an AiiDA instance.

KEY_BROKER_HOST = 'broker_host'
KEY_BROKER_PARAMETERS = 'broker_parameters'
KEY_BROKER_PASSWORD = 'broker_password'
KEY_BROKER_PORT = 'broker_port'
KEY_BROKER_PROTOCOL = 'broker_protocol'
KEY_BROKER_USERNAME = 'broker_username'
KEY_BROKER_VIRTUAL_HOST = 'broker_virtual_host'
KEY_DATABASE_BACKEND = 'AIIDADB_BACKEND'
KEY_DATABASE_ENGINE = 'AIIDADB_ENGINE'
KEY_DATABASE_HOSTNAME = 'AIIDADB_HOST'
KEY_DATABASE_NAME = 'AIIDADB_NAME'
KEY_DATABASE_PASSWORD = 'AIIDADB_PASS'
KEY_DATABASE_PORT = 'AIIDADB_PORT'
KEY_DATABASE_USERNAME = 'AIIDADB_USER'
KEY_DEFAULT_USER = 'default_user_email'
KEY_OPTIONS = 'options'
KEY_REPOSITORY_URI = 'AIIDADB_REPOSITORY_URI'
KEY_UUID = 'PROFILE_UUID'
RMQ_PREFIX = 'aiida-{uuid}'
__dict__ = mappingproxy({'__module__': 'aiida.manage.configuration.profile', '__doc__': 'Class that models a profile as it is stored in the configuration file of an AiiDA instance.', 'RMQ_PREFIX': 'aiida-{uuid}', 'KEY_OPTIONS': 'options', 'KEY_UUID': 'PROFILE_UUID', 'KEY_DEFAULT_USER': 'default_user_email', 'KEY_DATABASE_ENGINE': 'AIIDADB_ENGINE', 'KEY_DATABASE_BACKEND': 'AIIDADB_BACKEND', 'KEY_DATABASE_NAME': 'AIIDADB_NAME', 'KEY_DATABASE_PORT': 'AIIDADB_PORT', 'KEY_DATABASE_HOSTNAME': 'AIIDADB_HOST', 'KEY_DATABASE_USERNAME': 'AIIDADB_USER', 'KEY_DATABASE_PASSWORD': 'AIIDADB_PASS', 'KEY_BROKER_PROTOCOL': 'broker_protocol', 'KEY_BROKER_USERNAME': 'broker_username', 'KEY_BROKER_PASSWORD': 'broker_password', 'KEY_BROKER_HOST': 'broker_host', 'KEY_BROKER_PORT': 'broker_port', 'KEY_BROKER_VIRTUAL_HOST': 'broker_virtual_host', 'KEY_BROKER_PARAMETERS': 'broker_parameters', 'KEY_REPOSITORY_URI': 'AIIDADB_REPOSITORY_URI', '_map_config_to_internal': {'options': 'options', 'PROFILE_UUID': 'uuid', 'default_user_email': 'default_user', 'AIIDADB_ENGINE': 'database_engine', 'AIIDADB_BACKEND': 'database_backend', 'AIIDADB_NAME': 'database_name', 'AIIDADB_PORT': 'database_port', 'AIIDADB_HOST': 'database_hostname', 'AIIDADB_USER': 'database_username', 'AIIDADB_PASS': 'database_password', 'broker_protocol': 'broker_protocol', 'broker_username': 'broker_username', 'broker_password': 'broker_password', 'broker_host': 'broker_host', 'broker_port': 'broker_port', 'broker_virtual_host': 'broker_virtual_host', 'broker_parameters': 'broker_parameters', 'AIIDADB_REPOSITORY_URI': 'repository_uri'}, 'contains_unknown_keys': <classmethod object>, '__init__': <function Profile.__init__>, 'uuid': <property object>, 'default_user': <property object>, 'database_engine': <property object>, 'database_backend': <property object>, 'database_name': <property object>, 'database_port': <property object>, 'database_hostname': <property object>, 'database_username': <property object>, 'database_password': <property object>, 'broker_protocol': <property object>, 'broker_host': <property object>, 'broker_port': <property object>, 'broker_username': <property object>, 'broker_password': <property object>, 'broker_virtual_host': <property object>, 'broker_parameters': <property object>, 'repository_uri': <property object>, 'options': <property object>, 'get_option': <function Profile.get_option>, 'set_option': <function Profile.set_option>, 'unset_option': <function Profile.unset_option>, 'name': <property object>, 'dictionary': <property object>, 'rmq_prefix': <property object>, 'is_test_profile': <property object>, 'repository_path': <property object>, '_parse_repository_uri': <function Profile._parse_repository_uri>, 'get_rmq_url': <function Profile.get_rmq_url>, 'configure_repository': <function Profile.configure_repository>, 'filepaths': <property object>, '__dict__': <attribute '__dict__' of 'Profile' objects>, '__weakref__': <attribute '__weakref__' of 'Profile' objects>})
__init__(name, attributes, from_config=False)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.manage.configuration.profile'
__weakref__

list of weak references to the object (if defined)

_map_config_to_internal = {'AIIDADB_BACKEND': 'database_backend', 'AIIDADB_ENGINE': 'database_engine', 'AIIDADB_HOST': 'database_hostname', 'AIIDADB_NAME': 'database_name', 'AIIDADB_PASS': 'database_password', 'AIIDADB_PORT': 'database_port', 'AIIDADB_REPOSITORY_URI': 'repository_uri', 'AIIDADB_USER': 'database_username', 'PROFILE_UUID': 'uuid', 'broker_host': 'broker_host', 'broker_parameters': 'broker_parameters', 'broker_password': 'broker_password', 'broker_port': 'broker_port', 'broker_protocol': 'broker_protocol', 'broker_username': 'broker_username', 'broker_virtual_host': 'broker_virtual_host', 'default_user_email': 'default_user', 'options': 'options'}
_parse_repository_uri()[source]

This function validates the REPOSITORY_URI, that should be in the format protocol://address

Note

At the moment, only the file protocol is supported.

Returns

a tuple (protocol, address).

property broker_host
property broker_parameters
property broker_password
property broker_port
property broker_protocol
property broker_username
property broker_virtual_host
configure_repository()[source]

Validates the configured repository and in the case of a file system repo makes sure the folder exists.

classmethod contains_unknown_keys(dictionary)[source]

Return whether the profile dictionary contains any unsupported keys.

Parameters

dictionary – a profile dictionary

Returns

boolean, True when the dictionay contains unsupported keys

property database_backend
property database_engine
property database_hostname
property database_name
property database_password
property database_port
property database_username
property default_user
property dictionary

Return the profile attributes as a dictionary with keys as it is stored in the config

Returns

the profile configuration dictionary

property filepaths

Return the filepaths used by this profile.

Returns

a dictionary of filepaths

get_option(option_key, default=None)[source]
get_rmq_url()[source]
property is_test_profile

Return whether the profile is a test profile

Returns

boolean, True if test profile, False otherwise

property name

Return the profile name.

Returns

the profile name

property options
property repository_path

Return the absolute path of the repository configured for this profile.

Returns

absolute filepath of the profile’s file repository

property repository_uri
property rmq_prefix

Return the prefix that should be used for RMQ resources

Returns

the rmq prefix string

set_option(option_key, value, override=True)[source]

Set a configuration option for a certain scope.

Parameters
  • option_key – the key of the configuration option

  • option_value – the option value

  • override – boolean, if False, will not override the option if it already exists

unset_option(option_key)[source]
property uuid

Return the profile uuid.

Returns

string UUID

Base settings required for the configuration of an AiiDA instance.

aiida.manage.configuration.settings.create_directory(path)[source]

Attempt to create the configuration folder at the given path skipping if it already exists

Parameters

path – an absolute path to create a directory at

aiida.manage.configuration.settings.create_instance_directories()[source]

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. Subsequently, it will create the daemon directory within it and the daemon log directory.

aiida.manage.configuration.settings.set_configuration_directory()[source]

Determine the location of the configuration directory and set the related global variables.

The location of the configuration folder will be determined and optionally created following these heuristics:

  • 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 contain one, a configuration folder will be created in the last path considered.

  • If the AIIDA_PATH variable is not set the DEFAULT_AIIDA_PATH value will be used as base path and if it does not yet contain a configuration folder, one will be created.

In principle then, a configuration folder should always be found or automatically created.

Module that defines methods required to setup a new AiiDA instance.

aiida.manage.configuration.setup.delete_db(profile, non_interactive=True, verbose=False)[source]

Delete an AiiDA database associated with an AiiDA profile.

Parameters
aiida.manage.configuration.setup.delete_from_config(profile, non_interactive=True)[source]

Delete an AiiDA profile from the config file.

Parameters
aiida.manage.configuration.setup.delete_profile(profile, non_interactive=True, include_db=True, include_repository=True, include_config=True)[source]

Delete an AiiDA profile and AiiDA user.

Parameters
  • profile (aiida.manage.configuration.profile.Profile) – AiiDA profile

  • non_interactive – do not prompt for configuration values, fail if not all values are given as kwargs.

  • include_db (bool) – Include deletion of associated database

  • include_repository (bool) – Include deletion of associated file repository

  • include_config (bool) – Include deletion of entry from AiiDA configuration file

aiida.manage.configuration.setup.delete_repository(profile, non_interactive=True)[source]

Delete an AiiDA file repository associated with an AiiDA profile.

Parameters