Application, dependency and version management#

application.control#

Runtime control shared by simtools applications.

class simtools.application.control.RedactFilter(name='')[source]#

Filter to redact sensitive information from log messages.

This filter dynamically retrieves secret values from environment variables and uses pattern matching to identify and redact sensitive key-value pairs.

filter(record)[source]#

Filter log record to redact sensitive information.

simtools.application.control.get_log_file(args_dict, activity_id=None)[source]#

Get log file path.

Generate log file path if needed from application name and application ID.

Returns:
Path, str or None

Log file path, or None if no logging to file is configured.

simtools.application.control.initialize_runtime(args_dict, needs=())[source]#

Initialize common runtime services for parsed application configuration.

Parameters:
args_dictdict

Parsed application configuration.

needstuple of str, optional

Runtime services required by the application.

Returns:
RunContext

Configuration and services for the application run.

simtools.application.control.setup_logging(logger_name=None, log_level='INFO', log_file=None, activity_id=None)[source]#

Set up logging configuration.

Parameters:
logger_namestr, optional

Name for the logger. If None, uses the root logger. Default is None.

log_levelstr, optional

Logging level as a string (e.g., “DEBUG”, “INFO”). Default is “INFO”.

log_filestr or pathlib.Path, optional

Path to a log file. If provided, a file handler is added and log messages are written to this file. If None, logging to file is disabled. Default is None.

application.definition#

Definitions for command-line applications.

class simtools.application.definition.ApplicationDefinition(module_name, description, arguments=(), model_repository=False, needs=None, post_parse=None, defer_required_validation=False, usage=None, excluded_standard_arguments=())[source]#

Command-line and startup definition for an application.

property all_arguments#

Return standard and application-selected arguments in registration order.

build_parser()[source]#

Build the complete parser without reading configuration or starting the application.

classmethod for_module(module_name, **kwargs)[source]#

Define an application using the loaded module’s name and documentation.

property label#

Return the application module label.

start()[source]#

Read configuration and run the standard application startup sequence.

dependency_versions#

Read, validate, and export the simtools dependency version catalog.

simtools.model_repository.dependency_versions.build_workflow_matrices(catalog)[source]#

Build GitHub Actions matrices from the dependency catalog.

Image catalogs export only the production matrix. Catalogs that pin component sources also export the source-build matrices.

simtools.model_repository.dependency_versions.corsika_source_tag_for_build_id(build_id, catalog=None)[source]#

Return the CORSIKA source tag matching a legacy build identifier.

simtools.model_repository.dependency_versions.dependency_catalog_environment(catalog)[source]#

Return catalog-managed runtime values as environment assignments.

Parameters:
catalogdict

Validated dependency version catalog.

Returns:
dict

Environment variable names and values for model repository and test-resource configuration. Local paths and credentials are intentionally omitted.

simtools.model_repository.dependency_versions.dependency_catalog_summary(catalog)[source]#

Return stable scalar build values used by Docker workflows.

Image catalogs omit the values that only source builds use.

simtools.model_repository.dependency_versions.export_dependency_configuration(pyproject_path=None, output_format='catalog', extras=None)[source]#

Return dependency configuration in a selected export format.

Parameters:
pyproject_pathstr or Path, optional

Explicit project file, required for python-requirements output. The repository is searched when omitted for that output format.

output_formatstr, optional

One of catalog, env, github-output, python-requirements, or summary.

extraslist of str, optional

Optional dependency groups included in python-requirements output.

Returns:
str

Serialized dependency configuration, including a trailing newline.

simtools.model_repository.dependency_versions.find_dependency_versions(start_path=None)[source]#

Find the dependency catalog matching the running simtools installation.

Parameters:
start_pathstr or Path, optional

Explicit search directory, taking precedence over bundled catalogs. By default, bundled catalogs take precedence over the working directory. SIMTOOLS_DEPENDENCY_VERSIONS overrides either lookup order.

Returns:
pathlib.Path

Path to the matching dependency_versions.yml file.

Raises:
FileNotFoundError

If an explicit environment override is missing or no catalog can be found.

simtools.model_repository.dependency_versions.find_pyproject(start_path=None)[source]#

Find the nearest pyproject.toml file.

simtools.model_repository.dependency_versions.load_dependency_catalog(catalog_path=None, validate=True)[source]#

Load the dependency version catalog from YAML.

Parameters:
catalog_pathstr or Path, optional

Explicit catalog file. The repository is searched when omitted.

validatebool, optional

Validate the catalog structure when True.

Returns:
dict

Dependency version catalog.

simtools.model_repository.dependency_versions.model_repository_revision(catalog)[source]#

Return the configured simulation-model repository ref or revision.

simtools.model_repository.dependency_versions.project_requirements(pyproject_path, extras)[source]#

Return project requirements, optionally including named extras.

simtools.model_repository.dependency_versions.validate_dependency_catalog(catalog)[source]#

Validate required dependency catalog values.

Parameters:
catalogdict

Dependency version catalog.

Returns:
dict

The validated catalog.

Raises:
ValueError

If a required value is missing or invalid.

simtools.model_repository.dependency_versions.validate_env_template(template_path)[source]#

Validate non-secret runtime defaults against the dependency catalog.

Parameters:
template_pathstr or Path

Environment template to validate.

Raises:
ValueError

If catalog-managed versions are duplicated in the template.

version#

Software version setting.

simtools.version.base_version_for_patch_delta(version_string)[source]#

Return major.minor.0 version for patch releases (x.y.z -> x.y.0) or None.

Parameters:
version_stringstr or None

Version string to inspect, or None.

Returns:
str or None

The base patch version for patch releases, or None for all other inputs.

simtools.version.check_version_constraint(version_string, constraint)[source]#

Check if a version satisfies a constraint.

Parameters:
version_stringstr

The version string to check (e.g., “6.0.2”).

constraintstr

The version constraint to check against (e.g., “>=6.0.0”).

Returns:
bool

True if the version satisfies the constraint, False otherwise.

simtools.version.compare_versions(version_string_1, version_string_2, level='major.minor.patch')[source]#

Compare two versions at the given level: “major”, “major.minor”, “major.minor.patch”.

Parameters:
version_string_1str

First version string to compare.

version_string_2str

Second version string to compare.

levelstr, optional

Level of comparison: “major”, “major.minor”, or “major.minor.patch”

Returns:
int
-1 if version_string_1 < version_string_2

0 if version_string_1 == version_string_2 1 if version_string_1 > version_string_2

simtools.version.is_valid_model_version(version_string)[source]#

Return whether a value is a bare simulation-model version.

Parameters:
version_stringstr

Version string to validate.

Returns:
bool

True when the value matches the simulation-model version format.

simtools.version.is_valid_package_version(version_string)[source]#

Return whether a value is a bare PEP 440 package version.

Parameters:
version_stringstr

Version string to validate.

Returns:
bool

True when the value is a valid non-v-prefixed PEP 440 version.

simtools.version.is_valid_release_tag(version_string)[source]#

Return whether a value is a v-prefixed semantic release tag.

Parameters:
version_stringstr

Version string to validate.

Returns:
bool

True when the value is a valid v-prefixed semantic release tag.

simtools.version.is_valid_revision(version_string)[source]#

Return whether a value is an exact lower-case Git revision.

Parameters:
version_stringstr

Revision string to validate.

Returns:
bool

True when the value is a valid lower-case Git revision hash.

simtools.version.is_valid_semantic_version(version_string, strict=True)[source]#

Check if a string is a valid semantic version.

Parameters:
version_stringstr

The version string to validate (e.g., “6.0.2”, “1.0.0-alpha”).

strictbool, optional

If True, use PEP 440 validation (packaging.version.Version). If False, use SemVer 2.0.0 regex pattern (allows more flexible pre-release identifiers).

Returns:
bool

True if the version string is valid, False otherwise.

simtools.version.resolve_by_version(config, model_version, preserve_inconsistent_keys=None)[source]#

Resolve version-dependent values in a configuration dictionary.

Fields whose value is a dict with a single by_version key are replaced by the first matching constraint value. All other fields are left unchanged.

Parameters:
configdict

Configuration dictionary (typically loaded from a YAML file).

model_versionstr or list

Semantic version string or list of strings used to evaluate constraints (e.g. “6.0.2” or [“6.0.2”, “6.1.1”]).

preserve_inconsistent_keysset, optional

Keys whose by_version mappings are retained when they resolve differently.

Returns:
dict

New dictionary with all by_version fields resolved to their matching value, or None when no constraint matches.

simtools.version.resolve_version_to_latest_patch(partial_version, available_versions)[source]#

Resolve a partial version (major.minor) to the latest patch version.

Given a partial version string (e.g., “6.0”) and a list of available versions, finds the latest patch version that matches the major.minor pattern.

Parameters:
partial_versionstr

Partial version string in format “major.minor” (e.g., “6.0”, “5.2”)

available_versionslist of str

List of available semantic versions (e.g., [“5.0.0”, “5.0.1”, “6.0.0”, “6.0.2”])

Returns:
str

Latest patch version matching the partial version pattern

Raises:
ValueError

If partial_version is not in major.minor format

ValueError

If no matching versions are found

Examples

>>> versions = ["5.0.0", "5.0.1", "6.0.0", "6.0.2", "6.1.0"]
>>> resolve_version_to_latest_patch("6.0", versions)
'6.0.2'
>>> resolve_version_to_latest_patch("5.0", versions)
'5.0.1'
>>> resolve_version_to_latest_patch("5.0.1", versions)
'5.0.1'
simtools.version.semver_to_int(version_string)[source]#

Convert a semantic version string to an integer.

Parameters:
version_stringstr

Semantic version string (e.g., “6.0.2”)

Returns:
int

Integer representation of the version (e.g., 60002 for “6.0.2”)

simtools.version.sort_versions(version_list, reverse=False)[source]#

Sort a list of semantic version strings.

Parameters:
version_listlist of str

List of semantic version strings (e.g., [“5.0.0”, “6.0.2”, “5.1.0”])

reversebool, optional

Sort in descending order if True (default False)

Returns:
list of str

Sorted list of version strings.

simtools.version.validate_release_tag(version_string)[source]#

Validate and return a v-prefixed semantic release tag.

Parameters:
version_stringstr

Release tag to validate.

Returns:
str

The unchanged release tag.

Raises:
ValueError

If version_string is not a v-prefixed semantic release tag.

simtools.version.version_kind(version_string)[source]#

Determine the kind of version string.

Parameters:
version_stringstr

The version string to analyze.

Returns:
str

The kind of version string (“major.minor”, “major.minor.patch”, or “major”).