lgtm: Fix Module imported with `import` and `import from`

pull/6289/head
Daniel Mensinger 5 years ago committed by Jussi Pakkanen
parent 9b1a857473
commit 286b9f0921
  1. 59
      mesonbuild/compilers/compilers.py
  2. 13
      mesonbuild/compilers/fortran.py
  3. 40
      mesonbuild/coredata.py
  4. 37
      mesonbuild/dependencies/base.py
  5. 5
      mesonbuild/mlog.py
  6. 18
      run_tests.py

@ -13,8 +13,7 @@
# limitations under the License.
import contextlib, os.path, re, tempfile
import typing
from typing import Optional, Tuple, List
from typing import TYPE_CHECKING, Optional, Tuple, List, Union
from ..linkers import StaticLinker, GnuLikeDynamicLinkerMixin, SolarisDynamicLinker
from .. import coredata
@ -28,7 +27,7 @@ from ..envconfig import (
Properties,
)
if typing.TYPE_CHECKING:
if TYPE_CHECKING:
from ..coredata import OptionDictType
from ..envconfig import MachineInfo
from ..environment import Environment
@ -522,7 +521,7 @@ class CompilerArgs(list):
return True
return False
def to_native(self, copy: bool = False) -> typing.List[str]:
def to_native(self, copy: bool = False) -> List[str]:
# Check if we need to add --start/end-group for circular dependencies
# between static libraries, and for recursively searching for symbols
# needed by static libraries that are provided by object files or
@ -669,10 +668,10 @@ class Compiler:
# manually searched.
internal_libs = ()
LINKER_PREFIX = None # type: typing.Union[None, str, typing.List[str]]
LINKER_PREFIX = None # type: Union[None, str, List[str]]
def __init__(self, exelist, version, for_machine: MachineChoice, info: 'MachineInfo',
linker: typing.Optional['DynamicLinker'] = None, **kwargs):
linker: Optional['DynamicLinker'] = None, **kwargs):
if isinstance(exelist, str):
self.exelist = [exelist]
elif isinstance(exelist, list):
@ -747,10 +746,10 @@ class Compiler:
def get_exelist(self):
return self.exelist[:]
def get_linker_exelist(self) -> typing.List[str]:
def get_linker_exelist(self) -> List[str]:
return self.linker.get_exelist()
def get_linker_output_args(self, outputname: str) -> typing.List[str]:
def get_linker_output_args(self, outputname: str) -> List[str]:
return self.linker.get_output_args(outputname)
def get_builtin_define(self, *args, **kwargs):
@ -793,10 +792,10 @@ class Compiler:
"""
return self.get_language() in languages_using_ldflags
def get_linker_args_from_envvars(self) -> typing.List[str]:
def get_linker_args_from_envvars(self) -> List[str]:
return self.linker.get_args_from_envvars()
def get_args_from_envvars(self) -> typing.Tuple[typing.List[str], typing.List[str]]:
def get_args_from_envvars(self) -> Tuple[List[str], List[str]]:
"""
Returns a tuple of (compile_flags, link_flags) for the specified language
from the inherited environment
@ -813,8 +812,8 @@ class Compiler:
if lang not in cflags_mapping:
return [], []
compile_flags = [] # type: typing.List[str]
link_flags = [] # type: typing.List[str]
compile_flags = [] # type: List[str]
link_flags = [] # type: List[str]
env_compile_flags = os.environ.get(cflags_mapping[lang])
log_var(cflags_mapping[lang], env_compile_flags)
@ -885,7 +884,7 @@ class Compiler:
def get_option_compile_args(self, options):
return []
def get_option_link_args(self, options: 'OptionDictType') -> typing.List[str]:
def get_option_link_args(self, options: 'OptionDictType') -> List[str]:
return self.linker.get_option_args(options)
def check_header(self, *args, **kwargs) -> Tuple[bool, bool]:
@ -921,7 +920,7 @@ class Compiler:
return args[:]
@classmethod
def native_args_to_unix(cls, args: typing.List[str]) -> typing.List[str]:
def native_args_to_unix(cls, args: List[str]) -> List[str]:
"Always returns a copy that can be independently mutated"
return args[:]
@ -939,7 +938,7 @@ class Compiler:
'Language {} does not support has_multi_arguments.'.format(
self.get_display_language()))
def has_multi_link_arguments(self, args: typing.List[str], env: 'Environment') -> Tuple[bool, bool]:
def has_multi_link_arguments(self, args: List[str], env: 'Environment') -> Tuple[bool, bool]:
return self.linker.has_multi_arguments(args, env)
def _get_compile_output(self, dirname, mode):
@ -1053,22 +1052,22 @@ class Compiler:
def get_compile_debugfile_args(self, rel_obj, **kwargs):
return []
def get_link_debugfile_args(self, targetfile: str) -> typing.List[str]:
def get_link_debugfile_args(self, targetfile: str) -> List[str]:
return self.linker.get_debugfile_args(targetfile)
def get_std_shared_lib_link_args(self) -> typing.List[str]:
def get_std_shared_lib_link_args(self) -> List[str]:
return self.linker.get_std_shared_lib_args()
def get_std_shared_module_link_args(self, options: 'OptionDictType') -> typing.List[str]:
def get_std_shared_module_link_args(self, options: 'OptionDictType') -> List[str]:
return self.linker.get_std_shared_module_args(options)
def get_link_whole_for(self, args: typing.List[str]) -> typing.List[str]:
def get_link_whole_for(self, args: List[str]) -> List[str]:
return self.linker.get_link_whole_for(args)
def get_allow_undefined_link_args(self) -> typing.List[str]:
def get_allow_undefined_link_args(self) -> List[str]:
return self.linker.get_allow_undefined_args()
def no_undefined_link_args(self) -> typing.List[str]:
def no_undefined_link_args(self) -> List[str]:
return self.linker.no_undefined_args()
# Compiler arguments needed to enable the given instruction set.
@ -1079,7 +1078,7 @@ class Compiler:
def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: str, build_rpath: str,
install_rpath: str) -> typing.List[str]:
install_rpath: str) -> List[str]:
return self.linker.build_rpath_args(
env, build_dir, from_dir, rpath_paths, build_rpath, install_rpath)
@ -1110,7 +1109,7 @@ class Compiler:
m = 'Language {} does not support position-independent executable'
raise EnvironmentException(m.format(self.get_display_language()))
def get_pie_link_args(self) -> typing.List[str]:
def get_pie_link_args(self) -> List[str]:
return self.linker.get_pie_args()
def get_argument_syntax(self):
@ -1132,7 +1131,7 @@ class Compiler:
raise EnvironmentException(
'%s does not support get_profile_use_args ' % self.get_id())
def get_undefined_link_args(self) -> typing.List[str]:
def get_undefined_link_args(self) -> List[str]:
return self.linker.get_undefined_link_args()
def remove_linkerlike_args(self, args):
@ -1150,21 +1149,21 @@ class Compiler:
def sanitizer_link_args(self, value: str) -> List[str]:
return self.linker.sanitizer_args(value)
def get_asneeded_args(self) -> typing.List[str]:
def get_asneeded_args(self) -> List[str]:
return self.linker.get_asneeded_args()
def bitcode_args(self) -> typing.List[str]:
def bitcode_args(self) -> List[str]:
return self.linker.bitcode_args()
def get_linker_debug_crt_args(self) -> typing.List[str]:
def get_linker_debug_crt_args(self) -> List[str]:
return self.linker.get_debug_crt_args()
def get_buildtype_linker_args(self, buildtype: str) -> typing.List[str]:
def get_buildtype_linker_args(self, buildtype: str) -> List[str]:
return self.linker.get_buildtype_args(buildtype)
def get_soname_args(self, env: 'Environment', prefix: str, shlib_name: str,
suffix: str, soversion: str, darwin_versions: typing.Tuple[str, str],
is_shared_module: bool) -> typing.List[str]:
suffix: str, soversion: str, darwin_versions: Tuple[str, str],
is_shared_module: bool) -> List[str]:
return self.linker.get_soname_args(
env, prefix, shlib_name, suffix, soversion,
darwin_versions, is_shared_module)

@ -13,9 +13,8 @@
# limitations under the License.
from pathlib import Path
from typing import List
from typing import TYPE_CHECKING, List
import subprocess, os
import typing
from .. import coredata
from .compilers import (
@ -36,7 +35,7 @@ from mesonbuild.mesonlib import (
version_compare, EnvironmentException, MesonException, MachineChoice, LibType
)
if typing.TYPE_CHECKING:
if TYPE_CHECKING:
from ..envconfig import MachineInfo
@ -192,7 +191,7 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
'none')})
return opts
def get_option_compile_args(self, options) -> typing.List[str]:
def get_option_compile_args(self, options) -> List[str]:
args = []
std = options['fortran_std']
if std.value != 'none':
@ -298,7 +297,7 @@ class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler):
'none')})
return opts
def get_option_compile_args(self, options) -> typing.List[str]:
def get_option_compile_args(self, options) -> List[str]:
args = []
std = options['fortran_std']
stds = {'legacy': 'none', 'f95': 'f95', 'f2003': 'f03', 'f2008': 'f08', 'f2018': 'f18'}
@ -318,7 +317,7 @@ class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler):
def language_stdlib_only_link_flags(self):
return ['-lifcore', '-limf']
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> typing.List[str]:
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> List[str]:
return ['-gen-dep=' + outtarget, '-gen-depformat=make']
@ -348,7 +347,7 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
'none')})
return opts
def get_option_compile_args(self, options) -> typing.List[str]:
def get_option_compile_args(self, options) -> List[str]:
args = []
std = options['fortran_std']
stds = {'legacy': 'none', 'f95': 'f95', 'f2003': 'f03', 'f2008': 'f08', 'f2018': 'f18'}

@ -27,16 +27,16 @@ import ast
import argparse
import configparser
from typing import (
Any, Dict, Generic, Iterable, List, Optional, Type, TypeVar, Union
Any, Dict, Generic, Iterable, Iterator, List, MutableMapping, Optional, Tuple, Type, TypeVar, Union,
TYPE_CHECKING,
)
import typing
import enum
import shlex
if typing.TYPE_CHECKING:
if TYPE_CHECKING:
from . import dependencies
OptionDictType = typing.Dict[str, 'UserOption[Any]']
OptionDictType = Dict[str, 'UserOption[Any]']
version = '0.52.999'
backendlist = ['ninja', 'vs', 'vs2010', 'vs2015', 'vs2017', 'vs2019', 'xcode']
@ -231,9 +231,9 @@ def load_configs(filenames: List[str]) -> configparser.ConfigParser:
return config
if typing.TYPE_CHECKING:
CacheKeyType = typing.Tuple[typing.Tuple[typing.Any, ...], ...]
SubCacheKeyType = typing.Tuple[typing.Any, ...]
if TYPE_CHECKING:
CacheKeyType = Tuple[Tuple[Any, ...], ...]
SubCacheKeyType = Tuple[Any, ...]
class DependencyCacheType(enum.Enum):
@ -257,7 +257,7 @@ class DependencySubCache:
def __init__(self, type_: DependencyCacheType):
self.types = [type_]
self.__cache = {} # type: typing.Dict[SubCacheKeyType, dependencies.Dependency]
self.__cache = {} # type: Dict[SubCacheKeyType, dependencies.Dependency]
def __getitem__(self, key: 'SubCacheKeyType') -> 'dependencies.Dependency':
return self.__cache[key]
@ -268,7 +268,7 @@ class DependencySubCache:
def __contains__(self, key: 'SubCacheKeyType') -> bool:
return key in self.__cache
def values(self) -> typing.Iterable['dependencies.Dependency']:
def values(self) -> Iterable['dependencies.Dependency']:
return self.__cache.values()
@ -280,12 +280,12 @@ class DependencyCache:
successfully lookup by providing a simple get/put interface.
"""
def __init__(self, builtins_per_machine: PerMachine[typing.Dict[str, UserOption[typing.Any]]], for_machine: MachineChoice):
self.__cache = OrderedDict() # type: typing.MutableMapping[CacheKeyType, DependencySubCache]
def __init__(self, builtins_per_machine: PerMachine[Dict[str, UserOption[Any]]], for_machine: MachineChoice):
self.__cache = OrderedDict() # type: MutableMapping[CacheKeyType, DependencySubCache]
self.__builtins_per_machine = builtins_per_machine
self.__for_machine = for_machine
def __calculate_subkey(self, type_: DependencyCacheType) -> typing.Tuple[typing.Any, ...]:
def __calculate_subkey(self, type_: DependencyCacheType) -> Tuple[Any, ...]:
if type_ is DependencyCacheType.PKG_CONFIG:
return tuple(self.__builtins_per_machine[self.__for_machine]['pkg_config_path'].value)
elif type_ is DependencyCacheType.CMAKE:
@ -293,7 +293,7 @@ class DependencyCache:
assert type_ is DependencyCacheType.OTHER, 'Someone forgot to update subkey calculations for a new type'
return tuple()
def __iter__(self) -> typing.Iterator['CacheKeyType']:
def __iter__(self) -> Iterator['CacheKeyType']:
return self.keys()
def put(self, key: 'CacheKeyType', dep: 'dependencies.Dependency') -> None:
@ -303,7 +303,7 @@ class DependencyCache:
subkey = self.__calculate_subkey(t)
self.__cache[key][subkey] = dep
def get(self, key: 'CacheKeyType') -> typing.Optional['dependencies.Dependency']:
def get(self, key: 'CacheKeyType') -> Optional['dependencies.Dependency']:
"""Get a value from the cache.
If there is no cache entry then None will be returned.
@ -321,14 +321,14 @@ class DependencyCache:
pass
return None
def values(self) -> typing.Iterator['dependencies.Dependency']:
def values(self) -> Iterator['dependencies.Dependency']:
for c in self.__cache.values():
yield from c.values()
def keys(self) -> typing.Iterator['CacheKeyType']:
def keys(self) -> Iterator['CacheKeyType']:
return iter(self.__cache.keys())
def items(self) -> typing.Iterator[typing.Tuple['CacheKeyType', typing.List['dependencies.Dependency']]]:
def items(self) -> Iterator[Tuple['CacheKeyType', List['dependencies.Dependency']]]:
for k, v in self.__cache.items():
vs = []
for t in v.types:
@ -390,9 +390,9 @@ class CoreData:
if not filenames:
return []
found_invalid = [] # type: typing.List[str]
missing = [] # type: typing.List[str]
real = [] # type: typing.List[str]
found_invalid = [] # type: List[str]
missing = [] # type: List[str]
real = [] # type: List[str]
for i, f in enumerate(filenames):
f = os.path.expanduser(os.path.expandvars(f))
if os.path.exists(f):

@ -23,8 +23,7 @@ import shlex
import shutil
import textwrap
import platform
import typing
from typing import Any, Dict, List, Tuple
from typing import Any, Dict, List, Optional, Tuple, Type, Union
from enum import Enum
from pathlib import Path, PurePath
@ -208,8 +207,8 @@ class Dependency:
"""
raise RuntimeError('Unreachable code in partial_dependency called')
def _add_sub_dependency(self, dep_type: typing.Type['Dependency'], env: Environment,
kwargs: typing.Dict[str, typing.Any], *,
def _add_sub_dependency(self, dep_type: Type['Dependency'], env: Environment,
kwargs: Dict[str, Any], *,
method: DependencyMethods = DependencyMethods.AUTO) -> None:
"""Add an internal dependency of of the given type.
@ -222,14 +221,14 @@ class Dependency:
kwargs['method'] = method
self.ext_deps.append(dep_type(env, kwargs))
def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None,
configtool: typing.Optional[str] = None, default_value: typing.Optional[str] = None,
pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]:
def get_variable(self, *, cmake: Optional[str] = None, pkgconfig: Optional[str] = None,
configtool: Optional[str] = None, default_value: Optional[str] = None,
pkgconfig_define: Optional[List[str]] = None) -> Union[str, List[str]]:
if default_value is not None:
return default_value
raise DependencyException('No default provided for dependency {!r}, which is not pkg-config, cmake, or config-tool based.'.format(self))
def generate_system_dependency(self, include_type: str) -> typing.Type['Dependency']:
def generate_system_dependency(self, include_type: str) -> Type['Dependency']:
new_dep = copy.deepcopy(self)
new_dep.include_type = self._process_include_type_kw({'include_type': include_type})
return new_dep
@ -550,9 +549,9 @@ class ConfigToolDependency(ExternalDependency):
def log_tried(self):
return self.type_name
def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None,
configtool: typing.Optional[str] = None, default_value: typing.Optional[str] = None,
pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]:
def get_variable(self, *, cmake: Optional[str] = None, pkgconfig: Optional[str] = None,
configtool: Optional[str] = None, default_value: Optional[str] = None,
pkgconfig_define: Optional[List[str]] = None) -> Union[str, List[str]]:
if configtool:
# In the not required case '' (empty string) will be returned if the
# variable is not found. Since '' is a valid value to return we
@ -984,9 +983,9 @@ class PkgConfigDependency(ExternalDependency):
def log_tried(self):
return self.type_name
def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None,
configtool: typing.Optional[str] = None, default_value: typing.Optional[str] = None,
pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]:
def get_variable(self, *, cmake: Optional[str] = None, pkgconfig: Optional[str] = None,
configtool: Optional[str] = None, default_value: Optional[str] = None,
pkgconfig_define: Optional[List[str]] = None) -> Union[str, List[str]]:
if pkgconfig:
kwargs = {}
if default_value is not None:
@ -1479,9 +1478,9 @@ class CMakeDependency(ExternalDependency):
return 'modules: ' + ', '.join(modules)
return ''
def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None,
configtool: typing.Optional[str] = None, default_value: typing.Optional[str] = None,
pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]:
def get_variable(self, *, cmake: Optional[str] = None, pkgconfig: Optional[str] = None,
configtool: Optional[str] = None, default_value: Optional[str] = None,
pkgconfig_define: Optional[List[str]] = None) -> Union[str, List[str]]:
if cmake:
try:
v = self.traceparser.vars[cmake]
@ -1696,8 +1695,8 @@ class ExternalProgram:
# An 'ExternalProgram' always runs on the build machine
for_machine = MachineChoice.BUILD
def __init__(self, name: str, command: typing.Optional[typing.List[str]] = None,
silent: bool = False, search_dir: typing.Optional[str] = None):
def __init__(self, name: str, command: Optional[List[str]] = None,
silent: bool = False, search_dir: Optional[str] = None):
self.name = name
if command is not None:
self.command = listify(command)

@ -18,8 +18,7 @@ import sys
import time
import platform
from contextlib import contextmanager
import typing
from typing import Any, Generator, List, Optional, Sequence, TextIO, Union
from typing import Any, Generator, List, Optional, Sequence, TextIO, Union, cast
from pathlib import Path
"""This is (mostly) a standalone module used to write logging
@ -232,7 +231,7 @@ def _log_error(severity: str, *rargs: Union[str, AnsiDecorator], **kwargs: Any)
location_str = get_error_location_string(location_file, location.lineno)
# Unions are frankly awful, and we have to cast here to get mypy
# to understand that the list concatenation is safe
location_list = typing.cast(List[Union[str, AnsiDecorator]], [location_str])
location_list = cast(List[Union[str, AnsiDecorator]], [location_str])
args = location_list + args
log(*args, **kwargs)

@ -26,7 +26,8 @@ from io import StringIO
from enum import Enum
from glob import glob
from pathlib import Path
import mesonbuild
from mesonbuild import compilers
from mesonbuild import dependencies
from mesonbuild import mesonlib
from mesonbuild import mesonmain
from mesonbuild import mtest
@ -95,7 +96,6 @@ class FakeCompilerOptions:
self.value = []
def get_fake_options(prefix=''):
import argparse
opts = argparse.Namespace()
opts.native_file = []
opts.cross_file = None
@ -135,7 +135,7 @@ def get_meson_script():
running in-process (which is the default).
'''
# Is there a meson.py next to the mesonbuild currently in use?
mesonbuild_dir = Path(mesonbuild.__file__).resolve().parent.parent
mesonbuild_dir = Path(mesonmain.__file__).resolve().parent.parent
meson_script = mesonbuild_dir / 'meson.py'
if meson_script.is_file():
return str(meson_script)
@ -263,12 +263,12 @@ def run_mtest_inprocess(commandlist):
return returncode, mystdout.getvalue(), mystderr.getvalue()
def clear_meson_configure_class_caches():
mesonbuild.compilers.CCompiler.library_dirs_cache = {}
mesonbuild.compilers.CCompiler.program_dirs_cache = {}
mesonbuild.compilers.CCompiler.find_library_cache = {}
mesonbuild.compilers.CCompiler.find_framework_cache = {}
mesonbuild.dependencies.PkgConfigDependency.pkgbin_cache = {}
mesonbuild.dependencies.PkgConfigDependency.class_pkgbin = mesonlib.PerMachine(None, None)
compilers.CCompiler.library_dirs_cache = {}
compilers.CCompiler.program_dirs_cache = {}
compilers.CCompiler.find_library_cache = {}
compilers.CCompiler.find_framework_cache = {}
dependencies.PkgConfigDependency.pkgbin_cache = {}
dependencies.PkgConfigDependency.class_pkgbin = mesonlib.PerMachine(None, None)
def run_configure_inprocess(commandlist, env=None):
old_stdout = sys.stdout

Loading…
Cancel
Save