treewide: various cleanups to move imports for mypy into typechecking blocks

Along the way, add __future__ annotations where lacking.
pull/10477/head
Eli Schwartz 3 years ago committed by Xavier Claessens
parent 6aeb8792ca
commit a49cd00d64
  1. 5
      mesonbuild/backend/ninjabackend.py
  2. 4
      mesonbuild/backend/vs2010backend.py
  3. 9
      mesonbuild/backend/vs2012backend.py
  4. 6
      mesonbuild/backend/vs2013backend.py
  5. 9
      mesonbuild/backend/vs2015backend.py
  6. 7
      mesonbuild/backend/vs2017backend.py
  7. 7
      mesonbuild/backend/vs2019backend.py
  8. 7
      mesonbuild/backend/vs2022backend.py
  9. 11
      mesonbuild/backend/xcodebackend.py
  10. 7
      mesonbuild/compilers/rust.py
  11. 4
      mesonbuild/dependencies/boost.py
  12. 4
      mesonbuild/dependencies/cmake.py
  13. 2
      mesonbuild/dependencies/factory.py
  14. 10
      mesonbuild/minstall.py
  15. 4
      mesonbuild/modules/unstable_cuda.py
  16. 6
      mesonbuild/msubprojects.py
  17. 50
      mesonbuild/scripts/env2mfile.py

@ -49,11 +49,12 @@ from ..mesonlib import (
)
from ..mesonlib import get_compiler_for_source, has_path_sep, OptionKey
from .backends import CleanTrees
from ..build import GeneratedList, InvalidArguments, ExtractedObjects
from ..interpreter import Interpreter
from ..build import GeneratedList, InvalidArguments
if T.TYPE_CHECKING:
from .._typing import ImmutableListProtocol
from ..build import ExtractedObjects
from ..interpreter import Interpreter
from ..linkers import DynamicLinker, StaticLinker
from ..compilers.cs import CsCompiler

@ -27,12 +27,14 @@ from .. import build
from .. import dependencies
from .. import mlog
from .. import compilers
from ..interpreter import Interpreter
from ..mesonlib import (
File, MesonException, replace_if_different, OptionKey, version_compare, MachineChoice
)
from ..environment import Environment, build_filename
if T.TYPE_CHECKING:
from ..interpreter import Interpreter
def autodetect_vs_version(build: T.Optional[build.Build], interpreter: T.Optional[Interpreter]) -> backends.Backend:
vs_version = os.getenv('VisualStudioVersion', None)

@ -11,13 +11,16 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import typing as T
from .vs2010backend import Vs2010Backend
from ..mesonlib import MesonException
from ..interpreter import Interpreter
from ..build import Build
import typing as T
if T.TYPE_CHECKING:
from ..build import Build
from ..interpreter import Interpreter
class Vs2012Backend(Vs2010Backend):
def __init__(self, build: T.Optional[Build], interpreter: T.Optional[Interpreter]):

@ -11,13 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from .vs2010backend import Vs2010Backend
from ..mesonlib import MesonException
from ..interpreter import Interpreter
from ..build import Build
import typing as T
if T.TYPE_CHECKING:
from ..build import Build
from ..interpreter import Interpreter
class Vs2013Backend(Vs2010Backend):
def __init__(self, build: T.Optional[Build], interpreter: T.Optional[Interpreter]):

@ -11,13 +11,16 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import typing as T
from .vs2010backend import Vs2010Backend
from ..mesonlib import MesonException
from ..interpreter import Interpreter
from ..build import Build
import typing as T
if T.TYPE_CHECKING:
from ..build import Build
from ..interpreter import Interpreter
class Vs2015Backend(Vs2010Backend):
def __init__(self, build: T.Optional[Build], interpreter: T.Optional[Interpreter]):

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import os
import typing as T
@ -18,8 +19,10 @@ import xml.etree.ElementTree as ET
from .vs2010backend import Vs2010Backend
from ..mesonlib import MesonException
from ..interpreter import Interpreter
from ..build import Build
if T.TYPE_CHECKING:
from ..build import Build
from ..interpreter import Interpreter
class Vs2017Backend(Vs2010Backend):

@ -11,14 +11,17 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import os
import typing as T
import xml.etree.ElementTree as ET
from .vs2010backend import Vs2010Backend
from ..interpreter import Interpreter
from ..build import Build
if T.TYPE_CHECKING:
from ..build import Build
from ..interpreter import Interpreter
class Vs2019Backend(Vs2010Backend):

@ -11,14 +11,17 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import os
import typing as T
import xml.etree.ElementTree as ET
from .vs2010backend import Vs2010Backend
from ..interpreter import Interpreter
from ..build import Build
if T.TYPE_CHECKING:
from ..build import Build
from ..interpreter import Interpreter
class Vs2022Backend(Vs2010Backend):

@ -11,17 +11,20 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import uuid, os, operator
import typing as T
from . import backends
from .. import build
from .. import dependencies
from .. import mesonlib
from .. import mlog
import uuid, os, operator
import typing as T
from ..mesonlib import MesonException, OptionKey
from ..interpreter import Interpreter
if T.TYPE_CHECKING:
from ..interpreter import Interpreter
INDENT = '\t'
XCODETYPEMAP = {'c': 'sourcecode.c.c',

@ -11,16 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import subprocess, os.path
import textwrap
import typing as T
from .. import coredata
from ..mesonlib import (
EnvironmentException, MachineChoice, MesonException, Popen_safe,
OptionKey,
)
from ..mesonlib import EnvironmentException, MesonException, Popen_safe, OptionKey
from .compilers import Compiler, rust_buildtype_args, clike_debug_args
if T.TYPE_CHECKING:
@ -28,6 +26,7 @@ if T.TYPE_CHECKING:
from ..envconfig import MachineInfo
from ..environment import Environment # noqa: F401
from ..linkers import DynamicLinker
from ..mesonlib import MachineChoice
from ..programs import ExternalProgram

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import re
import dataclasses
@ -20,14 +21,13 @@ from pathlib import Path
from .. import mlog
from .. import mesonlib
from ..environment import Environment
from .base import DependencyException, SystemDependency
from .pkgconfig import PkgConfigDependency
from .misc import threads_factory
if T.TYPE_CHECKING:
from ..environment import Properties
from ..environment import Environment, Properties
# On windows 3 directory layouts are supported:
# * The default layout (versioned) installed:

@ -11,10 +11,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from .base import ExternalDependency, DependencyException, DependencyTypeName
from ..mesonlib import is_windows, MesonException, PerMachine, stringlistify, extract_as_list
from ..cmake import CMakeExecutor, CMakeTraceParser, CMakeException, CMakeToolchain, CMakeExecScope, check_cmake_args, CMakeTarget, resolve_cmake_trace_targets, cmake_is_debug
from ..cmake import CMakeExecutor, CMakeTraceParser, CMakeException, CMakeToolchain, CMakeExecScope, check_cmake_args, resolve_cmake_trace_targets, cmake_is_debug
from .. import mlog
import importlib.resources
from pathlib import Path
@ -26,6 +27,7 @@ import textwrap
import typing as T
if T.TYPE_CHECKING:
from ..cmake import CMakeTarget
from ..environment import Environment
from ..envconfig import MachineInfo

@ -18,7 +18,6 @@ import functools
import typing as T
from .base import DependencyException, DependencyMethods
from .base import ExternalDependency
from .base import process_method_kw
from .base import BuiltinDependency, SystemDependency
from .cmake import CMakeDependency
@ -26,6 +25,7 @@ from .framework import ExtraFrameworkDependency
from .pkgconfig import PkgConfigDependency
if T.TYPE_CHECKING:
from .base import ExternalDependency
from .configtool import ConfigToolDependency
from ..environment import Environment
from ..mesonlib import MachineChoice

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from glob import glob
from pathlib import Path
@ -26,10 +27,7 @@ import typing as T
from . import build
from . import environment
from .backend.backends import (
InstallData, InstallDataBase, InstallEmptyDir, InstallSymlinkData,
TargetInstallData, ExecutableSerialisation
)
from .backend.backends import InstallData
from .coredata import major_versions_differ, MesonVersionMismatchException
from .coredata import version as coredata_version
from .mesonlib import MesonException, Popen_safe, RealPathAction, is_windows, setup_vsenv
@ -43,6 +41,10 @@ except ImportError:
main_file = None
if T.TYPE_CHECKING:
from .backend.backends import (
ExecutableSerialisation, InstallDataBase, InstallEmptyDir,
InstallSymlinkData, TargetInstallData
)
from .mesonlib import FileMode
try:

@ -11,12 +11,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import typing as T
import re
from ..mesonlib import version_compare
from ..compilers import CudaCompiler, Compiler
from ..compilers import CudaCompiler
from . import NewExtensionModule
@ -27,6 +28,7 @@ from ..interpreterbase import (
if T.TYPE_CHECKING:
from . import ModuleState
from ..compilers import Compiler
class CudaModule(NewExtensionModule):

@ -1,3 +1,5 @@
from __future__ import annotations
from dataclasses import dataclass, InitVar
import os, subprocess
import argparse
@ -13,12 +15,14 @@ import zipfile
from . import mlog
from .mesonlib import quiet_git, GitException, Popen_safe, MesonException, windows_proof_rmtree
from .wrap.wrap import PackageDefinition, Resolver, WrapException, ALL_TYPES
from .wrap.wrap import Resolver, WrapException, ALL_TYPES
from .wrap import wraptool
if T.TYPE_CHECKING:
from typing_extensions import Protocol
from .wrap.wrap import PackageDefinition
class Arguments(Protocol):
sourcedir: str
num_processes: int

@ -11,15 +11,17 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import sys, os, subprocess, shutil
import shlex
import argparse
from typing import TextIO, Dict, List, Union, Tuple, Any, Optional
import typing as T
from .. import mlog
if T.TYPE_CHECKING:
import argparse
UNIXY_ENVVARS_COMPILER = {'c': 'CC',
'cpp': 'CXX',
'objc': 'OBJCC',
@ -86,16 +88,16 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None:
class MachineInfo:
def __init__(self) -> None:
self.compilers: Dict[str, List[str]] = {}
self.binaries: Dict[str, List[str]] = {}
self.properties: Dict[str, Union[str, List[str]]] = {}
self.compile_args: Dict[str, List[str]] = {}
self.link_args: Dict[str, List[str]] = {}
self.compilers: T.Dict[str, T.List[str]] = {}
self.binaries: T.Dict[str, T.List[str]] = {}
self.properties: T.Dict[str, T.Union[str, T.List[str]]] = {}
self.compile_args: T.Dict[str, T.List[str]] = {}
self.link_args: T.Dict[str, T.List[str]] = {}
self.system: Optional[str] = None
self.cpu: Optional[str] = None
self.cpu_family: Optional[str] = None
self.endian: Optional[str] = None
self.system: T.Optional[str] = None
self.cpu: T.Optional[str] = None
self.cpu_family: T.Optional[str] = None
self.endian: T.Optional[str] = None
#parser = argparse.ArgumentParser(description='''Generate cross compilation definition file for the Meson build system.
#
@ -108,7 +110,7 @@ class MachineInfo:
#'''
#)
def locate_path(program: str) -> List[str]:
def locate_path(program: str) -> T.List[str]:
if os.path.isabs(program):
return [program]
for d in os.get_exec_path():
@ -117,7 +119,7 @@ def locate_path(program: str) -> List[str]:
return [f]
raise ValueError("%s not found on $PATH" % program)
def write_args_line(ofile: TextIO, name: str, args: List[str]) -> None:
def write_args_line(ofile: T.TextIO, name: str, args: T.List[str]) -> None:
if len(args) == 0:
return
ostr = name + ' = ['
@ -165,7 +167,7 @@ cpu_family_map = dict(mips64el="mips64",
cpu_map = dict(armhf="arm7hlf",
mips64el="mips64",)
def deb_compiler_lookup(infos: MachineInfo, compilerstems: List[Tuple[str, str]], host_arch: str, gccsuffix: str) -> None:
def deb_compiler_lookup(infos: MachineInfo, compilerstems: T.List[T.Tuple[str, str]], host_arch: str, gccsuffix: str) -> None:
for langname, stem in compilerstems:
compilername = f'{host_arch}-{stem}{gccsuffix}'
try:
@ -174,7 +176,7 @@ def deb_compiler_lookup(infos: MachineInfo, compilerstems: List[Tuple[str, str]]
except ValueError:
pass
def detect_cross_debianlike(options: Any) -> MachineInfo:
def detect_cross_debianlike(options: T.Any) -> MachineInfo:
if options.debarch is None:
cmd = ['dpkg-architecture']
else:
@ -258,7 +260,7 @@ def write_machine_file(infos: MachineInfo, ofilename: str, write_system_info: bo
ofile.write(f"system = '{infos.system}'\n")
os.replace(tmpfilename, ofilename)
def detect_language_args_from_envvars(langname: str, envvar_suffix: str ='') -> Tuple[List[str], List[str]]:
def detect_language_args_from_envvars(langname: str, envvar_suffix: str ='') -> T.Tuple[T.List[str], T.List[str]]:
ldflags = tuple(shlex.split(os.environ.get('LDFLAGS' + envvar_suffix, '')))
compile_args = shlex.split(os.environ.get(UNIXY_ENVVARS_FLAGS[langname] + envvar_suffix, ''))
if langname in LANGS_USING_CPPFLAGS:
@ -291,7 +293,7 @@ def detect_binaries_from_envvars(infos: MachineInfo, envvar_suffix:str ='') -> N
if binstr:
infos.binaries[binname] = shlex.split(binstr)
def detect_cross_system(infos: MachineInfo, options: Any) -> None:
def detect_cross_system(infos: MachineInfo, options: T.Any) -> None:
for optname in ('system', 'cpu', 'cpu_family', 'endian'):
v = getattr(options, optname)
if not v:
@ -299,7 +301,7 @@ def detect_cross_system(infos: MachineInfo, options: Any) -> None:
sys.exit(1)
setattr(infos, optname, v)
def detect_cross_env(options: Any) -> MachineInfo:
def detect_cross_env(options: T.Any) -> MachineInfo:
if options.debarch:
print('Detecting cross environment via dpkg-reconfigure.')
infos = detect_cross_debianlike(options)
@ -309,7 +311,7 @@ def detect_cross_env(options: Any) -> MachineInfo:
detect_cross_system(infos, options)
return infos
def add_compiler_if_missing(infos: MachineInfo, langname: str, exe_names: List[str]) -> None:
def add_compiler_if_missing(infos: MachineInfo, langname: str, exe_names: T.List[str]) -> None:
if langname in infos.compilers:
return
for exe_name in exe_names:
@ -325,12 +327,12 @@ def add_compiler_if_missing(infos: MachineInfo, langname: str, exe_names: List[s
return
def detect_missing_native_compilers(infos: MachineInfo) -> None:
# Any per-platform special detection should go here.
# T.Any per-platform special detection should go here.
for langname, exes in TYPICAL_UNIXY_COMPILER_NAMES.items():
add_compiler_if_missing(infos, langname, exes)
def detect_missing_native_binaries(infos: MachineInfo) -> None:
# Any per-platform special detection should go here.
# T.Any per-platform special detection should go here.
for toolname in sorted(UNIXY_ENVVARS_TOOLS.keys()):
if toolname in infos.binaries:
continue
@ -338,7 +340,7 @@ def detect_missing_native_binaries(infos: MachineInfo) -> None:
if exe:
infos.binaries[toolname] = [exe]
def detect_native_env(options: Any) -> MachineInfo:
def detect_native_env(options: T.Any) -> MachineInfo:
use_for_build = has_for_build()
if use_for_build:
mlog.log('Using FOR_BUILD envvars for detection')
@ -352,7 +354,7 @@ def detect_native_env(options: Any) -> MachineInfo:
detect_missing_native_binaries(infos)
return infos
def run(options: Any) -> None:
def run(options: T.Any) -> None:
if options.cross and options.native:
sys.exit('You can only specify either --cross or --native, not both.')
if not options.cross and not options.native:

Loading…
Cancel
Save