Coverage for debputy/plugins/numpy3.py: 85%
34 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-09-07 09:27 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-09-07 09:27 +0000
1import functools
2import os
3from typing import Any, Tuple
5from debputy.plugin.api import (
6 BinaryCtrlAccessor,
7 PackageProcessingContext,
8 define_debputy_plugin,
9)
10from debputy.util import _error
12plugin_definition = define_debputy_plugin()
15@functools.lru_cache
16def _parse_numpy3_versions(versions_file: str) -> Tuple[str, str]:
17 attributes = {}
18 try:
19 with open(versions_file, "rt", encoding="utf-8") as fd:
20 for line in fd:
21 if line.startswith("#") or line.isspace():
22 continue
23 k, v = line.split()
24 attributes[k] = v
25 except FileNotFoundError:
26 _error(
27 f"Missing Build-Dependency on python3-numpy to ensure {versions_file}"
28 " is present."
29 )
31 try:
32 api_min_version = attributes["api-min-version"]
33 abi_version = attributes["abi"]
34 except KeyError as e:
35 k = e.args[0]
36 _error(f'Expected {versions_file} to contain the key "{k}"')
37 assert False
39 return api_min_version, abi_version
42@plugin_definition.metadata_or_maintscript_detector(
43 # Probably not necessary, but this is the most faithful conversion
44 package_type=["deb", "udeb"],
45)
46def numpy_depends(
47 _unused: Any,
48 ctrl: BinaryCtrlAccessor,
49 context: PackageProcessingContext,
50) -> None:
51 if context.binary_package.is_arch_all:
52 dep = "python3-numpy"
53 else:
54 # Note we do not support --strict; codesearch.d.n suggests it is not used
55 # anywhere and this saves us figuring out how to support it here.
56 versions_file = os.environ.get("_NUMPY_TEST_PATH", "/usr/share/numpy3/versions")
57 api_min_version, abi_version = _parse_numpy3_versions(versions_file)
58 dep = f"python3-numpy (>= {api_min_version}), python3-numpy-abi{abi_version}"
59 ctrl.substvars.add_dependency("python3:Depends", dep)