aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-03-22 20:28:59 -0400
committerEli Schwartz <eschwartz@archlinux.org>2022-03-29 16:44:54 -0400
commitc9938f8f60c0b7cca7a5668807b17badb7861c86 (patch)
tree6bbdb301a2c8ce4b92866a04703ada96241683b4 /mesonbuild
parent05cfe756f1c2dbd212aa6d30a3879cfe47a7f2fd (diff)
downloadmeson-c9938f8f60c0b7cca7a5668807b17badb7861c86.zip
meson-c9938f8f60c0b7cca7a5668807b17badb7861c86.tar.gz
meson-c9938f8f60c0b7cca7a5668807b17badb7861c86.tar.bz2
move a bunch of imports into TYPE_CHECKING blocks
These are only used for type checking, so don't bother importing them at runtime. Generally add future annotations at the same time, to make sure that existing uses of these imports don't need to be quoted.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/dependencies/dev.py5
-rw-r--r--mesonbuild/interpreter/dependencyfallbacks.py8
-rw-r--r--mesonbuild/interpreter/interpreterobjects.py8
-rw-r--r--mesonbuild/modules/fs.py2
-rw-r--r--mesonbuild/modules/gnome.py4
-rw-r--r--mesonbuild/modules/java.py12
-rw-r--r--mesonbuild/modules/qt.py7
-rw-r--r--mesonbuild/scripts/depscan.py16
-rw-r--r--mesonbuild/scripts/run_tool.py5
9 files changed, 44 insertions, 23 deletions
diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py
index 793b38a..c2bef0d 100644
--- a/mesonbuild/dependencies/dev.py
+++ b/mesonbuild/dependencies/dev.py
@@ -29,7 +29,7 @@ from mesonbuild.interpreterbase.decorators import FeatureDeprecated
from .. import mesonlib, mlog
from ..compilers import AppleClangCCompiler, AppleClangCPPCompiler, detect_compiler_for
from ..environment import get_llvm_tool_names
-from ..mesonlib import version_compare, stringlistify, extract_as_list, MachineChoice
+from ..mesonlib import version_compare, stringlistify, extract_as_list
from .base import DependencyException, DependencyMethods, strip_system_libdirs, SystemDependency
from .cmake import CMakeDependency
from .configtool import ConfigToolDependency
@@ -39,7 +39,8 @@ from .pkgconfig import PkgConfigDependency
if T.TYPE_CHECKING:
from ..envconfig import MachineInfo
- from .. environment import Environment
+ from ..environment import Environment
+ from ..mesonlib import MachineChoice
from typing_extensions import TypedDict
class JNISystemDependencyKW(TypedDict):
diff --git a/mesonbuild/interpreter/dependencyfallbacks.py b/mesonbuild/interpreter/dependencyfallbacks.py
index e029854..a252046 100644
--- a/mesonbuild/interpreter/dependencyfallbacks.py
+++ b/mesonbuild/interpreter/dependencyfallbacks.py
@@ -1,5 +1,6 @@
-from .interpreterobjects import SubprojectHolder, extract_required_kwarg
+from __future__ import annotations
+from .interpreterobjects import extract_required_kwarg
from .. import mlog
from .. import dependencies
from .. import build
@@ -7,12 +8,13 @@ from ..wrap import WrapMode
from ..mesonlib import OptionKey, extract_as_list, stringlistify, version_compare_many, listify
from ..dependencies import Dependency, DependencyException, NotFoundDependency
from ..interpreterbase import (MesonInterpreterObject, FeatureNew,
- InterpreterException, InvalidArguments,
- TYPE_nkwargs, TYPE_nvar)
+ InterpreterException, InvalidArguments)
import typing as T
if T.TYPE_CHECKING:
from .interpreter import Interpreter
+ from ..interpreterbase import TYPE_nkwargs, TYPE_nvar
+ from .interpreterobjects import SubprojectHolder
class DependencyFallbacksHolder(MesonInterpreterObject):
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py
index bf668f3..6cc636b 100644
--- a/mesonbuild/interpreter/interpreterobjects.py
+++ b/mesonbuild/interpreter/interpreterobjects.py
@@ -16,10 +16,10 @@ from ..modules import ModuleReturnValue, ModuleObject, ModuleState, ExtensionMod
from ..backend.backends import TestProtocol
from ..interpreterbase import (
ContainerTypeInfo, KwargInfo, MesonOperator,
- InterpreterObject, MesonInterpreterObject, ObjectHolder, MutableInterpreterObject,
- FeatureCheckBase, FeatureNew, FeatureDeprecated,
+ MesonInterpreterObject, ObjectHolder, MutableInterpreterObject,
+ FeatureNew, FeatureDeprecated,
typed_pos_args, typed_kwargs, typed_operator,
- noArgsFlattening, noPosargs, noKwargs, unholder_return, TYPE_var, TYPE_kwargs, TYPE_nvar, TYPE_nkwargs,
+ noArgsFlattening, noPosargs, noKwargs, unholder_return,
flatten, resolve_second_level_holders, InterpreterException, InvalidArguments, InvalidCode)
from ..interpreter.type_checking import NoneType, ENV_SEPARATOR_KW
from ..dependencies import Dependency, ExternalLibrary, InternalDependency
@@ -32,7 +32,7 @@ if T.TYPE_CHECKING:
from . import kwargs
from ..cmake.interpreter import CMakeInterpreter
from ..envconfig import MachineInfo
- from ..interpreterbase import SubProject
+ from ..interpreterbase import FeatureCheckBase, InterpreterObject, SubProject, TYPE_var, TYPE_kwargs, TYPE_nvar, TYPE_nkwargs
from .interpreter import Interpreter
from typing_extensions import TypedDict
diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py
index 5faee83..d0f5e2e 100644
--- a/mesonbuild/modules/fs.py
+++ b/mesonbuild/modules/fs.py
@@ -21,7 +21,6 @@ from .. import mlog
from . import ExtensionModule
from ..mesonlib import (
File,
- FileOrString,
MesonException,
path_is_in_root,
)
@@ -30,6 +29,7 @@ from ..interpreterbase import FeatureNew, KwargInfo, typed_kwargs, typed_pos_arg
if T.TYPE_CHECKING:
from . import ModuleState
from ..interpreter import Interpreter
+ from ..mesonlib import FileOrString
from typing_extensions import TypedDict
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index 484938e..5376d00 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -14,6 +14,7 @@
'''This module provides helper functions for Gnome/GLib related
functionality such as gobject-introspection, gresources and gtk-doc'''
+from __future__ import annotations
import copy
import itertools
@@ -30,7 +31,7 @@ from .. import build
from .. import interpreter
from .. import mesonlib
from .. import mlog
-from ..build import BuildTarget, CustomTarget, CustomTargetIndex, Executable, GeneratedList, InvalidArguments
+from ..build import CustomTarget, CustomTargetIndex, Executable, GeneratedList, InvalidArguments
from ..dependencies import Dependency, PkgConfigDependency, InternalDependency
from ..interpreter.type_checking import DEPENDS_KW, DEPEND_FILES_KW, INSTALL_KW, NoneType, in_set_validator
from ..interpreterbase import noPosargs, noKwargs, FeatureNew, FeatureDeprecated
@@ -46,6 +47,7 @@ if T.TYPE_CHECKING:
from typing_extensions import Literal, TypedDict
from . import ModuleState
+ from ..build import BuildTarget
from ..compilers import Compiler
from ..interpreter import Interpreter
from ..interpreterbase import TYPE_var, TYPE_kwargs
diff --git a/mesonbuild/modules/java.py b/mesonbuild/modules/java.py
index 22b8d2c..a8e5062 100644
--- a/mesonbuild/modules/java.py
+++ b/mesonbuild/modules/java.py
@@ -11,17 +11,23 @@
# 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 pathlib
import typing as T
+
from mesonbuild import mesonlib
from mesonbuild.build import CustomTarget, CustomTargetIndex, GeneratedList, Target
-from mesonbuild.compilers import detect_compiler_for, Compiler
-from mesonbuild.interpreter import Interpreter
+from mesonbuild.compilers import detect_compiler_for
from mesonbuild.interpreterbase.decorators import ContainerTypeInfo, FeatureDeprecated, FeatureNew, KwargInfo, typed_pos_args, typed_kwargs
from mesonbuild.mesonlib import version_compare, MachineChoice
-from . import NewExtensionModule, ModuleReturnValue, ModuleState
+from . import NewExtensionModule, ModuleReturnValue
+
+if T.TYPE_CHECKING:
+ from . import ModuleState
+ from ..compilers import Compiler
+ from ..interpreter import Interpreter
class JavaModule(NewExtensionModule):
@FeatureNew('Java Module', '0.60.0')
diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py
index 81dd3e9..99581a4 100644
--- a/mesonbuild/modules/qt.py
+++ b/mesonbuild/modules/qt.py
@@ -12,6 +12,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 shutil
@@ -23,17 +24,19 @@ from .. import build
from .. import coredata
from .. import mlog
from ..dependencies import find_external_dependency, Dependency, ExternalLibrary
-from ..mesonlib import MesonException, File, FileOrString, version_compare, Popen_safe
+from ..mesonlib import MesonException, File, version_compare, Popen_safe
from ..interpreter import extract_required_kwarg
from ..interpreter.type_checking import NoneType
from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, KwargInfo, noPosargs, FeatureNew, typed_kwargs
-from ..programs import ExternalProgram, NonExistingExternalProgram
+from ..programs import NonExistingExternalProgram
if T.TYPE_CHECKING:
from . import ModuleState
from ..dependencies.qt import QtPkgConfigDependency, QmakeQtDependency
from ..interpreter import Interpreter
from ..interpreter import kwargs
+ from ..mesonlib import FileOrString
+ from ..programs import ExternalProgram
QtDependencyType = T.Union[QtPkgConfigDependency, QmakeQtDependency]
diff --git a/mesonbuild/scripts/depscan.py b/mesonbuild/scripts/depscan.py
index 3b26f92..6f92715 100644
--- a/mesonbuild/scripts/depscan.py
+++ b/mesonbuild/scripts/depscan.py
@@ -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 json
import os
@@ -20,9 +21,12 @@ import re
import sys
import typing as T
-from ..backend.ninjabackend import TargetDependencyScannerInfo, ninja_quote
+from ..backend.ninjabackend import ninja_quote
from ..compilers.compilers import lang_suffixes
+if T.TYPE_CHECKING:
+ from ..backend.ninjabackend import TargetDependencyScannerInfo
+
CPP_IMPORT_RE = re.compile(r'\w*import ([a-zA-Z0-9]+);')
CPP_EXPORT_RE = re.compile(r'\w*export module ([a-zA-Z0-9]+);')
@@ -38,13 +42,13 @@ FORTRAN_USE_RE = re.compile(FORTRAN_USE_PAT, re.IGNORECASE)
class DependencyScanner:
def __init__(self, pickle_file: str, outfile: str, sources: T.List[str]):
with open(pickle_file, 'rb') as pf:
- self.target_data = pickle.load(pf) # type: TargetDependencyScannerInfo
+ self.target_data: TargetDependencyScannerInfo = pickle.load(pf)
self.outfile = outfile
self.sources = sources
- self.provided_by = {} # type: T.Dict[str, str]
- self.exports = {} # type: T.Dict[str, str]
- self.needs = {} # type: T.Dict[str, T.List[str]]
- self.sources_with_exports = [] # type: T.List[str]
+ self.provided_by: T.Dict[str, str] = {}
+ self.exports: T.Dict[str, str] = {}
+ self.needs: T.Dict[str, T.List[str]] = {}
+ self.sources_with_exports: T.List[str] = []
def scan_file(self, fname: str) -> None:
suffix = os.path.splitext(fname)[1][1:].lower()
diff --git a/mesonbuild/scripts/run_tool.py b/mesonbuild/scripts/run_tool.py
index 700f459..f120df2 100644
--- a/mesonbuild/scripts/run_tool.py
+++ b/mesonbuild/scripts/run_tool.py
@@ -11,8 +11,8 @@
# 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
import itertools
import fnmatch
from pathlib import Path
@@ -22,6 +22,9 @@ from ..compilers import lang_suffixes
from ..mesonlib import Popen_safe
import typing as T
+if T.TYPE_CHECKING:
+ import subprocess
+
def parse_pattern_file(fname: Path) -> T.List[str]:
patterns = []
try: