diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-06-30 12:58:38 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-06-30 14:06:30 -0700 |
commit | 1416ba0b8d950d3263aa35667c659aee18cfa8bf (patch) | |
tree | f0154ec38bc2eaba95748d91dcd286d37f123841 | |
parent | 351a1e9ec93fecee8923356c5647fa526524c54d (diff) | |
download | meson-1416ba0b8d950d3263aa35667c659aee18cfa8bf.zip meson-1416ba0b8d950d3263aa35667c659aee18cfa8bf.tar.gz meson-1416ba0b8d950d3263aa35667c659aee18cfa8bf.tar.bz2 |
modules: add classes with the found method
These will be needed for checking whether a module is found or not if it
is required false.
-rw-r--r-- | mesonbuild/modules/__init__.py | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py index 2b53de5..ab8534e 100644 --- a/mesonbuild/modules/__init__.py +++ b/mesonbuild/modules/__init__.py @@ -16,10 +16,11 @@ # are UI-related. import os +import typing as T from .. import build from ..mesonlib import relpath, HoldableObject -import typing as T +from ..interpreterbase.decorators import noKwargs, noPosargs if T.TYPE_CHECKING: from ..interpreter import Interpreter @@ -91,15 +92,17 @@ class ModuleState: wanted: T.Optional[str] = None) -> 'ExternalProgram': return self._interpreter.find_program_impl(prog, required=required, version_func=version_func, wanted=wanted) + class ModuleObject(HoldableObject): """Base class for all objects returned by modules """ def __init__(self) -> None: self.methods: T.Dict[ str, - T.Callable[[ModuleState, T.List[TYPE_var], TYPE_kwargs], T.Union[ModuleReturnValue, TYPE_var]] + T.Callable[[ModuleState, T.List['TYPE_var'], 'TYPE_kwargs'], T.Union[ModuleReturnValue, 'TYPE_var']] ] = {} + class MutableModuleObject(ModuleObject): pass @@ -110,6 +113,53 @@ class ExtensionModule(ModuleObject): def __init__(self, interpreter: 'Interpreter') -> None: super().__init__() self.interpreter = interpreter + self.methods.update({ + 'found': self.found_method, + }) + + @noPosargs + @noKwargs + def found_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> bool: + return True + + +class NewExtensionModule(ModuleObject): + + """Class for modern modules + + provides the found method. + """ + + def __init__(self): + super().__init__() + self.methods.update({ + 'found': self.found_method, + }) + + @noPosargs + @noKwargs + def found_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> bool: + return True + + +class NotFoundExtensionModule(ModuleObject): + + """Class for modern modules + + provides the found method. + """ + + def __init__(self): + super().__init__() + self.methods.update({ + 'found': self.found_method, + }) + + @noPosargs + @noKwargs + def found_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> bool: + return False + def is_module_library(fname): ''' |