Skip to content

Commit

Permalink
fixup! dependencies: use a concrete type for Dependency cache keys
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbaker committed Dec 6, 2023
1 parent df635b5 commit d323faa
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions mesonbuild/dependencies/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,12 @@
from .. import mlog

if T.TYPE_CHECKING:
from typing_extensions import TypedDict

from ..environment import Environment
from ..interpreter.kwargs import Dependency as DependencyKw
from .factory import DependencyFactory, WrappedFactoryFunc, DependencyGenerator

PackageTypes = T.Union[T.Type[ExternalDependency], DependencyFactory, WrappedFactoryFunc]

class DependencyCacheKeyInit(TypedDict, total=False):
cmake_args: T.Tuple[str, ...]
cmake_module_path: T.Tuple[str, ...]
cmake_package_version: str
components: T.Tuple[str, ...]
language: T.Optional[str]
main: bool
method: str
modules: T.Tuple[str, ...]
optional_modules: T.Tuple[str, ...]
private_headers: bool
static: T.Optional[bool]
embed: bool

class DependencyPackages(collections.UserDict):
data: T.Dict[str, PackageTypes]
defaults: T.Dict[str, str] = {}
Expand Down Expand Up @@ -90,7 +74,7 @@ class DependencyCacheKey:


def get_dep_identifier(name: str, kwargs: DependencyKw) -> DependencyCacheKey:
nkwargs: DependencyCacheKeyInit = {}
key = DependencyCacheKey(kwargs['name'])
for k, v in kwargs.items():
# 'version' is irrelevant for caching; the caller must check version matches
# 'native' is handled above with `for_machine`
Expand All @@ -103,13 +87,12 @@ def get_dep_identifier(name: str, kwargs: DependencyKw) -> DependencyCacheKey:
# 'include_type' is handled after the dependency lookup
if k not in _DEPEDNENCY_CACHE_KEYS:
continue
# Mypy doesn't (yet) understand iterating a TypedDict, and doesn't know that k is valid
if isinstance(v, list):
nkwargs[k] = tuple(v) # type: ignore[literal-required]
setattr(key, k, tuple(v))
else:
nkwargs[k] = v # type: ignore[literal-required]
setattr(key, k, v)

return DependencyCacheKey(name, **nkwargs)
return key


display_name_map = {
Expand Down

0 comments on commit d323faa

Please sign in to comment.