-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversioning.py
More file actions
61 lines (48 loc) · 1.67 KB
/
versioning.py
File metadata and controls
61 lines (48 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Centralised version and naming information for SRPSS.
This module is the single source of truth for application version,
executable name, and human-readable metadata. Both the runtime and
build tooling import this so we do not duplicate strings across the
codebase.
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Tuple
APP_NAME: str = "ShittyRandomPhotoScreenSaver"
APP_EXE_NAME: str = "SRPSS"
APP_VERSION: str = "4.2"
# Short description is used for Windows file metadata (Task Manager shows this string).
APP_DESCRIPTION: str = "ShittyRandomPhotoScreenSaver"
# Preserve the long-form marketing description for release notes, website copy, etc.
APP_TAGLINE: str = (
"ShittyRandomPhotoScreenSaver - Random Image Screensaver & Media Centre. "
)
APP_COMPANY: str = "Jayde Ver Elst"
@dataclass(frozen=True)
class VersionInfo:
major: int
minor: int
patch: int
def to_tuple(self) -> Tuple[int, int, int]:
return (self.major, self.minor, self.patch)
def parse_version(version_str: str = APP_VERSION) -> VersionInfo:
"""Parse a semantic-ish version string ``MAJOR.MINOR.PATCH``.
Falls back to ``0.0.0`` on parse errors so callers always receive a
usable object.
"""
try:
parts = [int(p) for p in str(version_str).split(".")[:3]]
while len(parts) < 3:
parts.append(0)
return VersionInfo(parts[0], parts[1], parts[2])
except (ValueError, TypeError, IndexError):
return VersionInfo(0, 0, 0)
__all__ = [
"APP_NAME",
"APP_EXE_NAME",
"APP_VERSION",
"APP_DESCRIPTION",
"APP_TAGLINE",
"APP_COMPANY",
"VersionInfo",
"parse_version",
]