diff --git a/CMakeLists.txt b/CMakeLists.txt index e69f9619..97192c54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,3 +16,5 @@ daq_add_application(create_config_plot create_config_plot.cxx GraphBuilder.cpp L daq_add_unit_test(Graph_test) daq_install() + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python/ DESTINATION ${CMAKE_INSTALL_PYTHONDIR} OPTIONAL FILES_MATCHING PATTERN "py.typed" PATTERN "*.pyi") diff --git a/python/daqconf/assets.py b/python/daqconf/assets.py index cc3b3c41..c8562a67 100644 --- a/python/daqconf/assets.py +++ b/python/daqconf/assets.py @@ -1,12 +1,29 @@ -from os.path import exists,abspath,dirname,expandvars +from os.path import exists, abspath, dirname, expandvars +from urllib.parse import urlparse, parse_qsl from daq_assettools.asset_file import AssetFile from daq_assettools.asset_database import Database from sqlite3 import OperationalError -def resolve_asset_file(data_file, verbose = False): - from urllib.parse import urlparse, parse_qsl + +def resolve_asset_file(data_file: str, verbose: bool = False) -> str: + """ + Resolves a data file URI to an absolute file path. The data file can be specified as + - An asset URI (e.g., asset://?name=frames) + - A file URI (e.g., file:///path/to/frames.bin) + - A local file path (e.g., /path/to/frames.bin) + + Args: + data_file (str): The data file URI or path to resolve. + verbose (bool): If True, prints additional information during resolution. + + Returns: + str: The absolute path to the resolved data file. + + Raises: + RuntimeError: If the data file cannot be found or resolved. + """ data_file_url = urlparse(data_file) if verbose: @@ -14,16 +31,23 @@ def resolve_asset_file(data_file, verbose = False): if data_file_url.scheme == 'asset': asset_query = dict(parse_qsl(data_file_url.query)) - asset_db = Database('/cvmfs/dunedaq.opensciencegrid.org/assets/dunedaq-asset-db.sqlite') + asset_db = Database( + '/cvmfs/dunedaq.opensciencegrid.org/assets/dunedaq-asset-db.sqlite' + ) asset_query['status'] = 'valid' try: files = asset_db.get_files(asset_query) if not files: - raise RuntimeError(f"Couldn\'t find a valid asset for the query {data_file_url.query}") + raise RuntimeError( + f"Couldn\'t find a valid asset for the query {data_file_url.query}" + ) elif len(files)>1: - print(f"Found {len(files)} assets in {dirname(asset_db.database_file)}, taking the first one") + print( + f"Found {len(files)} assets in {dirname(asset_db.database_file)}, " + "taking the first one" + ) if verbose: print(f"Found asset in {dirname(asset_db.database_file)}") diff --git a/python/daqconf/cider/data_structures/configuration_handler.py b/python/daqconf/cider/data_structures/configuration_handler.py index 941f6895..ac66273e 100644 --- a/python/daqconf/cider/data_structures/configuration_handler.py +++ b/python/daqconf/cider/data_structures/configuration_handler.py @@ -1,5 +1,5 @@ import os -from typing import Any, Dict, List +from typing import Dict, List import conffwk @@ -43,11 +43,11 @@ def __cache_all_conf_objects(self)->None: self._loaded_dals.append(conf_obj) #============================== Getters + Setters ==============================# - def get_relationships_for_conf_object(self, conf_object)->List[Any]: + def get_relationships_for_conf_object(self, conf_object: object) -> List[Dict[str, object]]: """For a given configuration object, return all related objects Arguments: - conf_object -- Any DAL object + conf_object -- configuration DAL object Returns: List of related objects @@ -67,7 +67,7 @@ def get_relationships_for_conf_object(self, conf_object)->List[Any]: return relations_list - def get_conf_objects_class(self, conf_class: str): + def get_conf_objects_class(self, conf_class: str) -> List[object]: """Get all configuration objects of a given class Arguments: @@ -78,7 +78,7 @@ def get_conf_objects_class(self, conf_class: str): """ return self._configuration.get_dals(conf_class) - def get_all_conf_classes(self)->Dict[str, Any]: + def get_all_conf_classes(self) -> Dict[str, List[object]]: """Gets all classes + objects of that class in the configuration Returns: @@ -122,7 +122,7 @@ def conf_obj_list(self): """ return self._loaded_dals - def get_obj(self, class_id: str, uid: str): + def get_obj(self, class_id: str, uid: str) -> object: """Get a particular configuration object Arguments: @@ -134,7 +134,7 @@ def get_obj(self, class_id: str, uid: str): """ return self.configuration.get_obj(class_id, uid) - def commit(self, update_message: str): + def commit(self, update_message: str) -> None: """Commit changes to the database Arguments: @@ -149,7 +149,7 @@ def n_dals(self)->int: """ return len(self._loaded_dals) - def add_new_conf_obj(self, class_id: str, uid: str): + def add_new_conf_obj(self, class_id: str, uid: str) -> None: """Add new configuration object Arguments: @@ -161,7 +161,7 @@ def add_new_conf_obj(self, class_id: str, uid: str): self.configuration.update_dal(config_as_dal) self._loaded_dals.append(config_as_dal) - def destroy_conf_obj(self, class_id: str, uid: str): + def destroy_conf_obj(self, class_id: str, uid: str) -> None: """Destroy a configuration object Arguments: @@ -172,8 +172,14 @@ def destroy_conf_obj(self, class_id: str, uid: str): self.configuration.destroy_dal(dal) self._loaded_dals.remove(dal) - def modify_relationship(self, class_id, uid, relationship_name: str, updated_value, - append: bool=False): + def modify_relationship( + self, + class_id: str, + uid: str, + relationship_name: str, + updated_value: object, + append: bool = False, + ) -> None: """Modify TODO: EDIT THIS :param class_id: _description_ diff --git a/python/daqconf/cider/widgets/modify_config_relations.py b/python/daqconf/cider/widgets/modify_config_relations.py index 23c4a073..536dc0e6 100644 --- a/python/daqconf/cider/widgets/modify_config_relations.py +++ b/python/daqconf/cider/widgets/modify_config_relations.py @@ -8,15 +8,19 @@ from textual.containers import VerticalScroll from rich.console import RichCast, ConsoleRenderable -from typing import Any +from typing import Protocol from daqconf.cider.widgets.configuration_controller import ConfigurationController from daqconf.cider.widgets.custom_rich_log import RichLogWError +class RelatedDal(Protocol): + def __repr__(self) -> str: ... + + class SingleRelationshipModifier(Static): - def __init__(self, relationship_type: str, current_related_dal: Any, relationship_name: str, + def __init__(self, relationship_type: str, current_related_dal: RelatedDal | object, relationship_name: str, renderable: ConsoleRenderable | RichCast | str = "", *, expand: bool = False, shrink: bool = False, markup: bool = True, name: str | None = None, id: str | None = None, classes: str | None = None, disabled: bool = False) -> None: diff --git a/python/daqconf/cider/widgets/popups/edit_cell_screen.py b/python/daqconf/cider/widgets/popups/edit_cell_screen.py index 83c24d7d..006800f0 100644 --- a/python/daqconf/cider/widgets/popups/edit_cell_screen.py +++ b/python/daqconf/cider/widgets/popups/edit_cell_screen.py @@ -5,17 +5,21 @@ from textual.widgets import Input, Label from textual.containers import Container -from typing import Any +from typing import Protocol from daqconf.cider.widgets.configuration_controller import ConfigurationController +class TableCellEvent(Protocol): + row_key: object + + class EditCellScreen(ModalScreen): css_file_path = f"{environ.get('DAQCONF_SHARE')}/config/textual_dbe/textual_css" CSS_PATH = f"{css_file_path}/edit_cell_layout.tcss" def __init__( - self, event: Any, name: str | None = None, id: str | None = None, classes: str | None = None) -> None: + self, event: TableCellEvent, name: str | None = None, id: str | None = None, classes: str | None = None) -> None: super().__init__(name=name, id=id, classes=classes) """Screen which pops up when a cell is clicked in the ConfigTable """ diff --git a/python/daqconf/cider/widgets/selection_menu.py b/python/daqconf/cider/widgets/selection_menu.py index c88917c8..58493b44 100644 --- a/python/daqconf/cider/widgets/selection_menu.py +++ b/python/daqconf/cider/widgets/selection_menu.py @@ -1,4 +1,3 @@ -from typing import Any import numpy as np from textual.widgets import Static, Tree diff --git a/python/daqconf/consolidate.py b/python/daqconf/consolidate.py index 8603ba86..66509e85 100755 --- a/python/daqconf/consolidate.py +++ b/python/daqconf/consolidate.py @@ -7,7 +7,20 @@ log = getLogger('daqconf.consolidate') -def get_all_includes(db, file): +def get_all_includes(db: conffwk.Configuration, file: str) -> list[str]: + """ + Recursively get all includes from an OKS database + + Args: + db (conffwk.Configuration): The OKS database to get includes from + file (str): The file to get includes from + + Returns: + list(str): A list of all includes in the database + + Raises: + None + """ includes = db.get_includes(file) for include in includes: if "data.xml" not in include: @@ -16,12 +29,26 @@ def get_all_includes(db, file): return list(set(includes)) -def consolidate_db(oksfile: str, output_file: str, session_id: Optional[str] = None)->None: - """Consolidates a single session +def consolidate_db( + oksfile: str, output_file: str, session_id: Optional[str] = None +) -> None: + """ + Consolidates a session database files into a single file. + + The consolidated file contains all the schema and data required to define the entire + session. If session_id is None, all sessions will be consolidated into the single + output file. + + Args: + oksfile: OKS file(s) to consolidate + output_file: File to output consolidated database to + session_id: Name of session, defaults to None + + Returns: + None - :param oksfile: OKS file(s) to consolidate - :param output_file: File to output consolidated database to - :param session_id: Name of session, defaults to None + Raises: + None """ log.info(f"Consolidating database into output database '{output_file}'. Input database: '{oksfile}'.") @@ -38,13 +65,16 @@ def consolidate_db(oksfile: str, output_file: str, session_id: Optional[str] = N def create_copy_template(oksfile: str, output_file: str)->Tuple[conffwk.Configuration, conffwk.Configuration]: - ''' - Creates a blank oks .data.xml file stored in output_file with all the schema includes of oksfile - :param oksfile: OKS file to copy includes from - :param output_file: OKS file to copy includes into + """ + Create a blank oks .data.xml template file with all the schema includes of oksfile. - :returns: Tuple of old_db, copied_db - ''' + Args: + oksfile: OKS file to copy includes from + output_file: OKS file to copy includes into + + Returns: + Tuple of old_db, copied_db + """ log.debug("Reading database") db = conffwk.Configuration("oksconflibs:" + oksfile) @@ -89,7 +119,7 @@ def consolidate_session(db: conffwk.Configuration, new_db: conffwk.Configuration dal_list = get_relationships(db, dal_session, []) copy_dals_to_cfg(new_db, dal_list) -def get_relationships(db: conffwk.Configuration, current_dal, dal_list): +def get_relationships(db: conffwk.Configuration, current_dal: conffwk.Configuration, dal_list: list[conffwk.Configuration]) -> list[conffwk.Configuration]: ''' Recurssively get all objects related to current_dal ''' @@ -109,7 +139,7 @@ def get_relationships(db: conffwk.Configuration, current_dal, dal_list): return dal_list -def copy_dals_to_cfg(new_db: conffwk.Configuration, dal_list)->None: +def copy_dals_to_cfg(new_db: conffwk.Configuration, dal_list: list[conffwk.Configuration]) -> None: ''' Copy a list of dals into a configuration ''' @@ -121,7 +151,7 @@ def copy_dals_to_cfg(new_db: conffwk.Configuration, dal_list)->None: new_db.commit() -def copy_configuration(dest_dir : Path, input_files: list): +def copy_configuration(dest_dir : Path, input_files: list[conffwk.Configuration]) -> list[conffwk.Configuration]: if len(input_files) == 0: return [] @@ -157,7 +187,7 @@ def copy_configuration(dest_dir : Path, input_files: list): return output_dbs -def consolidate_files(oksfile, *input_files): +def consolidate_files(oksfile: str, *input_files) -> None: includes = [] dbs = [] str_in_files = '\n'.join(input_files) diff --git a/python/daqconf/createOKSdb.py b/python/daqconf/createOKSdb.py index 5f7068df..8030b1ee 100755 --- a/python/daqconf/createOKSdb.py +++ b/python/daqconf/createOKSdb.py @@ -3,7 +3,7 @@ import glob -def generate_file(oksfile, include): +def generate_file(oksfile: str, include: list[str]) -> None: """Simple script to create an 'empty' OKS file. The file will automatically include the confmodel schema and any other OKS files you specify""" diff --git a/python/daqconf/dal_helpers.py b/python/daqconf/dal_helpers.py index 1446f09d..35860e4a 100644 --- a/python/daqconf/dal_helpers.py +++ b/python/daqconf/dal_helpers.py @@ -3,25 +3,25 @@ ## # Dal helpers # -def get_attribute_info(o): +def get_attribute_info(o: object) -> dict[str, object]: return o.__schema__['attribute'] -def get_relation_info(o): +def get_relation_info(o: object) -> dict[str, object]: return o.__schema__['relation'] -def get_attribute_list(o): +def get_attribute_list(o: object) -> list[str]: return list(get_attribute_info(o)) -def get_relation_list(o): +def get_relation_list(o: object) -> list[str]: return list(get_relation_info(o)) -def get_superclass_list(o): +def get_superclass_list(o: object) -> list[str]: return o.__schema__['superclass'] -def get_subclass_list(o): +def get_subclass_list(o: object) -> list[str]: return o.__schema__['subclass'] -def compare_dal_obj(a, b): +def compare_dal_obj(a: object, b: object) -> bool: """Compare two dal objects by content""" # TODO: add a check on a and b being dal objects @@ -45,7 +45,7 @@ def compare_dal_obj(a, b): #--------------- -def find_related(dal_obj, dal_group: set): +def find_related(dal_obj: object, dal_group: set[object]) -> None: rels = get_relation_list(dal_obj) @@ -71,7 +71,7 @@ def find_related(dal_obj, dal_group: set): find_related(o, dal_group) from collections.abc import Iterable -def find_duplicates( collection: Iterable ): +def find_duplicates(collection: Iterable[object]) -> set[object]: """ Find duplicated dal objects in a collection by comparing objects attributes and relationships """ diff --git a/python/daqconf/dromap2oks.py b/python/daqconf/dromap2oks.py index 0c87f4cf..64592419 100755 --- a/python/daqconf/dromap2oks.py +++ b/python/daqconf/dromap2oks.py @@ -3,7 +3,13 @@ import json import sys -def dro_json_to_oks(jsonfile, oksfile, source_id_offset, nomap, lcores): +def dro_json_to_oks( + jsonfile: str, + oksfile: str, + source_id_offset: int, + nomap: bool, + lcores: str, +) -> None: """Simple script to convert a JSON readout map file to an OKS file.""" group_name = os.path.basename(jsonfile).removesuffix(".json") diff --git a/python/daqconf/enable.py b/python/daqconf/enable.py index 138f472c..80703f92 100755 --- a/python/daqconf/enable.py +++ b/python/daqconf/enable.py @@ -5,7 +5,7 @@ import glob -def enable(oksfile, disable, resource, session_name): +def enable(oksfile: str, disable: bool, resource: list[str], session_name: str) -> None: """Script to enable or disable (-d) Resources from the first Session of the specified OKS database file""" db = conffwk.Configuration("oksconflibs:" + oksfile) diff --git a/python/daqconf/enable_tpg.py b/python/daqconf/enable_tpg.py index cfcf59c0..279ab417 100755 --- a/python/daqconf/enable_tpg.py +++ b/python/daqconf/enable_tpg.py @@ -5,7 +5,7 @@ import os import glob -def get_segment_apps(segment): +def get_segment_apps(segment: object) -> list[str]: apps = [] for ss in segment.segments: @@ -16,7 +16,7 @@ def get_segment_apps(segment): return apps -def enable_tpg(oksfile, disable, session_name): +def enable_tpg(oksfile: str, disable: bool, session_name: str) -> None: """Script to enable or disable (-d) TP generation in ReadoutApplications of the specified OKS configuration""" db = conffwk.Configuration("oksconflibs:" + oksfile) diff --git a/python/daqconf/generate.py b/python/daqconf/generate.py index 86a7ae96..26986e40 100755 --- a/python/daqconf/generate.py +++ b/python/daqconf/generate.py @@ -8,14 +8,14 @@ def generate_dataflow( - oksfile, - include, - n_dfapps, - tpwriting_enabled, - generate_segment, - n_data_writers=1, - trmon_app=False, -): + oksfile: str, + include: list[str], + n_dfapps: int, + tpwriting_enabled: bool, + generate_segment: bool, + n_data_writers: int = 1, + trmon_app: bool = False, +) -> None: """Simple script to create an OKS configuration file for a dataflow segment. The file will automatically include the relevant schema files and @@ -233,10 +233,10 @@ def generate_dataflow( def generate_hsi( - oksfile, - include, - generate_segment, -): + oksfile: str, + include: list[str], + generate_segment: bool, +) -> None: """Simple script to create an OKS configuration file for a FakeHSI segment. The file will automatically include the relevant schema files and @@ -361,14 +361,14 @@ def generate_hsi( def generate_readout( - readoutmap, - oksfile, - include, - generate_segment, - emulated_file_name, - tpg_enabled=True, - hosts_to_use=[], -): + readoutmap: str, + oksfile: str, + include: list[str], + generate_segment: bool, + emulated_file_name: str, + tpg_enabled: bool = True, + hosts_to_use: list[str] = [], +) -> None: """Simple script to create an OKS configuration file for all ReadoutApplications defined in a readout map. @@ -793,8 +793,14 @@ def generate_readout( def generate_fakedata( - oksfile, include, generate_segment, n_streams, n_apps, det_id, fragment_type=None -): + oksfile: str, + include: list[str], + generate_segment: bool, + n_streams: int, + n_apps: int, + det_id: int, + fragment_type: str | None = None, +) -> None: """Simple script to create an OKS configuration file for a FakeDataProd-based readout segment. The file will automatically include the relevant schema files and @@ -946,12 +952,12 @@ def generate_fakedata( def generate_trigger( - oksfile, - include, - generate_segment, - tpg_enabled=True, - hsi_enabled=False, -): + oksfile: str, + include: list[str], + generate_segment: bool, + tpg_enabled: bool = True, + hsi_enabled: bool = False, +) -> None: """Simple script to create an OKS configuration file for a trigger segment. The file will automatically include the relevant schema files and @@ -1122,13 +1128,13 @@ def generate_trigger( def generate_session( - oksfile, - include, - session_name, - op_env, - connectivity_service_is_infrastructure_app=True, - disable_connectivity_service=False, -): + oksfile: str, + include: list[str], + session_name: str, + op_env: str, + connectivity_service_is_infrastructure_app: bool = True, + disable_connectivity_service: bool = False, +) -> None: """Simple script to create an OKS configuration file for a session. The file will automatically include the relevant schema files and diff --git a/python/daqconf/generate_hwmap.py b/python/daqconf/generate_hwmap.py index ea3f465d..0ba30579 100755 --- a/python/daqconf/generate_hwmap.py +++ b/python/daqconf/generate_hwmap.py @@ -5,8 +5,17 @@ import json import sys -def generate_hwmap(oksfile, n_streams, n_apps = 1, det_id = 3, app_host = "localhost", - eth_protocol = "udp", flx_mode = "fix_rate", crate_id_offset = 1, slot_id = 0): +def generate_hwmap( + oksfile: str, + n_streams: int, + n_apps: int = 1, + det_id: int = 3, + app_host: str = "localhost", + eth_protocol: str = "udp", + flx_mode: str = "fix_rate", + crate_id_offset: int = 1, + slot_id: int = 0, +) -> None: schemafiles = [ "schema/confmodel/dunedaq.schema.xml", diff --git a/python/daqconf/get_session_apps.py b/python/daqconf/get_session_apps.py index 490415f9..87549d9b 100755 --- a/python/daqconf/get_session_apps.py +++ b/python/daqconf/get_session_apps.py @@ -5,7 +5,7 @@ import glob -def get_segment_apps(segment): +def get_segment_apps(segment: object) -> list[str]: apps = [] for ss in segment.segments: @@ -17,7 +17,7 @@ def get_segment_apps(segment): return apps -def get_session_apps(oksfile, session_name=""): +def get_session_apps(oksfile: str, session_name: str = "") -> list[str] | None: """Get the apps defined in the given session""" session_db = conffwk.Configuration("oksconflibs:" + oksfile) if session_name == "": @@ -38,7 +38,7 @@ def get_session_apps(oksfile, session_name=""): return get_segment_apps(segment) -def get_database_apps(oksfile): +def get_database_apps(oksfile: str) -> dict[str, list[str]]: output = {} session_db = conffwk.Configuration("oksconflibs:" + oksfile) diff --git a/python/daqconf/get_session_env_var.py b/python/daqconf/get_session_env_var.py index 4a27d44c..451d0c12 100755 --- a/python/daqconf/get_session_env_var.py +++ b/python/daqconf/get_session_env_var.py @@ -2,7 +2,9 @@ import confmodel_dal import sys -def get_session_env_var(oksfile, session_name, requested_env_var_name): +def get_session_env_var( + oksfile: str, session_name: str, requested_env_var_name: str +) -> str | None: """Script to get the value of an environment variable in the specified Session of the specified OKS database file""" db = conffwk.Configuration("oksconflibs:" + oksfile) diff --git a/python/daqconf/jsonify.py b/python/daqconf/jsonify.py index 318c2c99..e0bd08cf 100644 --- a/python/daqconf/jsonify.py +++ b/python/daqconf/jsonify.py @@ -6,12 +6,12 @@ log = getLogger('daqconf.jsonify') -def hash_function(obj): +def hash_function(obj: object) -> int: # I guess we could get ObjectId from MongoDB return hash(f'{obj.id}@{obj.className()}') -def convert_to_dict(db, obj): +def convert_to_dict(db: conffwk.Configuration, obj: object) -> dict[str, str | int]: dal_dict = { "__type": obj.className(), "_id": { @@ -46,7 +46,7 @@ def convert_to_dict(db, obj): return dict(sorted(dal_dict.items())) -def jsonify_xml_data(oksfile, output): +def jsonify_xml_data(oksfile: str, output: str) -> None: sys.setrecursionlimit(10000) diff --git a/python/daqconf/oks_format.py b/python/daqconf/oks_format.py index a2e0330a..953f7e29 100644 --- a/python/daqconf/oks_format.py +++ b/python/daqconf/oks_format.py @@ -1,7 +1,7 @@ import conffwk import oks -def oks_format(input_file) -> None: +def oks_format(input_file: str) -> None: if ".data.xml" in input_file: print(f"Formatting database file {input_file}") dal = conffwk.dal.module("generated", "schema/confmodel/dunedaq.schema.xml") diff --git a/python/daqconf/py.typed b/python/daqconf/py.typed new file mode 100644 index 00000000..e69de29b diff --git a/python/daqconf/rename_duplicate_dals.py b/python/daqconf/rename_duplicate_dals.py index eadd240f..214e85a7 100644 --- a/python/daqconf/rename_duplicate_dals.py +++ b/python/daqconf/rename_duplicate_dals.py @@ -1,7 +1,7 @@ """ HW: Finds non-unique DAL objects and provides a simple CLI to rename them iteratively """ -from typing import List, Dict, Any, Set +from typing import Dict, List, Set from collections import defaultdict from pathlib import Path from itertools import combinations @@ -35,11 +35,11 @@ def __init__(self, db: Configuration | str): if isinstance(db, str): db = Configuration("oksconflibs:" + db) self.db = db - self._relations_cache: Dict[str, Any] = {} - self._parents_cache: Dict[Any, list] = {} + self._relations_cache: Dict[str, List[str]] = {} + self._parents_cache: Dict[DalBase, List[DalBase]] = {} self.graph = self._build_graph() - def _relations(self, class_name: str): + def _relations(self, class_name: str) -> List[str]: if class_name not in self._relations_cache: self._relations_cache[class_name] = self.db.relations(class_name, all=True) return self._relations_cache[class_name] @@ -74,7 +74,7 @@ def __init__(self, dal: DalBase, config: Configuration, tree: RelationshipCache) self.dal = dal self.config = config self.tree = tree - self._attributes: Dict[str, Any] | None = None + self._attributes: Dict[str, object] | None = None self._relations: Dict[str, Set[str]] | None = None @property @@ -82,7 +82,7 @@ def id(self) -> str: return self.dal.id @property - def attributes(self) -> Dict[str, Any]: + def attributes(self) -> Dict[str, object]: if self._attributes is None: self._attributes = { a: getattr(self.dal, a, None) diff --git a/python/daqconf/rename_session.py b/python/daqconf/rename_session.py index 35ddeb4e..2070eecb 100644 --- a/python/daqconf/rename_session.py +++ b/python/daqconf/rename_session.py @@ -1,7 +1,9 @@ import conffwk import copy -def rename_session(oksfile,output_name,session_name=None): +def rename_session( + oksfile: str, output_name: str, session_name: str | None = None +) -> None: """Script to rename the session (first session if multiple and not specified)""" db = conffwk.Configuration('oksconflibs:'+oksfile) diff --git a/python/daqconf/session.py b/python/daqconf/session.py index 393fa35f..333b79e7 100644 --- a/python/daqconf/session.py +++ b/python/daqconf/session.py @@ -1,6 +1,6 @@ import conffwk -def get_segment_apps(segment): +def get_segment_apps(segment: object) -> list[object]: """ Gather the list of applications in the segment and its sub-segments """ @@ -17,7 +17,7 @@ def get_segment_apps(segment): return apps -def get_session_apps(confdb, session_name=""): +def get_session_apps(confdb: conffwk.Configuration, session_name: str = "") -> list[object] | None: """ Gather the apps defined used in a session. """ @@ -39,7 +39,7 @@ def get_session_apps(confdb, session_name=""): return get_segment_apps(segment) -def get_apps_in_any_session(confdb): +def get_apps_in_any_session(confdb: conffwk.Configuration) -> dict[str, list[object]]: """ Gather the applications used in any session present in the database """ @@ -57,7 +57,12 @@ def get_apps_in_any_session(confdb): return output -def enable_resource_in_session(db, session_name: str, resource: list[str], disable: bool): +def enable_resource_in_session( + db: conffwk.Configuration, + session_name: str, + resource: list[str], + disable: bool, +) -> None: """Script to enable or disable (-d) Resources from the first Session of the specified OKS database file""" if session_name == "": diff --git a/python/daqconf/set_connectivity_service_port.py b/python/daqconf/set_connectivity_service_port.py index 578d5442..10537173 100755 --- a/python/daqconf/set_connectivity_service_port.py +++ b/python/daqconf/set_connectivity_service_port.py @@ -2,7 +2,9 @@ import confmodel_dal from daqconf.utils import find_free_port -def set_connectivity_service_port(oksfile, session_name, connsvc_port=0): +def set_connectivity_service_port( + oksfile: str, session_name: str, connsvc_port: int = 0 +) -> int: """Script to set the value of the Connectivity Service port in the specified Session of the specified OKS database file. If the new port is not specified, it is set to a random available k8s NodePort.""" db = conffwk.Configuration("oksconflibs:" + oksfile) diff --git a/python/daqconf/set_rc_controller_port.py b/python/daqconf/set_rc_controller_port.py index 94b32a80..3a3cce04 100644 --- a/python/daqconf/set_rc_controller_port.py +++ b/python/daqconf/set_rc_controller_port.py @@ -3,7 +3,7 @@ from daqconf.utils import find_free_port import sys -def set_rc_controller_port(oksfile, session_name, rc_port=0): +def set_rc_controller_port(oksfile: str, session_name: str, rc_port: int = 0) -> int: """ Script to set the value of the RC Controller Service port used by the specified Session in the specified OKS database file. If the new port is not specified, diff --git a/python/daqconf/set_session_env_var.py b/python/daqconf/set_session_env_var.py index b6be6731..8cc3a52c 100755 --- a/python/daqconf/set_session_env_var.py +++ b/python/daqconf/set_session_env_var.py @@ -2,7 +2,13 @@ import confmodel_dal import sys -def set_session_env_var(oksfile, session_name, requested_env_var_name, requested_env_var_value, overwrite=True): +def set_session_env_var( + oksfile: str, + session_name: str, + requested_env_var_name: str, + requested_env_var_value: str, + overwrite: bool = True, +) -> None: """Script to set the value of an environment variable in the specified Session of the specified OKS database file""" db = conffwk.Configuration("oksconflibs:" + oksfile) diff --git a/python/daqconf/utils.py b/python/daqconf/utils.py index b245dda6..77c4b708 100755 --- a/python/daqconf/utils.py +++ b/python/daqconf/utils.py @@ -9,7 +9,7 @@ log_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] -def setup_logging(level:str="INFO"): +def setup_logging(level: str = "INFO") -> None: level = level.upper() loglevel = logging.INFO @@ -35,7 +35,7 @@ def setup_logging(level:str="INFO"): logging.getLogger().setLevel(loglevel) -def find_oksincludes(includes:list[str], extra_dirs:list[str] = []): +def find_oksincludes(includes: list[str], extra_dirs: list[str] = []) -> list[object]: includefiles = [] searchdirs = [path for path in os.environ["DUNEDAQ_DB_PATH"].split(":")] @@ -90,7 +90,7 @@ def find_oksincludes(includes:list[str], extra_dirs:list[str] = []): # This function returns a random available network port. Users can optionally # specify a range that should be used. -def find_free_port(min_port_num:int=0, max_port_num:int=65535): +def find_free_port(min_port_num: int = 0, max_port_num: int = 65535) -> int: # If the user didn't specify a minimum port number (or deliberately specified # zero), we can simply ask the system for an available port. if min_port_num == 0: diff --git a/python/daqconf/validate.py b/python/daqconf/validate.py index 7156d542..05255157 100644 --- a/python/daqconf/validate.py +++ b/python/daqconf/validate.py @@ -2,7 +2,7 @@ import confmodel_dal -def compare_objects(obj1, obj2): +def compare_objects(obj1: object, obj2: object) -> bool: """ Compare 2 dal objects for equality attribute by attribute """ same = True if type(obj1) != type(obj2): @@ -31,7 +31,7 @@ def compare_objects(obj1, obj2): -def check_unique_relationship(objects, relationship): +def check_unique_relationship(objects: list[object], relationship: str) -> bool: """ Check to see if the given relationship (by class name) is unique among a list of objects. First by comparing the UIDs, then by @@ -66,7 +66,7 @@ def check_unique_relationship(objects, relationship): return unique -def validate_readout(db, session): +def validate_readout(db: conffwk.Configuration, session: object) -> int: errcount = 0 # Find all enabled readout apps and check that # DetectorToDaqConnection's are unique @@ -133,7 +133,7 @@ def validate_readout(db, session): return errcount -def validate_session(oksfile, session_name): +def validate_session(oksfile: str, session_name: str) -> None: db = conffwk.Configuration("oksconflibs:" + oksfile) if session_name == "": session_dals = db.get_dals(class_name="Session")