diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-06-04 23:13:06 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-06-05 11:57:01 +0200 |
commit | 969ee9d85bb85b7aab2d21ebd1368c4ab2e90771 (patch) | |
tree | a6d930f13a3245e9542d3bbe7c9f9f16a14e5a1a /mesonbuild | |
parent | 1d0bd562f173b5a6c43ec50da4cba5fc5612783a (diff) | |
download | meson-969ee9d85bb85b7aab2d21ebd1368c4ab2e90771.zip meson-969ee9d85bb85b7aab2d21ebd1368c4ab2e90771.tar.gz meson-969ee9d85bb85b7aab2d21ebd1368c4ab2e90771.tar.bz2 |
typing: Fully annotate dependencies.configtool
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/dependencies/configtool.py | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/mesonbuild/dependencies/configtool.py b/mesonbuild/dependencies/configtool.py index d07b0c3..ed339c7 100644 --- a/mesonbuild/dependencies/configtool.py +++ b/mesonbuild/dependencies/configtool.py @@ -19,6 +19,11 @@ from .. import mlog import re import typing as T +from mesonbuild import mesonlib + +if T.TYPE_CHECKING: + from ..environment import Environment + class ConfigToolDependency(ExternalDependency): """Class representing dependencies found using a config tool. @@ -30,12 +35,12 @@ class ConfigToolDependency(ExternalDependency): Because some tools are stupid and don't return 0 """ - tools = None - tool_name = None + tools: T.Optional[T.List[str]] = None + tool_name: T.Optional[str] = None version_arg = '--version' __strip_version = re.compile(r'^[0-9][0-9.]+') - def __init__(self, name, environment, kwargs, language: T.Optional[str] = None): + def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any], language: T.Optional[str] = None): super().__init__('config-tool', environment, kwargs, language=language) self.name = name # You may want to overwrite the class version in some cases @@ -45,7 +50,11 @@ class ConfigToolDependency(ExternalDependency): if 'version_arg' in kwargs: self.version_arg = kwargs['version_arg'] - req_version = kwargs.get('version', None) + req_version_raw = kwargs.get('version', None) + if req_version_raw is not None: + req_version = mesonlib.stringlistify(req_version_raw) + else: + req_version = [] tool, version = self.find_config(req_version, kwargs.get('returncode_value', 0)) self.config = tool self.is_found = self.report_config(version, req_version) @@ -54,7 +63,7 @@ class ConfigToolDependency(ExternalDependency): return self.version = version - def _sanitize_version(self, version): + def _sanitize_version(self, version: str) -> str: """Remove any non-numeric, non-point version suffixes.""" m = self.__strip_version.match(version) if m: @@ -63,14 +72,12 @@ class ConfigToolDependency(ExternalDependency): return m.group(0).rstrip('.') return version - def find_config(self, versions: T.Optional[T.List[str]] = None, returncode: int = 0) \ - -> T.Tuple[T.Optional[str], T.Optional[str]]: + def find_config(self, versions: T.List[str], returncode: int = 0) \ + -> T.Tuple[T.Optional[T.List[str]], T.Optional[str]]: """Helper method that searches for config tool binaries in PATH and returns the one that best matches the given version requirements. """ - if not isinstance(versions, list) and versions is not None: - versions = listify(versions) - best_match = (None, None) # type: T.Tuple[T.Optional[str], T.Optional[str]] + best_match: T.Tuple[T.Optional[T.List[str]], T.Optional[str]] = (None, None) for potential_bin in find_external_program( self.env, self.for_machine, self.tool_name, self.tool_name, self.tools, allow_default_for_cross=False): @@ -105,14 +112,14 @@ class ConfigToolDependency(ExternalDependency): return best_match - def report_config(self, version, req_version): + def report_config(self, version: T.Optional[str], req_version: T.List[str]) -> bool: """Helper method to print messages about the tool.""" - found_msg = [mlog.bold(self.tool_name), 'found:'] + found_msg: T.List[T.Union[str, mlog.AnsiDecorator]] = [mlog.bold(self.tool_name), 'found:'] if self.config is None: found_msg.append(mlog.red('NO')) - if version is not None and req_version is not None: + if version is not None and req_version: found_msg.append(f'found {version!r} but need {req_version!r}') elif req_version: found_msg.append(f'need {req_version!r}') @@ -134,10 +141,10 @@ class ConfigToolDependency(ExternalDependency): return split_args(out) @staticmethod - def get_methods(): + def get_methods() -> T.List[DependencyMethods]: return [DependencyMethods.AUTO, DependencyMethods.CONFIG_TOOL] - def get_configtool_variable(self, variable_name): + def get_configtool_variable(self, variable_name: str) -> str: p, out, _ = Popen_safe(self.config + [f'--{variable_name}']) if p.returncode != 0: if self.required: @@ -148,7 +155,7 @@ class ConfigToolDependency(ExternalDependency): mlog.debug(f'Got config-tool variable {variable_name} : {variable}') return variable - def log_tried(self): + def log_tried(self) -> str: return self.type_name def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None, |