dependencies: use better internal representation of factory methods

functools.partial preserves information about how the method was
created, lambdas do not. Also, we just want to freeze the first argument
and forward the rest anyway.

This also lets us get rid of a mypy error that was being ignored.
pull/10756/head
Eli Schwartz 3 years ago
parent 7972c49bda
commit b821a03511
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 3
      mesonbuild/dependencies/detect.py
  2. 12
      mesonbuild/dependencies/factory.py

@ -178,8 +178,7 @@ def _build_external_dependency_list(name: str, env: 'Environment', for_machine:
if isinstance(packages[lname], type):
entry1 = T.cast('T.Type[ExternalDependency]', packages[lname]) # mypy doesn't understand isinstance(..., type)
if issubclass(entry1, ExternalDependency):
# TODO: somehow make mypy understand that entry1(env, kwargs) is OK...
func: T.Callable[[], 'ExternalDependency'] = lambda: entry1(env, kwargs) # type: ignore
func: T.Callable[[], 'ExternalDependency'] = functools.partial(entry1, env, kwargs)
dep = [func]
else:
entry2 = T.cast('T.Union[DependencyFactory, WrappedFactoryFunc]', packages[lname])

@ -100,15 +100,15 @@ class DependencyFactory:
] = {
# Just attach the correct name right now, either the generic name
# or the method specific name.
DependencyMethods.EXTRAFRAMEWORK: lambda env, kwargs: framework_class(framework_name or name, env, kwargs),
DependencyMethods.PKGCONFIG: lambda env, kwargs: pkgconfig_class(pkgconfig_name or name, env, kwargs),
DependencyMethods.CMAKE: lambda env, kwargs: cmake_class(cmake_name or name, env, kwargs),
DependencyMethods.SYSTEM: lambda env, kwargs: system_class(name, env, kwargs),
DependencyMethods.BUILTIN: lambda env, kwargs: builtin_class(name, env, kwargs),
DependencyMethods.EXTRAFRAMEWORK: functools.partial(framework_class, framework_name or name),
DependencyMethods.PKGCONFIG: functools.partial(pkgconfig_class, pkgconfig_name or name),
DependencyMethods.CMAKE: functools.partial(cmake_class, cmake_name or name),
DependencyMethods.SYSTEM: functools.partial(system_class, name),
DependencyMethods.BUILTIN: functools.partial(builtin_class, name),
DependencyMethods.CONFIG_TOOL: None,
}
if configtool_class is not None:
self.classes[DependencyMethods.CONFIG_TOOL] = lambda env, kwargs: configtool_class(name, env, kwargs)
self.classes[DependencyMethods.CONFIG_TOOL] = functools.partial(configtool_class, name)
@staticmethod
def _process_method(method: DependencyMethods, env: 'Environment', for_machine: MachineChoice) -> bool:

Loading…
Cancel
Save