diff --git a/CHANGELOG.md b/CHANGELOG.md index 07cb4b6..246ac30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ recorded here; their history is the git log. ## [Unreleased] +## [4.59.0] - 2026-12-05 + +### Added +- `PackageDict`: optional `architecture`, the build's architecture in the package + manager's own words (`x64`, `x86`, `arm64` on Windows; `amd64`, `i386`, `all` from + dpkg; `x86_64`, `noarch` from rpm). It tells apart two packages of one name, such as a + multiarch host's `libc6` for amd64 and for i386 (NetOrk/netork#2907). A driver that + cannot tell leaves it out. `PackageDict` moves to `package_models`; `models` + re-exports it, so every import keeps working. + ### Fixed - A key declared `NotRequired` is optional at runtime too: `__optional_keys__` of `KernelFactsDict`, `HostRepairResultDict`, `LldpNeighborDict`, `LogSourceDict`, @@ -14,7 +24,8 @@ recorded here; their history is the git log. and `ZabbixAgentSettingsDict` was empty, and their optional keys read as required. Their modules postponed annotations (`from __future__ import annotations`), and TypedDict sees `NotRequired` only in an evaluated annotation. Type checking was not affected. A - test now walks every TypedDict in the package for an annotation it could not read. + test now walks every TypedDict in the package for an annotation it could not read + (#144). ## [4.58.1] - 2026-12-03 diff --git a/napalm_device_types/models.py b/napalm_device_types/models.py index 571e965..a11e997 100644 --- a/napalm_device_types/models.py +++ b/napalm_device_types/models.py @@ -10,8 +10,8 @@ from typing_extensions import TypedDict # The SNMP health profile shapes live in snmp_health_profile.py, those of the access # point getters in access_point_models.py, an OS's accounts and processes in -# os_models.py, the host firewall's in host_firewall_models.py; re-exported here, -# where they were. +# os_models.py, the host firewall's in host_firewall_models.py, an installed package's +# in package_models.py; re-exported here, where they were. from napalm_device_types.access_point_models import ChannelScanEntryDict as ChannelScanEntryDict from napalm_device_types.access_point_models import ( FastTransitionConfigDict as FastTransitionConfigDict, @@ -30,6 +30,7 @@ from napalm_device_types.host_firewall_models import NetfilterRuleDict as Netfil from napalm_device_types.kernel_models import KernelFactsDict as KernelFactsDict from napalm_device_types.os_models import ProcessDict as ProcessDict from napalm_device_types.os_models import UserDict as UserDict +from napalm_device_types.package_models import PackageDict as PackageDict from napalm_device_types.share_models import NASShareDict as NASShareDict from napalm_device_types.share_models import ShareAccessDict as ShareAccessDict from napalm_device_types.snmp_health_profile import SnmpHealthProfile as SnmpHealthProfile @@ -67,17 +68,6 @@ class MACACLDict(TypedDict): entries: list[MACACLEntryDict] -class PackageDict(TypedDict): - """A software package / plugin installed on the device.""" - - name: str - version: str - installed: bool - description: str - size: int - source: str - - #: A service's last run ended as it should, or it has not ended (systemd's ``Result``). SERVICE_RESULT_SUCCESS = "success" #: A service's last run ended with an exit code that is not success. diff --git a/napalm_device_types/package_models.py b/napalm_device_types/package_models.py new file mode 100644 index 0000000..6d01eb4 --- /dev/null +++ b/napalm_device_types/package_models.py @@ -0,0 +1,31 @@ +"""The shape of an installed package (``PackageManagementMixin.get_packages``). + +A module of its own rather than in :mod:`napalm_device_types.models`, which re-exports +it: the package grew its architecture (NetOrk/netork#2907), and ``models`` is at its +recorded size. +""" + +# No ``from __future__ import annotations``: TypedDict tells a ``NotRequired`` key only +# from an evaluated annotation (``PackageDict.__optional_keys__``). +from typing import NotRequired + +from typing_extensions import TypedDict + + +class PackageDict(TypedDict): + """A software package / plugin installed on the device. + + ``architecture`` is the build's architecture in the package manager's own words: + ``x64``, ``x86`` or ``arm64`` on Windows, ``amd64``, ``i386`` or ``all`` from dpkg, + ``x86_64`` or ``noarch`` from rpm. It tells apart two packages of one name, as a + Debian multiarch host's ``libc6`` for amd64 and for i386 or a 32-bit and a 64-bit + install of one Windows program. A driver that cannot tell leaves it out. + """ + + name: str + version: str + installed: bool + description: str + size: int + source: str + architecture: NotRequired[str] diff --git a/pyproject.toml b/pyproject.toml index 1da2458..50dce04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "napalm-device-types" -version = "4.58.1" +version = "4.59.0" description = "Abstract device-type base classes for NAPALM drivers" readme = "README.md" requires-python = ">=3.12" diff --git a/tests/quality_baseline.json b/tests/quality_baseline.json index e58db2a..ae798d0 100644 --- a/tests/quality_baseline.json +++ b/tests/quality_baseline.json @@ -31,7 +31,7 @@ }, "mypy_relaxed": [], "python_file_lines": { - "napalm_device_types/models.py": 1286 + "napalm_device_types/models.py": 1276 }, "untyped_public": [] } diff --git a/tests/test_package_models.py b/tests/test_package_models.py new file mode 100644 index 0000000..46814e0 --- /dev/null +++ b/tests/test_package_models.py @@ -0,0 +1,24 @@ +"""PackageDict: one installed package, told apart from its namesakes by architecture. + +A host can list one name twice: Debian multiarch installs ``libc6`` for amd64 and for +i386, Windows a 32-bit and a 64-bit build of one program (NetOrk/netork#2907). +""" + +from napalm_device_types import models +from napalm_device_types.package_models import PackageDict + + +def test_architecture_is_the_one_optional_key() -> None: + assert PackageDict.__optional_keys__ == {"architecture"} + assert PackageDict.__required_keys__ == { + "name", + "version", + "installed", + "description", + "size", + "source", + } + + +def test_models_re_exports_it() -> None: + assert models.PackageDict is PackageDict