Skip to content

Commit

Permalink
Use formatted version for cache path if available, else original string
Browse files Browse the repository at this point in the history
  • Loading branch information
bjhardcastle committed Jan 10, 2024
1 parent 616aaa9 commit a2db5a1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/npc_lims/paths/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ def get_current_cache_version() -> str:


def _parse_version(version: str) -> str:
"""
>>> _parse_version("0.0.0")
'v0.0.0'
>>> _parse_version("v0.0.0")
'v0.0.0'
>>> _parse_version("test")
Traceback (most recent call last):
...
ValueError: Invalid version 'test'
"""
try:
return f"v{packaging.version.parse(str(version))}"
except packaging.version.InvalidVersion:
Expand All @@ -77,7 +87,13 @@ def _parse_cache_path(
session_id: str | npc_session.SessionRecord | None = None,
version: str | None = None,
) -> upath.UPath:
version = version or get_current_cache_version()
if version is not None:
try:
version = _parse_version(version)
except ValueError:
version = version
else:
version = get_current_cache_version()
d = (
CACHE_ROOT
/ version
Expand Down

0 comments on commit a2db5a1

Please sign in to comment.