cmeta.config module
Configuration class
cMeta author and developer: (C) 2025-2026 Grigori Fursin
See the cMeta COPYRIGHT and LICENSE files in the project root for details.
Functions
- cmeta.config.check_init_vars_from_env()[source]
Load CMeta initialization parameters from environment variables.
Checks various environment variables to determine the home directory, logging settings, and debug/fail-on-error flags for CMeta initialization.
- Returns:
- A CMeta dictionary with the following keys:
return (int): Always 0 (success).
init (dict): Dictionary containing initialization parameters including ‘home’, ‘fail_on_error’, ‘log_level’, ‘log_file’, and ‘debug’.
- Return type:
dict
- cmeta.config.is_on(value)[source]
Check if a string value represents an “on” state.
- Parameters:
value (str | bool | None) – String to check (case-insensitive). Can be None.
- Returns:
- True if value is “1”, “on”, “true” or “yes” (case-insensitive), False otherwise.
Returns False if value is None.
- Return type:
bool
- cmeta.config.set_logging(name: str, log_level: str | None = None, log_file: str | None = None, log_format: str | None = None) Logger[source]
Set up logging configuration and return a logger.
- Parameters:
name (str) – Logger name.
log_level (str | None) – Logging level as string (case-insensitive). Accepted values: “DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL” If None or empty string, logging is disabled.
log_file (str | None) – Path to log file. If provided and not empty, logs will be written to this file. If None or empty string, logs will be written to console.
log_format (str | None) – Format string for log messages.
- Returns:
Configured logger instance.
- Return type:
logging.Logger
- Raises:
ValueError – If invalid log level is provided.
- cmeta.config.update_init_and_setup_logger(name: str, init: dict = {}, force_init: dict = {})[source]
Setup CMeta initialization parameters and configure logger.
Merges initialization parameters from environment with forced parameters, applies defaults and logical implications (e.g., debug mode enables DEBUG logging), and sets up the logger with the specified configuration.
- Parameters:
name (str) – Logger name (typically __name__ of the calling module).
init (dict) – Base initialization dictionary from environment.
force_init (dict) – Dictionary of parameters to forcibly override init values.
- Returns:
- A CMeta dictionary with the following keys:
return (int): 0 for success, >0 for error.
error (str): Error message if return > 0.
logger (logging.Logger): Configured logger instance (if return == 0).
init (dict): Final merged initialization parameters (if return == 0).
- Return type:
dict
Constants
- cmeta.config.cfg = {'base_category_last_api_version': 1, 'capitalized_name': 'CMETA', 'category_repo_uid': 'f4f792ab40c7498f', 'command_aliases': {'add': 'create', 'cp': 'copy', 'del': 'delete', 'load': 'read', 'ls': 'list', 'mv': 'move', 'remove': 'delete', 'ren': 'move', 'rename': 'move', 'rm': 'delete', 'search': 'find'}, 'con_error_prefix': 'cMeta error: ', 'default_config_name': 'default', 'default_ctuning_api': 'https://cTuning.ai/api/v1', 'default_git': 'https://github.com', 'default_git_repo': 'ctuninglabs', 'env_cmeta_log': 'CMETA_LOG', 'env_cmeta_log_file': 'CMETA_LOG_FILE', 'env_var_cmeta_authors': 'CMETA_AUTHORS', 'env_var_cmeta_copyright': 'CMETA_COPYRIGHT', 'env_var_cmeta_debug': 'CMETA_DEBUG', 'env_var_cmeta_fail_on_error': 'CMETA_FAIL_ON_ERROR', 'env_var_cmeta_server_info_url': 'http://127.0.0.1:8004/far?hcref=', 'env_var_cmeta_verbose': 'CMETA_VERBOSE', 'env_var_home': 'CMETA_HOME', 'env_var_home2': 'CMETA_HOME2', 'env_var_internal_repo_path': 'CMETA_INTERNAL_REPO_PATH', 'env_var_virtual_env': 'VIRTUAL_ENV', 'env_var_virtual_env2': 'CONDA_PREFIX', 'index_db_filename': 'index.db', 'index_dir': 'index', 'log_format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s', 'meta_filename_base': '_cmeta', 'name': 'cMeta', 'repo_local_meta': {'artifact': 'local,9a3280b14a4285c9', 'permanent': True}, 'repo_meta_desc': '_cmr.yaml', 'repos_config_filename': 'repos.json', 'repos_dir': 'repos'}
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
- cmeta.config.log_level_mapping = {'CRITICAL': 50, 'DEBUG': 10, 'ERROR': 40, 'FATAL': 50, 'INFO': 20, 'WARN': 30, 'WARNING': 30}
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
- cmeta.config.params_command2_desc = [{'desc': 'Category name (taken from the 1st argument from CLI)', 'key': 'category', 'skip_from_help': True, 'types': [<class 'str'>, <class 'dict'>]}, {'desc': 'Command (taken from the 2st argument from CLI)', 'key': 'command', 'skip_from_help': True, 'type': <class 'str'>}, {'desc': 'Force output to console', 'key': 'con', 'space_before': True, 'type': <class 'bool'>}, {'aliases': ['j'], 'desc': 'Print command output as JSON', 'key': 'json', 'type': <class 'bool'>}, {'aliases': ['json-file', 'jf'], 'desc': 'Specify json file to save command output', 'key': 'json_file', 'type': <class 'str'>}]
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
- cmeta.config.params_command_desc = [{'desc': 'Call common commands from the base category', 'key': 'base', 'space_before': True, 'type': <class 'bool'>}, {'desc': 'Choose category API version', 'key': 'api', 'type': <class 'int'>}]
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
- cmeta.config.params_desc = [{'aliases': ['h'], 'desc': 'Show help', 'key': 'help', 'type': <class 'bool'>}, {'aliases': ['v'], 'desc': 'Show version', 'key': 'version', 'type': <class 'bool'>}, {'desc': 'Reindex all artifacts', 'key': 'reindex', 'type': <class 'bool'>}, {'aliases': ['v'], 'desc': 'Use verbose output', 'key': 'verbose', 'type': <class 'bool'>}]
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
- cmeta.config.params_init_desc = [{'desc': 'Specify path with CMeta repositories', 'key': 'home', 'space_before': True, 'types': [<class 'str'>, <class 'bool'>]}, {'desc': 'Enable debug mode (sets log_level to "DEBUG" and fail_on_error to True)', 'key': 'debug', 'type': <class 'bool'>}, {'aliases': ['fail', 'fail-on-error'], 'desc': 'Raise exception on first error for debugging', 'key': 'fail_on_error', 'type': <class 'bool'>}, {'aliases': ['log-level'], 'desc': 'Set logging level (e.g., debug, info, warning, error)', 'key': 'log_level', 'type': <class 'str'>, 'values': ['DEBUG', 'INFO', 'WARNING', 'WARN', 'ERROR', 'CRITICAL', 'FATAL']}, {'aliases': ['log-file'], 'desc': 'Specify file for logging', 'key': 'log_file', 'type': <class 'str'>}, {'aliases': ['pif'], 'desc': 'Pause before exiting in case of errors', 'key': 'pause_if_error', 'type': <class 'bool'>}]
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.