cmeta.core module

СMeta core class and functions

cMeta author and developer: (C) 2025-2026 Grigori Fursin

See the cMeta COPYRIGHT and LICENSE files in the project root for details.

Classes

class cmeta.core.CMeta(home: str | None = None, debug: bool | None = None, fail_on_error: bool | None = None, log_level: str | None = None, log_file: str | None = None, log_format: str | None = None, pause_if_error: bool | None = None, package_allow_install: bool | None = True, package_timeout: float | None = None, print_host_info: bool | None = False)[source]

Bases: object

A common meta system to manage and reuse common artifacts and their automations.

__init__(home: str | None = None, debug: bool | None = None, fail_on_error: bool | None = None, log_level: str | None = None, log_file: str | None = None, log_format: str | None = None, pause_if_error: bool | None = None, package_allow_install: bool | None = True, package_timeout: float | None = None, print_host_info: bool | None = False)[source]

Initialize CMeta with repositories

Parameters:
  • home (Optional[str]) – Path to cMeta home directory.

  • debug (Optional[bool]) – If True, sets log_level to “DEBUG” (overrides log_level parameter).

  • fail_on_error (Optional[bool]) – If True, raise error instead of returning dictionary with error

  • log_level (Optional[str]) – Logging level as string (case-insensitive).

  • log_file (Optional[str]) – Path to log file. If provided and not empty, logs will be written to this file.

  • log_format (Optional[str]) – Logging format string.

  • pause_if_error (Optional[bool]) – If True, pause before exiting after errors.

  • package_allow_install (Optional[bool]) – If True, allow automatic Python package installation.

  • package_timeout (Optional[float]) – Default timeout for package installation and checks, in seconds.

  • print_host_info (Optional[bool]) – If True, print host system information during access calls.

Returns:

This is a constructor that initializes the CMeta instance.

Return type:

None

Raises:
  • FileExistsError – If there’s a race condition when creating the home directory.

  • OSError – If there’s an error creating the home directory due to permissions or other OS-level issues.

  • PermissionError – If the process lacks permissions to create the home directory.

  • Exception – For any other unexpected errors during directory creation or initialization.

error(error_msg, return_code=1, exception=None, fail16=False, fail_on_error=None, extra={})[source]

Create or raise a cMeta error using framework-level defaults.

Parameters:
  • error_msg – Error message text.

  • return_code – Numeric return code.

  • exception – Exception object associated with the error.

  • fail16 – If True, treat return code 16 as a fatal error.

  • fail_on_error – If True, raise exceptions instead of returning error dictionaries.

Returns:

Operation result.

Return type:

dict

Raises:

Exception – Propagated runtime errors, if any.

catch_error(r, fail16=False)[source]

Catches error and creates return dictionary or raise exception based on fail_on_error flag.

Parameters:
  • r – cMeta access return dict

  • fail16 – If True, treat return code 16 as a fatal error.

Returns:

Dictionary with ‘return’ and ‘error’ keys.

Return type:

dict

Raises:

Exception – If fail_on_error is True and return_code != 16.

Example

if self.cm.catch_error(r): return r

catch_error_and_halt(r, fail16=False)[source]

Raise or print an error and terminate execution when needed.

Parameters:
  • r (dict) – cMeta return dictionary.

  • fail16 (bool) – If True, treat return code 16 as a fatal error.

Returns:

Original input dictionary.

Return type:

dict

Raises:

Exception – Propagated runtime errors, if any.

halt(r)[source]

If r[‘return’]>0: print error and halt

Parameters:

r (dict) – output from CM function with “return” and “error”

Returns:

r

Return type:

(dict)

Raises:

Exception – Propagated runtime errors, if any.

dump(filename, meta, wait=False)[source]

Write metadata to a file and optionally wait for user confirmation.

Parameters:
  • filename – File name or path string.

  • meta – Metadata dictionary to persist.

  • wait – If True, wait for interactive confirmation after writing data.

Returns:

Operation result.

Return type:

dict

Raises:

Exception – Propagated runtime errors, if any.

outdated(path, meta)[source]
access(request: Dict[str, Any]) Dict[str, Any][source]

Access common meta framework in a unified way

Parameters:

request (Dict[str, Any]) – Dictionary containing the request data

Returns:

0, …} for success or {“return”: >0, “error”: “error text”} for errors

Return type:

Dictionary with {“return”

Raises:

Exception – Propagated runtime errors, if any.

Constants

cmeta.core.control_params_desc = [{'aliases': ['h'], 'desc': 'Show help', 'key': 'help', 'type': <class 'bool'>}, {'desc': 'Reindex all artifacts', 'key': 'reindex', 'type': <class 'bool'>}, {'aliases': ['v'], 'desc': 'Use verbose output', 'key': 'verbose', 'type': <class 'bool'>}, {'aliases': ['q'], 'desc': 'Quetly select default answer to questions', 'key': 'quiet', 'type': <class 'bool'>}, {'aliases': ['r'], 'desc': 'Save input and related into to cmeta-reproduce-input.json', 'key': 'repro', 'type': <class 'bool'>}, {'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'>}, {'desc': 'Dump context to cmeta-ctx.json at the end of a command', 'key': 'dump', 'type': <class 'bool'>}, {'desc': 'Pause at the end of a command', 'key': 'pause_at_the_end', 'type': <class 'bool'>}, {'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'>}, {'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.