typing: fix dependencies for new follow_imports

pull/7657/head
Daniel Mensinger 4 years ago
parent b57a355426
commit 62f7642a61
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 22
      mesonbuild/dependencies/base.py
  2. 2
      mesonbuild/dependencies/hdf5.py
  3. 7
      mesonbuild/dependencies/mpi.py
  4. 2
      mesonbuild/mesonlib.py

@ -114,11 +114,11 @@ class Dependency:
def __init__(self, type_name, kwargs):
self.name = "null"
self.version = None
self.version = None # type: T.Optional[str]
self.language = None # None means C-like
self.is_found = False
self.type_name = type_name
self.compile_args = []
self.compile_args = [] # type: T.List[str]
self.link_args = []
# Raw -L and -l arguments without manual library searching
# If None, self.link_args will be used
@ -132,7 +132,7 @@ class Dependency:
s = '<{0} {1}: {2}>'
return s.format(self.__class__.__name__, self.name, self.is_found)
def get_compile_args(self):
def get_compile_args(self) -> T.List[str]:
if self.include_type == 'system':
converted = []
for i in self.compile_args:
@ -156,7 +156,7 @@ class Dependency:
return self.raw_link_args
return self.link_args
def found(self):
def found(self) -> bool:
return self.is_found
def get_sources(self):
@ -171,7 +171,7 @@ class Dependency:
def get_name(self):
return self.name
def get_version(self):
def get_version(self) -> str:
if self.version:
return self.version
else:
@ -183,7 +183,7 @@ class Dependency:
def get_exe_args(self, compiler):
return []
def get_pkgconfig_variable(self, variable_name, kwargs):
def get_pkgconfig_variable(self, variable_name: str, kwargs: T.Dict[str, T.Any]) -> str:
raise DependencyException('{!r} is not a pkgconfig dependency'.format(self.name))
def get_configtool_variable(self, variable_name):
@ -261,7 +261,7 @@ class InternalDependency(Dependency):
setattr(result, k, copy.deepcopy(v, memo))
return result
def get_pkgconfig_variable(self, variable_name, kwargs):
def get_pkgconfig_variable(self, variable_name: str, kwargs: T.Dict[str, T.Any]) -> str:
raise DependencyException('Method "get_pkgconfig_variable()" is '
'invalid for an internal dependency')
@ -504,7 +504,7 @@ class ConfigToolDependency(ExternalDependency):
return self.config is not None
def get_config_value(self, args, stage):
def get_config_value(self, args: T.List[str], stage: str) -> T.List[str]:
p, out, err = Popen_safe(self.config + args)
if p.returncode != 0:
if self.required:
@ -877,7 +877,7 @@ class PkgConfigDependency(ExternalDependency):
(self.name, out_raw))
self.link_args, self.raw_link_args = self._search_libs(out, out_raw)
def get_pkgconfig_variable(self, variable_name, kwargs):
def get_pkgconfig_variable(self, variable_name: str, kwargs: T.Dict[str, T.Any]) -> str:
options = ['--variable=' + variable_name, self.name]
if 'define_variable' in kwargs:
@ -2037,7 +2037,7 @@ class ExternalProgram:
def found(self) -> bool:
return self.command[0] is not None
def get_command(self):
def get_command(self) -> T.List[str]:
return self.command[:]
def get_path(self):
@ -2550,7 +2550,7 @@ def factory_methods(methods: T.Set[DependencyMethods]) -> T.Callable[['FactoryTy
This helps to make factory functions self documenting
>>> @factory_methods([DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE])
>>> def factory(env: Environment, for_machine: MachineChoice, kwargs: T.Dict[str, T.Any], methods: T.Set[DependencyMethods]) -> T.List[DependencyType]:
>>> def factory(env: Environment, for_machine: MachineChoice, kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List[T.Callable[[], 'Dependency']]:
>>> pass
"""

@ -113,7 +113,7 @@ class HDF5Dependency(ExternalDependency):
cmd = prog.get_command() + [shlib_arg, '-show']
p = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, timeout=15)
if p.returncode != 0:
mlog.debug('Command', mlog.bold(cmd), 'failed to run:')
mlog.debug('Command', mlog.bold(str(cmd)), 'failed to run:')
mlog.debug(mlog.bold('Standard output\n'), p.stdout)
mlog.debug(mlog.bold('Standard error\n'), p.stderr)
return

@ -24,10 +24,11 @@ from ..environment import detect_cpu_family
if T.TYPE_CHECKING:
from .base import Dependency
from ..compilers import Compiler
from ..compilers.compiler import CompilerType
from ..environment import Environment, MachineChoice
@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.SYSTEM}) # type: ignore
@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.SYSTEM})
def mpi_factory(env: 'Environment', for_machine: 'MachineChoice',
kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List[T.Callable[[], 'Dependency']]:
language = kwargs.get('language', 'c')
@ -36,7 +37,9 @@ def mpi_factory(env: 'Environment', for_machine: 'MachineChoice',
return []
candidates = [] # type: T.List[T.Callable[[], Dependency]]
compiler = detect_compiler('mpi', env, for_machine, language)
compiler = detect_compiler('mpi', env, for_machine, language) # type: T.Optional['CompilerType']
if compiler is None:
return []
compiler_is_intel = compiler.get_id() in {'intel', 'intel-cl'}
# Only OpenMPI has pkg-config, and it doesn't work with the intel compilers

@ -947,7 +947,7 @@ def do_define(regex: T.Pattern[str], line: str, confdata: 'ConfigurationData', v
for token in arr[2:]:
try:
(v, desc) = confdata.get(token)
define_value += [v]
define_value += [str(v)]
except KeyError:
define_value += [token]
return ' '.join(define_value)

Loading…
Cancel
Save