diff --git a/tracetools_launch/setup.cfg b/tracetools_launch/setup.cfg index 622fcba0..86ce32d0 100644 --- a/tracetools_launch/setup.cfg +++ b/tracetools_launch/setup.cfg @@ -2,3 +2,5 @@ script_dir=$base/lib/tracetools_launch [install] install_scripts=$base/lib/tracetools_launch +[mypy] +warn-unused-ignores = True diff --git a/tracetools_launch/tracetools_launch/action.py b/tracetools_launch/tracetools_launch/action.py index ffc38ecb..97ddeaf5 100644 --- a/tracetools_launch/tracetools_launch/action.py +++ b/tracetools_launch/tracetools_launch/action.py @@ -21,6 +21,7 @@ from typing import Dict from typing import Iterable from typing import List +from typing import Mapping from typing import Optional from typing import Text from typing import Union @@ -34,6 +35,7 @@ from launch.frontend import Parser from launch.launch_context import LaunchContext from launch.some_substitutions_type import SomeSubstitutionsType +from launch.substitution import Substitution from launch.substitutions import TextSubstitution from launch.utilities import normalize_to_list_of_substitutions from launch.utilities import perform_substitutions @@ -159,59 +161,62 @@ def __init__( self._base_path = base_path \ if base_path is None else normalize_to_list_of_substitutions(base_path) self._append_trace = append_trace - self._trace_directory = None + self._trace_directory: Optional[str] = None self._events_ust = [normalize_to_list_of_substitutions(x) for x in events_ust] self._events_kernel = [normalize_to_list_of_substitutions(x) for x in events_kernel] self._syscalls = [normalize_to_list_of_substitutions(x) for x in syscalls] - self._context_fields = \ + self._context_fields = ( { domain: [normalize_to_list_of_substitutions(field) for field in fields] for domain, fields in context_fields.items() - } \ - if isinstance(context_fields, dict) \ + } + if isinstance(context_fields, dict) else [normalize_to_list_of_substitutions(field) for field in context_fields] - self._ld_preload_actions: List[LdPreload] = [] + ) + self._ld_preload_actions: List[Action] = [] self._subbuffer_size_ust = subbuffer_size_ust self._subbuffer_size_kernel = subbuffer_size_kernel @property - def session_name(self): + def session_name(self) -> List[Substitution]: return self._session_name @property - def base_path(self): + def base_path(self) -> Optional[List[Substitution]]: return self._base_path @property - def append_trace(self): + def append_trace(self) -> bool: return self._append_trace @property - def trace_directory(self): + def trace_directory(self) -> Optional[str]: return self._trace_directory @property - def events_ust(self): + def events_ust(self) -> Iterable[List[Substitution]]: return self._events_ust @property - def events_kernel(self): + def events_kernel(self) -> Iterable[List[Substitution]]: return self._events_kernel @property - def syscalls(self): + def syscalls(self) -> Iterable[List[Substitution]]: return self._syscalls @property - def context_fields(self): + def context_fields( + self, + ) -> Union[Mapping[str, Iterable[List[Substitution]]], Iterable[List[Substitution]]]: return self._context_fields @property - def subbuffer_size_ust(self): + def subbuffer_size_ust(self) -> int: return self._subbuffer_size_ust @property - def subbuffer_size_kernel(self): + def subbuffer_size_kernel(self) -> int: return self._subbuffer_size_kernel @classmethod @@ -459,7 +464,7 @@ def _destroy(self, event: Event, context: LaunchContext) -> None: self._logger.debug(f'Finalizing tracing session: {self._session_name}') lttng.lttng_fini(session_name=self._session_name) - def __repr__(self): + def __repr__(self) -> Text: return ( 'Trace(' f'session_name={self._session_name}, ' diff --git a/tracetools_launch/tracetools_launch/actions/ld_preload.py b/tracetools_launch/tracetools_launch/actions/ld_preload.py index f2b53b85..463090cd 100644 --- a/tracetools_launch/tracetools_launch/actions/ld_preload.py +++ b/tracetools_launch/tracetools_launch/actions/ld_preload.py @@ -19,6 +19,7 @@ import subprocess from typing import List from typing import Optional +from typing import Text from launch import logging from launch.action import Action @@ -45,7 +46,7 @@ def __init__( """ super().__init__(**kwargs) self._lib_name = lib_name - self._env_action = None + self._env_action: Optional[Action] = None # Try to find lib self._lib_path = self.get_shared_lib_path(self._lib_name) # And create action if found @@ -65,9 +66,19 @@ def lib_name(self) -> str: @property def lib_path(self) -> Optional[str]: + """ + Get the resolved shared lib path, if found. + + :return: the full path to the shared lib if found, or `None` if not found + """ return self._lib_path def lib_found(self) -> bool: + """ + Check if the shared lib was found. + + :return: `True` if the shared lib was found, or `False` if not found + """ return self._env_action is not None def execute(self, context: LaunchContext) -> Optional[List[Action]]: @@ -113,7 +124,7 @@ def get_shared_lib_path(cls, lib_name: str) -> Optional[str]: shared_lib = shared_lib_paths[0] return shared_lib - def __repr__(self): + def __repr__(self) -> Text: return ( 'LdPreload(' f'lib_name={self._lib_name}, ' diff --git a/tracetools_read/setup.cfg b/tracetools_read/setup.cfg index de27ea5f..dae89709 100644 --- a/tracetools_read/setup.cfg +++ b/tracetools_read/setup.cfg @@ -2,3 +2,5 @@ script_dir=$base/lib/tracetools_read [install] install_scripts=$base/lib/tracetools_read +[mypy] +warn-unused-ignores = True diff --git a/tracetools_test/setup.cfg b/tracetools_test/setup.cfg index 24097e96..2b1f68c0 100644 --- a/tracetools_test/setup.cfg +++ b/tracetools_test/setup.cfg @@ -2,3 +2,5 @@ script_dir=$base/lib/tracetools_test [install] install_scripts=$base/lib/tracetools_test +[mypy] +warn-unused-ignores = True diff --git a/tracetools_test/tracetools_test/case.py b/tracetools_test/tracetools_test/case.py index c6681fc4..0ca4393b 100644 --- a/tracetools_test/tracetools_test/case.py +++ b/tracetools_test/tracetools_test/case.py @@ -86,7 +86,7 @@ def __init__( self._additional_actions = additional_actions or [] self._namespace = namespace - def setUp(self): + def setUp(self) -> None: # Get timestamp before trace (ns) timestamp_before = int(time.time() * 1000000000.0) @@ -133,7 +133,7 @@ def setUp(self): # Check that the launched nodes are present as processes self.assertProcessNamesExist(self._nodes) - def tearDown(self): + def tearDown(self) -> None: if not os.environ.get(self.ENV_VAR_DEBUG, None): cleanup_trace(self._full_path) diff --git a/tracetools_trace/setup.cfg b/tracetools_trace/setup.cfg index 855f7636..848d0db3 100644 --- a/tracetools_trace/setup.cfg +++ b/tracetools_trace/setup.cfg @@ -2,3 +2,5 @@ script_dir=$base/lib/tracetools_trace [install] install_scripts=$base/lib/tracetools_trace +[mypy] +warn-unused-ignores = True