caelus.config – Caelus Configuration Infrastructure

caelus.config performs the following tasks:

  • Configure the behavior of the Caelus python library using YAML based configuration files.
  • Provide an interface to Caelus CML installations and also aid in automated discovery of installed Caelus versions.
get_config Get the configuration object
reload_config Reset the configuration object
reset_default_config Reset to default configuration
cml_get_version Get the CML environment for the version requested
cml_get_latest_version Get the CML environment for the latest version available.
CMLEnv CML Environment Interface.

Caelus Python Configuration

The config module provides functions and classes for loading user configuration via YAML files and a central location to configure the behavior of the Caelus python library. The user configuration is stored in a dictionary format within the CaelusCfg and can be modified during runtime by user scripts. Access to the configuration object is by calling the get_config() method defined within this module which returns a fully populated instance of the configuration dictionary. This module also sets up logging (to both console as well as log files) during the initialization phase.

class caelus.config.config.CaelusCfg(**kwds)[source]

Bases: caelus.utils.struct.Struct

Caelus Configuration Object

A (key, value) dictionary containing all the configuration data parsed from the user configuration files. It is recommended that users obtain an instance of this class via the get_config() function instead of directly instantiating this class.

Initialize an ordered dictionary. The signature is the same as regular dictionaries, but keyword arguments are not recommended because their insertion order is arbitrary.

yaml_decoder

alias of caelus.utils.struct.StructYAMLLoader

yaml_encoder

alias of caelus.utils.struct.StructYAMLDumper

write_config(fh=<open file '<stdout>', mode 'w'>)[source]

Write configuration to file or standard output.

Parameters:fh (handle) – An open file handle
caelus.config.config.configure_logging(log_cfg=None)[source]

Configure python logging.

If log_cfg is None, then the basic configuration of python logging module is used.

See Python Logging Documentation for more information.

Parameters:log_cfg – Instance of CaelusCfg
caelus.config.config.get_appdata_dir()[source]

Return the path to the Windows APPDATA directory

caelus.config.config.get_caelus_root()[source]

Get Caelus root directory

In Unix-y systems this returns ${HOME}/Caelus and on Windows it returns C:\Caelus.

Returns:Path to Caelus root directory
Return type:path
caelus.config.config.get_config(base_cfg=None, init_logging=False)

Get the configuration object

On the first call, initializes the configuration object by parsing all available configuration files. Successive invocations return the same object that can be mutated by the user. The config dictionary can be reset by invoking reload_config().

Parameters:
  • base_cfg (CaelusCfg) – A base configuration object that is updated
  • init_logging (bool) – If True, initializes logging
Returns:

The configuration dictionary

Return type:

CaelusCfg

caelus.config.config.get_cpl_root()[source]

Return the root path for CPL

caelus.config.config.get_default_config()[source]

Return a fresh instance of the default configuration

This function does not read the caelus.yaml files on the system, and returns the configurations shipped with CPL.

Returns:The default configuration
Return type:CaelusCfg
caelus.config.config.rcfiles_loaded()

Return a list of the configuration files that were loaded

caelus.config.config.reload_config(base_cfg=None)

Reset the configuration object

Forces reloading of all the available configuration files and resets the modifications made by user scripts.

See also: reset_default_config()

Parameters:base_cfg – A CMLEnv object to use instead of default
Returns:The configuration dictionary
Return type:CaelusCfg
caelus.config.config.reset_default_config()

Reset to default configuration

Resets to library default configuration. Unlike reload_config(), this function does not load the configuration files.

Returns:The configuration dictionary
Return type:CaelusCfg
caelus.config.config.search_cfg_files()[source]

Search locations and return all possible configuration files.

The following locations are searched:

  • The path pointed by CAELUSRC_SYSTEM
  • The user’s home directory ~/.caelus/caelus.yaml on Unix-like systems, and %APPDATA%/caelus/caelus.yaml on Windows systems.
  • The path pointed by CAELUSRC, if defined.
  • The file caelus.yaml in the current working directory
Returns:List of configuration files available

Caelus CML Environment Manager

cmlenv serves as a replacement for Caelus/OpenFOAM bashrc files, providing ways to discover installed versions as well as interact with the installed Caelus CML versions. By default, cmlenv attempts to locate installed Caelus versions in standard locations: ~/Caelus/caelus-VERSION on Unix-like systems, and in C:Caelus in Windows systems. Users can override the default behavior and point to non-standard locations by customizing their Caelus Python configuration file.

class caelus.config.cmlenv.CMLEnv(cfg)[source]

Bases: object

CML Environment Interface.

This class provides an interface to an installed Caelus CML version.

Parameters:cfg (CaelusCfg) – The CML configuration object
bin_dir

Return the bin directory for executable

build_dir

Return the build platform directory

environ

Return an environment for running Caelus CML binaries

lib_dir

Return the bin directory for executable

mpi_bindir

Return the MPI executables path for this installation

mpi_dir

Return the MPI directory for this installation

mpi_libdir

Return the MPI library path for this installation

project_dir

Return the project directory path

Typically ~/Caelus/caelus-VERSION

root

Return the root path for the Caelus install

Typically on Linux/OSX this is the ~/Caelus directory.

user_bindir

Return path to user bin directory

user_dir

Return the user directory

user_libdir

Return path to user lib directory

version

Return the Caelus version

caelus.config.cmlenv.cml_get_latest_version()

Get the CML environment for the latest version available.

Returns:The environment object
Return type:CMLEnv
caelus.config.cmlenv.cml_get_version(version=None)

Get the CML environment for the version requested

If version is None, then it returns the version set as default in the configuration file.

Parameters:version (str) – Version string
Returns:The environment object
Return type:CMLEnv
caelus.config.cmlenv.discover_versions(root=None)[source]

Discover Caelus versions if no configuration is provided.

If no root directory is provided, then the function attempts to search in path provided by get_caelus_root().

Parameters:root (path) – Absolute path to root directory to be searched