aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies/base.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-01-28 13:46:41 -0800
committerDylan Baker <dylan@pnwbakers.com>2020-01-29 09:11:24 -0800
commitb0f0d30cf3e68c7643b87212b79a54eb691165b8 (patch)
treef2133cc2f6f689c31cbe21b196c3cbd1a8b06513 /mesonbuild/dependencies/base.py
parent47502f8adfbec979212f0bfd12d9b086a9117f20 (diff)
downloadmeson-b0f0d30cf3e68c7643b87212b79a54eb691165b8.zip
meson-b0f0d30cf3e68c7643b87212b79a54eb691165b8.tar.gz
meson-b0f0d30cf3e68c7643b87212b79a54eb691165b8.tar.bz2
dependencies: Add a decorator for dependency factory functions
This helps make them a bit more self documenting, and remove a bit of the boilerplate they would otherwise have to each implement.
Diffstat (limited to 'mesonbuild/dependencies/base.py')
-rw-r--r--mesonbuild/dependencies/base.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 0596395..370c714 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -2501,3 +2501,30 @@ def process_method_kw(possible: T.List[DependencyMethods], kwargs) -> T.List[Dep
mlog.format_list([x.value for x in [DependencyMethods.AUTO] + possible])))
return methods
+
+
+if T.TYPE_CHECKING:
+ FactoryType = T.Callable[[Environment, MachineChoice, T.Dict[str, T.Any]],
+ T.List['DependencyType']]
+ FullFactoryType = T.Callable[[Environment, MachineChoice, T.Dict[str, T.Any], T.Set[DependencyMethods]],
+ T.List['DependencyType']]
+
+
+def factory_methods(methods: T.Set[DependencyMethods]) -> 'FactoryType':
+ """Decorator for handling methods for dependency factory functions.
+
+ This helps to make factory functions self documenting
+ >>> @factory_methods([DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE])
+ >>> def factory(env: Environment, for_machine: MachineChoice, kwargs: T.Dict[str, T.Any], methods: T.Set[DependencyMethods]) -> T.List[DependencyType]:
+ >>> pass
+ """
+
+ def inner(func: 'FullFactoryType') -> 'FactoryType':
+
+ @functools.wraps(func)
+ def wrapped(env: Environment, for_machine: MachineChoice, kwargs: T.Dict[str, T.Any]) -> T.List['DependencyType']:
+ return func(env, for_machine, kwargs, process_method_kw(methods, kwargs))
+
+ return wrapped
+
+ return inner