Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share dependency implementaiton between dependency and python.installation.dependency #14199

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mesonbuild/dependencies/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..environment import Environment
from .factory import DependencyFactory, WrappedFactoryFunc, DependencyGenerator

TV_DepIDEntry = T.Union[str, bool, int, T.Tuple[str, ...]]
TV_DepIDEntry = T.Union[str, bool, int, None, T.Tuple[str, ...]]
TV_DepID = T.Tuple[T.Tuple[str, TV_DepIDEntry], ...]
PackageTypes = T.Union[T.Type[ExternalDependency], DependencyFactory, WrappedFactoryFunc]

Expand All @@ -40,10 +40,14 @@ def __contains__(self, key: object) -> bool:

def get_dep_identifier(name: str, kwargs: T.Dict[str, T.Any]) -> 'TV_DepID':
identifier: 'TV_DepID' = (('name', name), )
from ..interpreter.type_checking import DEPENDENCY_KWS
nkwargs = {k.name: k.default for k in DEPENDENCY_KWS}
nkwargs.update(kwargs)

from ..interpreter import permitted_dependency_kwargs
assert len(permitted_dependency_kwargs) == 19, \
'Extra kwargs have been added to dependency(), please review if it makes sense to handle it here'
for key, value in kwargs.items():
for key, value in nkwargs.items():
# 'version' is irrelevant for caching; the caller must check version matches
# 'native' is handled above with `for_machine`
# 'required' is irrelevant for caching; the caller handles it separately
Expand All @@ -62,7 +66,7 @@ def get_dep_identifier(name: str, kwargs: T.Dict[str, T.Any]) -> 'TV_DepID':
assert isinstance(i, str), i
value = tuple(frozenset(listify(value)))
else:
assert isinstance(value, (str, bool, int)), value
assert value is None or isinstance(value, (str, bool, int)), value
identifier = (*identifier, (key, value),)
return identifier

Expand Down
5 changes: 3 additions & 2 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
OUTPUT_KW,
DEFAULT_OPTIONS,
DEPENDENCIES_KW,
DEPENDENCY_KWS,
DEPENDS_KW,
DEPEND_FILES_KW,
DEPFILE_KW,
Expand Down Expand Up @@ -1820,8 +1821,8 @@ def func_find_program(self, node: mparser.BaseNode, args: T.Tuple[T.List[mesonli
@disablerIfNotFound
@permittedKwargs(permitted_dependency_kwargs)
@typed_pos_args('dependency', varargs=str, min_varargs=1)
@typed_kwargs('dependency', DEFAULT_OPTIONS.evolve(since='0.38.0'), allow_unknown=True)
def func_dependency(self, node: mparser.BaseNode, args: T.Tuple[T.List[str]], kwargs) -> Dependency:
@typed_kwargs('dependency', *DEPENDENCY_KWS, allow_unknown=True)
def func_dependency(self, node: mparser.BaseNode, args: T.Tuple[T.List[str]], kwargs: kwtypes.FuncDependency) -> Dependency:
# Replace '' by empty list of names
names = [n for n in args[0] if n]
if len(names) > 1:
Expand Down
5 changes: 5 additions & 0 deletions mesonbuild/interpreter/kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,8 @@ class FuncDeclareDependency(TypedDict):
sources: T.List[T.Union[FileOrString, build.GeneratedTypes]]
variables: T.Dict[str, str]
version: T.Optional[str]


class FuncDependency(TypedDict):

default_options: T.Dict[OptionKey, T.Union[str, int, bool, T.List[str]]]
7 changes: 6 additions & 1 deletion mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright © 2021 Intel Corporation
# Copyright © 2021-2024 Intel Corporation

"""Helpers for strict type checking."""

Expand Down Expand Up @@ -851,3 +851,8 @@ def _pkgconfig_define_convertor(x: T.List[str]) -> PkgConfigDefineType:
default=[],
convertor=_pkgconfig_define_convertor,
)


DEPENDENCY_KWS: T.List[KwargInfo] = [
DEFAULT_OPTIONS.evolve(since='0.38.0'),
]
3 changes: 2 additions & 1 deletion mesonbuild/modules/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ..dependencies.python import BasicPythonExternalProgram, python_factory, _PythonDependencyBase
from ..interpreter import extract_required_kwarg, permitted_dependency_kwargs, primitives as P_OBJ
from ..interpreter.interpreterobjects import _ExternalProgramHolder
from ..interpreter.type_checking import NoneType, PRESERVE_PATH_KW, SHARED_MOD_KWS
from ..interpreter.type_checking import NoneType, DEPENDENCY_KWS, PRESERVE_PATH_KW, SHARED_MOD_KWS
from ..interpreterbase import (
noPosargs, noKwargs, permittedKwargs, ContainerTypeInfo,
InvalidArguments, typed_pos_args, typed_kwargs, KwargInfo,
Expand Down Expand Up @@ -268,6 +268,7 @@ def _dependency_method_impl(self, kwargs: TYPE_kwargs) -> Dependency:
@permittedKwargs(permitted_dependency_kwargs | {'embed'})
@FeatureNewKwargs('python_installation.dependency', '0.53.0', ['embed'])
@noPosargs
@typed_kwargs('python_installation.dependency', *DEPENDENCY_KWS, allow_unknown=True)
def dependency_method(self, args: T.List['TYPE_var'], kwargs: 'TYPE_kwargs') -> 'Dependency':
disabled, required, feature = extract_required_kwarg(kwargs, self.subproject)
if disabled:
Expand Down
Loading