核心与配置¶
BaseModule
¶
Bases: ABC
Abstract base class for all modules in aloha.
Provides common attributes to all modules: - config: Global configuration object - LOG: Logger instance
Source code in aloha/base.py
Settings
¶
Global settings management class for the Aloha package.
This class manages the lazy loading of HOCON configuration files, environment profile resolution, and provides access to project resource and configuration directories.
Attributes: _config (Any | None): Internal storage for the parsed configuration.
Source code in aloha/settings.py
config
property
¶
Get the global configuration object.
Lazily loads and parses configuration files on first access. It resolves active
HOCON configuration files based on the FILES_CONFIG or ENV_PROFILE environment
variables, falls back to main.conf if not specified, and merges them into an AttrDict.
Returns:
| Type | Description |
|---|---|
|
Merged global configuration settings as an AttrDict. |
dir_config
property
¶
Get the absolute path of the configuration directory.
Resolves dynamically based on the DIR_CONFIG environment variable,
falling back to the 'config' subdirectory under the resource directory.
Returns:
| Type | Description |
|---|---|
|
Absolute path to the configuration directory. |
dir_resource
property
¶
Get the absolute path of the resource directory.
Resolves dynamically based on the DIR_RESOURCE environment variable,
falling back to the default 'resource' directory in the current working directory.
Returns:
| Type | Description |
|---|---|
|
Absolute path to the resource directory. |
__getitem__(item)
¶
Get a configuration value using dictionary key lookup syntax.
Allows retrieving configurations using SETTINGS[key].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
The configuration key to look up. |
required |
Returns:
| Type | Description |
|---|---|
|
The resolved configuration value. |
Source code in aloha/settings.py
__init__(config=None)
¶
Initialize the Settings manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any | None
|
Optional pre-loaded configuration dictionary, list, or None. If provided, it is parsed and loaded immediately. |
None
|
Source code in aloha/settings.py
load_settings(config)
¶
Recursively load and transform configuration values.
Converts raw dictionaries into AttrDict objects to support attribute-style
dot notation access, and recursively processes lists and nested values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
The configuration data to load (dict or list). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The converted configuration object (AttrDict or list). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the configuration data type is unsupported. |
Source code in aloha/settings.py
get_config_dir(*args)
¶
Get the configuration directory path. The config directory is determined by: 1. If DIR_CONFIG environment variable is set, use it; 2. Otherwise, default to 'config' directory under resource directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Additional path components to append to the config directory |
()
|
Returns:
| Type | Description |
|---|---|
str
|
Config directory path |
Source code in aloha/config/paths.py
get_config_files()
¶
Get a list of config files to parse. The base dir of config files should be specified by get_config_dir().
1. The function will look up the FILES_CONFIG environment variable to get a list of file names seperated by comma, if specified;
2. In case FILES_CONFIG is not specified, the function will use the default config file;
3. The default config file is determined by:
(a) If environment variable ENV_PROFILE is defined, the entry file will be "main-{ENV_PROFILE}.conf"
(b) If environment variable ENV_PROFILE is not defined, the entry config file will be "main.conf".
Returns:
| Type | Description |
|---|---|
list
|
list of string, which are file names of config files |
Source code in aloha/config/paths.py
get_current_module_dir(file_caller)
¶
Get the directory containing the given module file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_caller
|
str
|
Path to the module file (usually file) |
required |
Returns:
| Type | Description |
|---|---|
str
|
Directory path of the module |
Source code in aloha/config/paths.py
get_project_base_dir(file_caller)
¶
Get the project base directory by searching upwards for init.py. Starts from the given file path and moves up until a directory without init.py is found, indicating the project root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_caller
|
str
|
Path to the starting file (usually file) |
required |
Returns:
| Type | Description |
|---|---|
str
|
Project base directory path |
Source code in aloha/config/paths.py
get_resource_dir(*args)
¶
Get the resource directory path. The resource directory is determined by: 1. If DIR_RESOURCE environment variable is set, use it; 2. Otherwise, default to 'resource' directory under current working directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Additional path components to append to the resource directory |
()
|
Returns:
| Type | Description |
|---|---|
str
|
Resource directory path |
Source code in aloha/config/paths.py
path_join(*args)
¶
Join path components and normalize the result. Performs path joining, user expansion, environment variable expansion, and conversion to absolute path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Path components to join |
()
|
Returns:
| Type | Description |
|---|---|
str
|
Normalized absolute path string |
Source code in aloha/config/paths.py
load_config_from_hocon(config_file)
¶
Load configuration from a single HOCON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
Path to the HOCON configuration file |
required |
Returns:
| Type | Description |
|---|---|
|
Configuration as an ordered dictionary |
Source code in aloha/config/hocon.py
load_config_from_hocon_files(config_files, base_dir)
¶
Load configuration from multiple HOCON files.
Combines multiple HOCON files using include directives and returns the result as an AttrDict for attribute-style access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_files
|
list
|
List of HOCON configuration file names |
required |
base_dir
|
str
|
Base directory for resolving relative paths |
required |
Returns:
| Type | Description |
|---|---|
|
Configuration as an AttrDict object |