From 23bffeb5514e3593f6425a04a61c6e712a1beed7 Mon Sep 17 00:00:00 2001 From: Caleb Date: Fri, 11 Oct 2024 10:03:18 -0400 Subject: [PATCH 1/2] cache parse_dmi() --- ixhardware/dmi.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ixhardware/dmi.py b/ixhardware/dmi.py index 7b66025..43dbf5a 100644 --- a/ixhardware/dmi.py +++ b/ixhardware/dmi.py @@ -1,8 +1,8 @@ from dataclasses import dataclass from datetime import date, datetime +from functools import cache import logging import subprocess -from typing import Optional logger = logging.getLogger(__name__) @@ -11,7 +11,7 @@ @dataclass class DMIInfo: - bios_release_date: Optional[date] = None + bios_release_date: date | None = None ecc_memory: bool = False baseboard_manufacturer: str = "" baseboard_product_name: str = "" @@ -28,7 +28,7 @@ class DMIParser: def parse(self, output: str) -> DMIInfo: return self._parse_dmi(output.splitlines()) - def _parse_dmi(self, lines: [str]) -> DMIInfo: + def _parse_dmi(self, lines: list[str]) -> DMIInfo: info = DMIInfo() _type = None @@ -89,11 +89,20 @@ def _parse_bios_release_date(self, string): try: return datetime.strptime(string, formatter).date() except Exception as e: - logger.warning(f"Failed to format BIOS release date to datetime object: {e!r}") + logger.warning( + f"Failed to format BIOS release date to datetime object: {e!r}" + ) +@cache def parse_dmi() -> DMIInfo: return DMIParser().parse( - subprocess.run(DMIParser.command, check=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, - encoding="utf-8", errors="ignore").stdout + subprocess.run( + DMIParser.command, + check=False, + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, + encoding="utf-8", + errors="ignore", + ).stdout ) From fbd6e3d37d4d7c05604489b7f872d2ad4b206fd2 Mon Sep 17 00:00:00 2001 From: Caleb Date: Fri, 11 Oct 2024 10:46:50 -0400 Subject: [PATCH 2/2] fix github actions --- .github/workflows/unit_tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index f6e80e4..69d7e5d 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v1 + - uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: '3.11' - name: Install pytest run: | python -m pip install --upgrade pip