From 1416ba0b8d950d3263aa35667c659aee18cfa8bf Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 30 Jun 2021 12:58:38 -0700 Subject: 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. --- mesonbuild/modules/__init__.py | 54 ++++++++++++++++++++++++++++++++++++++++-- 1 file 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): ''' -- cgit v1.1