Application, dependency and version management.#
application_control#
Application control utilities for startup and shutdown simtools applications.
- class simtools.application_control.ApplicationContext(args: dict, db_config: dict, logger: Logger, io_handler: IOHandler | None)[source]#
Container for common application context elements.
- simtools.application_control.get_application_label(file_path)[source]#
Get application label from file path.
This is a convenience function to extract the application name from __file__.
- Parameters:
- file_pathstr
The __file__ variable from the calling application.
- Returns:
- str
Application label (filename without extension).
- simtools.application_control.startup_application(parse_function, setup_io_handler=True, logger_name=None)[source]#
Initialize common application startup tasks.
This function handles the repetitive startup tasks common to most simtools applications:
Parse command line arguments and configuration
Set up logging with appropriate level
Optionally initialize IOHandler
- Parameters:
- parse_functionCallable
Function that parses configuration and returns (args_dict, db_config) tuple. This should be the application’s _parse() function.
- setup_io_handlerbool, optional
Whether to initialize and return an IOHandler instance. Default is True.
- logger_namestr, optional
Name for the logger. If None, uses the root logger. Default is None.
- Returns:
- args_dictdict
Parsed command line arguments and configuration.
- db_configdict
Database configuration dictionary.
- loggerlogging.Logger
Configured logger instance.
- io_handler_instanceio_handler.IOHandler or None
IOHandler instance if setup_io_handler=True, None otherwise.
dependencies#
Simtools dependencies version management.
This modules provides two main functionalities:
retrieve the versions of simtools dependencies (e.g., databases, sim_telarray, CORSIKA)
provide space for future implementations of version management
- dependencies.get_build_options(run_time=None)[source]#
Return CORSIKA / sim_telarray build options.
Expects a build_opts.yml file in the sim_telarray directory.
- Parameters:
- run_timelist, optional
Runtime environment command (e.g., Docker).
- Returns:
- dict
Build options from build_opts.yml file.
- dependencies.get_corsika_version(run_time=None)[source]#
Get the version of the CORSIKA package.
- Parameters:
- run_timelist, optional
Runtime environment command (e.g., Docker).
- Returns:
- str
Version of the CORSIKA package.
- dependencies.get_database_version_or_name(db_config, version=True)[source]#
Get the version or name of the simulation model data base used.
- Parameters:
- db_configdict
Dictionary containing the database configuration.
- versionbool
If True, return the version of the database. If False, return the name.
- Returns:
- str
Version or name of the simulation model data base used.
- dependencies.get_sim_telarray_version(run_time)[source]#
Get the version of the sim_telarray package using ‘sim_telarray –version’.
- Parameters:
- run_timelist, optional
Runtime environment command (e.g., Docker).
- Returns:
- str
Version of the sim_telarray package.
- dependencies.get_version_string(db_config=None, run_time=None)[source]#
Print the versions of the dependencies.
- Parameters:
- db_configdict, optional
Database configuration dictionary.
- run_timelist, optional
Runtime environment command (e.g., Docker).
- Returns:
- str
String containing the versions of the dependencies.
version#
Software version setting.
- 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
- 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'
- 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”)
- 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.