Skip to content

Commit 94d71a6

Browse files
committed
Address version compatibility review
1 parent e95d3bf commit 94d71a6

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/nodenorm/handlers/version.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ class VersionHandler(BaseHandler):
99
name = "version"
1010

1111
async def get(self, *args, **kwargs):
12-
version = await asyncio.to_thread(get_version)
12+
loop = asyncio.get_running_loop()
13+
version = await loop.run_in_executor(None, get_version)
1314
self.write({"version": version})

src/nodenorm/version.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
22
import os
33
import pathlib
4-
from collections.abc import Iterable
5-
from functools import cache
4+
from functools import lru_cache
5+
from typing import Iterable, Optional
66

77
from git import InvalidGitRepositoryError, NoSuchPathError, Repo
88

@@ -14,7 +14,7 @@
1414
CONTAINER_VERSION_FILE = pathlib.Path("/home/nodenorm/configuration") / VERSION_FILE_NAME
1515

1616

17-
def read_version_file(version_file_paths: Iterable[pathlib.Path] | None = None) -> str | None:
17+
def read_version_file(version_file_paths: Optional[Iterable[pathlib.Path]] = None) -> Optional[str]:
1818
"""Read the build-time version file when the app is running from a packaged image."""
1919
candidate_paths = []
2020
configured_path = os.getenv(VERSION_FILE_ENV_VAR)
@@ -38,8 +38,8 @@ def read_version_file(version_file_paths: Iterable[pathlib.Path] | None = None)
3838
return None
3939

4040

41-
@cache
42-
def get_github_commit_hash(source_path: pathlib.Path | None = None) -> str:
41+
@lru_cache(maxsize=None)
42+
def get_github_commit_hash(source_path: Optional[pathlib.Path] = None) -> str:
4343
"""Retrieve the current GitHub commit hash using gitpython."""
4444
try:
4545
repo_path = source_path or pathlib.Path(__file__).resolve()
@@ -54,6 +54,6 @@ def get_github_commit_hash(source_path: pathlib.Path | None = None) -> str:
5454
return UNKNOWN_VERSION
5555

5656

57-
@cache
57+
@lru_cache(maxsize=None)
5858
def get_version() -> str:
5959
return read_version_file() or get_github_commit_hash()

0 commit comments

Comments
 (0)