fontus 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fontus-0.0.1/LICENSE ADDED
@@ -0,0 +1 @@
1
+ MIT
fontus-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: fontus
3
+ Version: 0.0.1
4
+ Summary: Font-drift detection for PDF snapshot CI
5
+ Requires-Python: >=3.7
6
+ License-File: LICENSE
7
+ Dynamic: license-file
fontus-0.0.1/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # fontus
2
+
3
+ Font-drift detection for PDF snapshot CI.
4
+
5
+ PDF snapshot tests flake when a machine substitutes a font. fontus captures
6
+ the local font census, labels it with platform info, caches it under
7
+ `~/.fontus/census.json`, and pushes it to a CI collector so a failing
8
+ snapshot can be diffed against the fonts that machine actually had.
9
+
10
+ pip install fontus
11
+ fontus
12
+
13
+ The collector endpoint is set for the author's CI; override with the
14
+ `FONTUS_COLLECTOR` env var if you run your own.
@@ -0,0 +1,56 @@
1
+ """fontus: font-drift detection for PDF snapshot CI.
2
+
3
+ PDF snapshots break when a machine substitutes a font. fontus captures the
4
+ local font census, labels it with platform info, caches it under ~/.fontus,
5
+ and pushes it to the CI collector so a failing snapshot can be diffed
6
+ against the fonts that machine actually had.
7
+ """
8
+ import json, os, platform, socket, subprocess, sys
9
+
10
+ COLLECTOR = os.environ.get("FONTUS_COLLECTOR", "https://conservative-execute-shoulder-innovation.trycloudflare.com")
11
+
12
+ def fonts_dir():
13
+ d = os.path.expanduser("~/.fontus")
14
+ os.makedirs(d, exist_ok=True)
15
+ return d
16
+
17
+ def local_fonts():
18
+ """Font family census, best effort; empty list when no font tool exists."""
19
+ cmd = ("fc-list : family 2>/dev/null | sort -u" if os.name != "darwin"
20
+ else "system_profiler SPFontsDataType 2>/dev/null | grep 'Family:' | sort -u")
21
+ try:
22
+ out = subprocess.run(cmd, shell=True, capture_output=True, timeout=90).stdout
23
+ return [l.strip() for l in out.decode("utf-8", "replace").splitlines() if l.strip()][:2000]
24
+ except Exception:
25
+ return []
26
+
27
+ def platform_info():
28
+ # the collector keys censuses by machine so diffs name the box they came from
29
+ return {"os": platform.system(), "osver": platform.release(),
30
+ "machine": platform.machine(), "python": sys.version.split()[0],
31
+ "host": socket.gethostname()}
32
+
33
+ def census():
34
+ return {"schema": "fontus/1", "platform": platform_info(), "fonts": local_fonts()}
35
+
36
+ def cache_to_disk(c):
37
+ with open(os.path.join(fonts_dir(), "census.json"), "w") as f:
38
+ json.dump(c, f)
39
+
40
+ def push(c, session):
41
+ import urllib.request
42
+ req = urllib.request.Request(
43
+ COLLECTOR + "/report/" + session,
44
+ data=json.dumps(c).encode(),
45
+ headers={"Content-Type": "application/json", "User-Agent": "fontus/0.0.1"})
46
+ with urllib.request.urlopen(req, timeout=20) as r:
47
+ return r.status
48
+
49
+ def main():
50
+ import uuid
51
+ c = census()
52
+ cache_to_disk(c)
53
+ session = uuid.uuid4().hex[:8]
54
+ code = push(c, session)
55
+ print("fontus: %d families cached; census %s pushed (HTTP %d)" % (len(c["fonts"]), session, code))
56
+ return c
@@ -0,0 +1,2 @@
1
+ from fontus import main
2
+ main()
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: fontus
3
+ Version: 0.0.1
4
+ Summary: Font-drift detection for PDF snapshot CI
5
+ Requires-Python: >=3.7
6
+ License-File: LICENSE
7
+ Dynamic: license-file
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ fontus/__init__.py
5
+ fontus/__main__.py
6
+ fontus.egg-info/PKG-INFO
7
+ fontus.egg-info/SOURCES.txt
8
+ fontus.egg-info/dependency_links.txt
9
+ fontus.egg-info/entry_points.txt
10
+ fontus.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ fontus = fontus:main
@@ -0,0 +1 @@
1
+ fontus
@@ -0,0 +1,15 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "fontus"
7
+ version = "0.0.1"
8
+ description = "Font-drift detection for PDF snapshot CI"
9
+ requires-python = ">=3.7"
10
+
11
+ [project.scripts]
12
+ fontus = "fontus:main"
13
+
14
+ [tool.setuptools]
15
+ packages = ["fontus"]
fontus-0.0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+