Skip to content

Collection acronyms for identification - cafi#

library #

validate #

validate_catalogue_db(to_eval, acr_db) #

Validates and creates a catalogue database from input data.

Parameters:

Name Type Description Default
to_eval dict[str, Any]

The input dictionary containing raw catalogue data.

required
acr_db ACR_DB_T

Acronym database used for validation purposes.

required

Returns:

Name Type Description
CCNO_DB_T CCNO_DB_T

The validated catalogue database.

Raises:

Type Description
Exception

If the validation process fails, an exception is raised with a message indicating incorrect formatting.

Source code in src/cafi/library/validate.py
def validate_catalogue_db(to_eval: dict[str, Any], acr_db: ACR_DB_T, /) -> CCNO_DB_T:
    """
    Validates and creates a catalogue database from input data.

    Args:
        to_eval (dict[str, Any]): The input dictionary containing raw catalogue data.
        acr_db (ACR_DB_T): Acronym database used for validation purposes.

    Returns:
        CCNO_DB_T: The validated catalogue database.

    Raises:
        Exception: If the validation process fails, an exception is raised with
            a message indicating incorrect formatting.
    """
    msg = "Catalogue data is incorrectly formatted!"
    _validate_ccno_db_struct(msg, to_eval)
    catalogue = create_ccno_db(to_eval)
    _validate_catalogue_dc(catalogue, acr_db)
    return catalogue

main #

run() #

Attempts to load the ACR database or handle version compatibility issues.

This function is intended to be the entry point for running the application. Currently, it attempts to load the ACR database using the load_acr_db() function. If a ValJsonEx exception occurs, indicating that the installed cafi version is incompatible with the latest data, an appropriate error message is printed.

Note

This function currently does not implement any additional functionality beyond the described behavior.

Raises:

Type Description
ValJsonEx

If there is a compatibility issue between the installed cafi version and the latest data.

Exception

Any unhandled exceptions raised by load_acr_db() will propagate upwards.

Example

run()

This will attempt to load the ACR database or print an error message#

if incompatible versions are detected.#

If an error occurs, it may output something like:#

"installed cafi version is not compatible with the latest data"#

References
  • load_acr_db(): Function responsible for loading the ACR database.
  • ValJsonEx: Exception raised when there's a version compatibility issue.
Source code in src/cafi/main.py
def run() -> None:
    """
    Attempts to load the ACR database or handle version compatibility issues.

    This function is intended to be the entry point for running the application.
    Currently, it attempts to load the ACR
    database using the `load_acr_db()` function. If a `ValJsonEx` exception occurs,
    indicating that the installed cafi
    version is incompatible with the latest data, an appropriate error message is printed.

    Note:
        This function currently does not implement any additional functionality beyond
        the described behavior.

    Raises:
        ValJsonEx: If there is a compatibility issue between the installed cafi version
            and the latest data.
        Exception: Any unhandled exceptions raised by `load_acr_db()` will
            propagate upwards.

    Example:
        >>> run()
        # This will attempt to load the ACR database or print an error message
        # if incompatible versions are detected.
        # If an error occurs, it may output something like:
        # "installed cafi version is not compatible with the latest data"

    References:
        * `load_acr_db()`: Function responsible for loading the ACR database.
        * `ValJsonEx`: Exception raised when there's a version compatibility issue.
    """
    try:
        load_acr_db()
    except ValJsonEx:
        print("installed cafi version is not compatible with the latest data")