Debian Codegraph @

DisplayCAL/meta.py

raw
1 """Meta information."""
2
3 from __future__ import annotations
4
5 import os
6 import re
7 import sys
8
9 # globals
10 VERSION_STRING = None
11 if getattr(sys, "frozen", False):
12 base_path = os.path.dirname(sys.executable)
13 if sys.platform == "darwin":
14 _base_path = os.path.join(os.path.dirname(base_path), "Resources")
15 if os.path.isdir(_base_path):
16 base_path = _base_path
17 else:
18 base_path = os.path.dirname(__file__)
19 VERSION_FILE = os.path.join(base_path, "VERSION")
20
21 # If it's not in the root, check the DisplayCAL subfolder just in case
22 if not os.path.isfile(VERSION_FILE):
23 VERSION_FILE = os.path.join(base_path, "DisplayCAL", "VERSION")
24
25 if os.path.isfile(VERSION_FILE):
26 with open(VERSION_FILE, encoding="utf-8") as f:
27 VERSION_STRING = f.read().strip()
28 VERSION_STRING = VERSION_STRING or "0.0.0"
29 """str: The version number of DisplayCAL."""
30
31 AUTHOR = "Florian Höch, Erkan Özgür Yılmaz, Patrick Zwerschke" # noqa: RUF001
32 AUTHOR_ASCII = "Florian Hoech, Erkan Ozgur Yilmaz, Patrick Zwerschke"
33 DESCRIPTION = (
34 "Display calibration and profiling with a focus on accuracy and versatility"
35 )
36 LONG_DESCRIPTION = (
37 "Calibrate and characterize your display devices using one of many supported "
38 "measurement instruments, with support for multi-display setups and a variety of "
39 "available options for advanced users, such as verification and reporting "
40 "functionality to evaluate ICC profiles and display devices, creating video 3D "
41 "LUTs, as well as optional CIECAM02 gamut mapping to take into account varying "
42 "viewing conditions."
43 )
44 DOMAIN = "displaycal.net"
45 DEVELOPMENT_HOME_PAGE = "https://github.com/eoyilmaz/displaycal-py3"
46 GITHUB_API_URL = "https://api.github.com/repos/eoyilmaz/displaycal-py3"
47
48 AUTHOR_EMAIL = ", ".join(
49 [
50 f"florian{chr(0o100)}{DOMAIN}",
51 f"eoyilmaz{chr(0o100)}gmail.com",
52 f"patrick{chr(0o100)}p5k.org",
53 ]
54 )
55 NAME = "DisplayCAL"
56 APPSTREAM_ID = ".".join(reversed([NAME, *DOMAIN.split(".")]))
57 NAME_HTML = '<span class="appname">Display<span>CAL</span></span>'
58
59 PY_MINVERSION = (3, 10)
60 PY_MAXVERSION = (3, 14)
61
62 VERSION_LIN = VERSION_STRING # Linux
63 VERSION_MAC = VERSION_STRING # Mac OS X
64 VERSION_WIN = VERSION_STRING # Windows
65 VERSION_SRC = VERSION_STRING
66 # follow semver format
67 VERSION_TUPLE = tuple(int(n) for n in VERSION_STRING.split("-")[0].split(".")[:3])
68 """tuple[int, int, int]: The version number as a tuple of integers."""
69
70 WX_MINVERSION = (4, 0, 0)
71 WX_RECVERSION = (4, 2, 0)
72
73
74 def get_latest_changelog_entry(readme: str) -> None | str:
75 """Get changelog entry for latest version from ReadMe HTML.
76
77 Args:
78 readme (str): ReadMe HTML content.
79
80 Returns:
81 None | str: Changelog entry or None if not found.
82 """
83 changelog = re.search(
84 r'<div id="(?:changelog|history)">.+?<h2>.+?</h2>.+?<dl>.+?</dd>', readme, re.S
85 )
86
87 if changelog:
88 changelog = changelog.group()
89 changelog = re.sub(r'\s*<div id="(?:changelog|history)">\n?', "", changelog)
90 changelog = re.sub(r"\s*</?d[ld]>\n?", "", changelog)
91 changelog = re.sub(r"\s*<(h[23])>.+?</\1>\n?", "", changelog)
92
93 return changelog
94
95
96 def script2pywname(script: str) -> str:
97 """Convert all-lowercase script name to mixed-case pyw name."""
98 a2b = {
99 f"{NAME}-3dlut-maker": f"{NAME}-3DLUT-maker",
100 f"{NAME}-vrml-to-x3d-converter": f"{NAME}-VRML-to-X3D-converter",
101 f"{NAME}-eecolor-to-madvr-converter": f"{NAME}-eeColor-to-madVR-converter",
102 }
103 if script.lower().startswith(NAME.lower()):
104 pyw = f"{NAME}{script[len(NAME) :]}"
105 return a2b.get(pyw, pyw)
106 return script