sciencelogo-documenter 0.0.1__py3-none-any.whl
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.
- sciencelogo_documenter/__init__.py +3 -0
- sciencelogo_documenter/__main__.py +3 -0
- sciencelogo_documenter/booklet.py +18 -0
- sciencelogo_documenter/bootstrap.py +111 -0
- sciencelogo_documenter/build.py +96 -0
- sciencelogo_documenter/cli.py +65 -0
- sciencelogo_documenter/config.py +143 -0
- sciencelogo_documenter/fonts/atkinson-hyperlegible-mono/AtkinsonHyperlegibleMono-Bold.ttf +0 -0
- sciencelogo_documenter/fonts/atkinson-hyperlegible-mono/AtkinsonHyperlegibleMono-Italic.ttf +0 -0
- sciencelogo_documenter/fonts/atkinson-hyperlegible-mono/AtkinsonHyperlegibleMono-Regular.ttf +0 -0
- sciencelogo_documenter/fonts/atkinson-hyperlegible-mono/OFL.txt +93 -0
- sciencelogo_documenter/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Bold.ttf +0 -0
- sciencelogo_documenter/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-BoldItalic.ttf +0 -0
- sciencelogo_documenter/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Italic.ttf +0 -0
- sciencelogo_documenter/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-Regular.ttf +0 -0
- sciencelogo_documenter/fonts/atkinson-hyperlegible-next/OFL.txt +93 -0
- sciencelogo_documenter/fonts/ibm-plex-sans/IBMPlexSans-Bold.woff2 +0 -0
- sciencelogo_documenter/fonts/ibm-plex-sans/IBMPlexSans-BoldItalic.woff2 +0 -0
- sciencelogo_documenter/fonts/ibm-plex-sans/IBMPlexSans-Italic.woff2 +0 -0
- sciencelogo_documenter/fonts/ibm-plex-sans/IBMPlexSans-Regular.woff2 +0 -0
- sciencelogo_documenter/fonts/ibm-plex-sans/LICENSE.txt +93 -0
- sciencelogo_documenter/fonts/ibm-plex-serif/IBMPlexSerif-Bold.woff2 +0 -0
- sciencelogo_documenter/fonts/ibm-plex-serif/IBMPlexSerif-BoldItalic.woff2 +0 -0
- sciencelogo_documenter/fonts/ibm-plex-serif/IBMPlexSerif-Italic.woff2 +0 -0
- sciencelogo_documenter/fonts/ibm-plex-serif/IBMPlexSerif-Regular.woff2 +0 -0
- sciencelogo_documenter/fonts/ibm-plex-serif/LICENSE.txt +93 -0
- sciencelogo_documenter/publish.py +105 -0
- sciencelogo_documenter/racket/code.rkt +62 -0
- sciencelogo_documenter/racket/extract.rkt +285 -0
- sciencelogo_documenter/racket/html.rkt +623 -0
- sciencelogo_documenter/racket/main.rkt +71 -0
- sciencelogo_documenter/racket/markers.rkt +95 -0
- sciencelogo_documenter/racket/markup.rkt +53 -0
- sciencelogo_documenter/racket/structure.rkt +38 -0
- sciencelogo_documenter/racket/typst.rkt +264 -0
- sciencelogo_documenter/racket/values.rkt +130 -0
- sciencelogo_documenter/racket/verbose.rkt +40 -0
- sciencelogo_documenter/static/site.css +130 -0
- sciencelogo_documenter/static/site.js +139 -0
- sciencelogo_documenter/static/template.typ +206 -0
- sciencelogo_documenter/versions.py +32 -0
- sciencelogo_documenter-0.0.1.dist-info/METADATA +369 -0
- sciencelogo_documenter-0.0.1.dist-info/RECORD +47 -0
- sciencelogo_documenter-0.0.1.dist-info/WHEEL +5 -0
- sciencelogo_documenter-0.0.1.dist-info/entry_points.txt +2 -0
- sciencelogo_documenter-0.0.1.dist-info/licenses/LICENSE +21 -0
- sciencelogo_documenter-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Compiles the booklet with Typst."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import typst
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def compile_booklet(source: Path, output: Path, font_dirs: list[Path]) -> None:
|
|
11
|
+
"""Compile `source` (booklet.typ) to the PDF `output`, using only the given fonts."""
|
|
12
|
+
typst.compile(
|
|
13
|
+
str(source),
|
|
14
|
+
output=str(output),
|
|
15
|
+
root=str(source.parent),
|
|
16
|
+
font_paths=[str(d) for d in font_dirs],
|
|
17
|
+
ignore_system_fonts=True,
|
|
18
|
+
)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""Racket and the `sciencelogo` package, downloaded once and kept in a cache."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import os
|
|
7
|
+
import platform
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
import tarfile
|
|
12
|
+
import tempfile
|
|
13
|
+
import urllib.request
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
from sciencelogo_documenter import versions
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BootstrapError(RuntimeError):
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def cache_root() -> Path:
|
|
24
|
+
"""The folder that holds the Documenter's downloads."""
|
|
25
|
+
explicit = os.environ.get("SCIENCELOGO_DOCUMENTER_CACHE")
|
|
26
|
+
if explicit:
|
|
27
|
+
return Path(explicit)
|
|
28
|
+
base = os.environ.get("XDG_CACHE_HOME")
|
|
29
|
+
return (Path(base) if base else Path.home() / ".cache") / "sciencelogo-documenter"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def platform_key() -> str:
|
|
33
|
+
machine = platform.machine().lower()
|
|
34
|
+
system = platform.system().lower()
|
|
35
|
+
if machine in ("x86_64", "amd64") and system == "linux":
|
|
36
|
+
return "x86_64-linux"
|
|
37
|
+
raise BootstrapError(f"no pinned Racket build for {system} on {machine}")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _versions(overrides: dict | None) -> dict:
|
|
41
|
+
overrides = overrides or {}
|
|
42
|
+
url, sha256 = (None, None)
|
|
43
|
+
if overrides.get("racket_url"):
|
|
44
|
+
url, sha256 = overrides["racket_url"], overrides.get("racket_sha256")
|
|
45
|
+
else:
|
|
46
|
+
url, sha256 = versions.racket_tarball(platform_key())
|
|
47
|
+
return {
|
|
48
|
+
"racket_url": url,
|
|
49
|
+
"racket_sha256": sha256,
|
|
50
|
+
"sciencelogo_url": overrides.get("sciencelogo_url") or versions.SCIENCELOGO_URL,
|
|
51
|
+
"sciencelogo_checksum": overrides.get("sciencelogo_checksum") or versions.SCIENCELOGO_CHECKSUM,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _download(url: str, dest: Path) -> None:
|
|
56
|
+
with urllib.request.urlopen(url, timeout=120) as response, open(dest, "wb") as out:
|
|
57
|
+
shutil.copyfileobj(response, out)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _sha256(path: Path) -> str:
|
|
61
|
+
digest = hashlib.sha256()
|
|
62
|
+
with open(path, "rb") as f:
|
|
63
|
+
for chunk in iter(lambda: f.read(1 << 20), b""):
|
|
64
|
+
digest.update(chunk)
|
|
65
|
+
return digest.hexdigest()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def racket_bin(overrides: dict | None = None) -> Path:
|
|
69
|
+
"""Return the `bin` folder of a Racket that has `sciencelogo` installed.
|
|
70
|
+
|
|
71
|
+
The environment variable SCIENCELOGO_DOCUMENTER_RACKET can name the `bin`
|
|
72
|
+
folder of an existing installation instead.
|
|
73
|
+
"""
|
|
74
|
+
existing = os.environ.get("SCIENCELOGO_DOCUMENTER_RACKET")
|
|
75
|
+
if existing:
|
|
76
|
+
return Path(existing)
|
|
77
|
+
|
|
78
|
+
chosen = _versions(overrides)
|
|
79
|
+
key = hashlib.sha256(repr(sorted(chosen.items())).encode()).hexdigest()[:12]
|
|
80
|
+
dest = cache_root() / f"racket-{key}"
|
|
81
|
+
if (dest / ".complete").exists():
|
|
82
|
+
return dest / "bin"
|
|
83
|
+
|
|
84
|
+
print("Installing Racket and the sciencelogo package (first run only)...", file=sys.stderr)
|
|
85
|
+
cache_root().mkdir(parents=True, exist_ok=True)
|
|
86
|
+
if dest.exists():
|
|
87
|
+
shutil.rmtree(dest)
|
|
88
|
+
with tempfile.TemporaryDirectory(dir=cache_root()) as tmp:
|
|
89
|
+
tmp_path = Path(tmp)
|
|
90
|
+
tarball = tmp_path / "racket.tgz"
|
|
91
|
+
_download(chosen["racket_url"], tarball)
|
|
92
|
+
if chosen["racket_sha256"] and _sha256(tarball) != chosen["racket_sha256"]:
|
|
93
|
+
raise BootstrapError("the Racket download does not match its pinned checksum")
|
|
94
|
+
with tarfile.open(tarball) as archive:
|
|
95
|
+
archive.extractall(tmp_path / "unpacked", filter="data")
|
|
96
|
+
# Racket is installed in place, so it is moved before any package is added.
|
|
97
|
+
(tmp_path / "unpacked" / "racket").rename(dest)
|
|
98
|
+
result = subprocess.run(
|
|
99
|
+
[
|
|
100
|
+
str(dest / "bin" / "raco"), "pkg", "install", "--auto", "--batch", "--no-docs",
|
|
101
|
+
"--scope", "installation",
|
|
102
|
+
"--checksum", chosen["sciencelogo_checksum"],
|
|
103
|
+
chosen["sciencelogo_url"],
|
|
104
|
+
],
|
|
105
|
+
capture_output=True,
|
|
106
|
+
text=True,
|
|
107
|
+
)
|
|
108
|
+
if result.returncode != 0:
|
|
109
|
+
raise BootstrapError("installing the sciencelogo package failed:\n" + result.stderr[-4000:])
|
|
110
|
+
(dest / ".complete").write_text("ok\n")
|
|
111
|
+
return dest / "bin"
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Builds the website and the booklet of one workflow."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import tempfile
|
|
10
|
+
from importlib.resources import as_file, files
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from sciencelogo_documenter import bootstrap, config
|
|
14
|
+
from sciencelogo_documenter.booklet import compile_booklet
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BuildError(RuntimeError):
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def git_root(path: Path) -> Path:
|
|
22
|
+
result = subprocess.run(
|
|
23
|
+
["git", "-C", str(path), "rev-parse", "--show-toplevel"],
|
|
24
|
+
capture_output=True,
|
|
25
|
+
text=True,
|
|
26
|
+
)
|
|
27
|
+
if result.returncode != 0:
|
|
28
|
+
raise BuildError(f"{path} is not in a Git repository; ScienceLogo includes require one")
|
|
29
|
+
return Path(result.stdout.strip())
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def build(entry: Path, out: Path, config_path: Path | None = None) -> Path:
|
|
33
|
+
"""Build `out/site`, with the booklet inside it. Return the site folder.
|
|
34
|
+
|
|
35
|
+
If the workflow is invalid, nothing is written and BuildError carries the
|
|
36
|
+
reader's message.
|
|
37
|
+
"""
|
|
38
|
+
entry = entry.resolve()
|
|
39
|
+
if not entry.is_file():
|
|
40
|
+
raise BuildError(f"{entry} does not exist")
|
|
41
|
+
root = git_root(entry.parent)
|
|
42
|
+
if config_path is None and (root / config.CONFIG_NAME).is_file():
|
|
43
|
+
config_path = root / config.CONFIG_NAME
|
|
44
|
+
settings, warnings = config.load(config_path)
|
|
45
|
+
for w in warnings:
|
|
46
|
+
print(f"warning: {w}", file=sys.stderr)
|
|
47
|
+
|
|
48
|
+
racket = bootstrap.racket_bin(settings["versions"]) / "racket"
|
|
49
|
+
package = files("sciencelogo_documenter")
|
|
50
|
+
with as_file(package) as package_dir, tempfile.TemporaryDirectory() as tmp:
|
|
51
|
+
package_dir = Path(package_dir)
|
|
52
|
+
tmp_path = Path(tmp)
|
|
53
|
+
site = tmp_path / "site"
|
|
54
|
+
work = tmp_path / "work"
|
|
55
|
+
work.mkdir()
|
|
56
|
+
|
|
57
|
+
# Files named in the settings are copied next to the outputs.
|
|
58
|
+
faces = []
|
|
59
|
+
for i, face in enumerate(settings["fonts"]["faces"]):
|
|
60
|
+
name = f"{i}-{Path(face['file']).name}"
|
|
61
|
+
faces.append({**face, "url": f"fonts/custom/{name}", "name": name})
|
|
62
|
+
settings["fonts"]["faces"] = faces
|
|
63
|
+
if settings["booklet"].get("logo"):
|
|
64
|
+
logo = Path(settings["booklet"]["logo"])
|
|
65
|
+
shutil.copyfile(logo, work / f"logo{logo.suffix}")
|
|
66
|
+
settings["booklet"]["logo_file"] = f"logo{logo.suffix}"
|
|
67
|
+
settings_file = tmp_path / "settings.json"
|
|
68
|
+
settings_file.write_text(json.dumps(settings))
|
|
69
|
+
|
|
70
|
+
result = subprocess.run(
|
|
71
|
+
[str(racket), str(package_dir / "racket" / "main.rkt"), "build",
|
|
72
|
+
str(entry), str(settings_file), str(site), str(work)],
|
|
73
|
+
capture_output=True,
|
|
74
|
+
text=True,
|
|
75
|
+
)
|
|
76
|
+
if result.returncode != 0:
|
|
77
|
+
raise BuildError(result.stderr.strip() or "the build failed")
|
|
78
|
+
if result.stderr.strip():
|
|
79
|
+
print(result.stderr.strip(), file=sys.stderr)
|
|
80
|
+
|
|
81
|
+
font_dirs = [package_dir / "fonts" / "atkinson-hyperlegible-next",
|
|
82
|
+
package_dir / "fonts" / "atkinson-hyperlegible-mono"]
|
|
83
|
+
if faces:
|
|
84
|
+
custom = site / "fonts" / "custom"
|
|
85
|
+
custom.mkdir(parents=True, exist_ok=True)
|
|
86
|
+
for face in faces:
|
|
87
|
+
shutil.copyfile(face["file"], custom / face["name"])
|
|
88
|
+
font_dirs.insert(0, custom)
|
|
89
|
+
compile_booklet(work / "booklet.typ", site / "booklet.pdf", font_dirs)
|
|
90
|
+
|
|
91
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
92
|
+
target = out / "site"
|
|
93
|
+
if target.exists():
|
|
94
|
+
shutil.rmtree(target)
|
|
95
|
+
shutil.move(str(site), str(target))
|
|
96
|
+
return target
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Command line entry point."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from collections.abc import Sequence
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from sciencelogo_documenter import __version__
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
14
|
+
parser = argparse.ArgumentParser(
|
|
15
|
+
prog="sciencelogo-documenter",
|
|
16
|
+
description="Readable websites and PDF booklets from ScienceLogo workflows.",
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
19
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
20
|
+
|
|
21
|
+
build = commands.add_parser("build", help="build the website and the booklet")
|
|
22
|
+
build.add_argument("entry", type=Path, help="the workflow's entry file")
|
|
23
|
+
build.add_argument("--out", type=Path, default=Path("documentation"),
|
|
24
|
+
help="output folder (default: documentation)")
|
|
25
|
+
build.add_argument("--config", type=Path, help="settings file (default: sciencelogo-documenter.toml "
|
|
26
|
+
"at the root of the workflow repository, if present)")
|
|
27
|
+
|
|
28
|
+
publish = commands.add_parser("publish", help="publish a built website")
|
|
29
|
+
publish.add_argument("--target", required=True,
|
|
30
|
+
choices=["pages-branch", "github-pages", "gitlab-pages", "dir"])
|
|
31
|
+
publish.add_argument("--site", type=Path, default=Path("documentation/site"),
|
|
32
|
+
help="the built website (default: documentation/site)")
|
|
33
|
+
publish.add_argument("--branch", default="pages", help="branch for pages-branch (default: pages)")
|
|
34
|
+
publish.add_argument("--remote", default="origin", help="remote for pages-branch (default: origin)")
|
|
35
|
+
publish.add_argument("--folder", type=Path, help="destination folder for github-pages, gitlab-pages or dir")
|
|
36
|
+
|
|
37
|
+
commands.add_parser("bootstrap", help=argparse.SUPPRESS)
|
|
38
|
+
return parser
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
42
|
+
args = build_parser().parse_args(argv)
|
|
43
|
+
try:
|
|
44
|
+
if args.command == "build":
|
|
45
|
+
from sciencelogo_documenter.build import build
|
|
46
|
+
|
|
47
|
+
site = build(args.entry, args.out, args.config)
|
|
48
|
+
print(f"Built {site}")
|
|
49
|
+
elif args.command == "publish":
|
|
50
|
+
from sciencelogo_documenter.publish import publish
|
|
51
|
+
|
|
52
|
+
where = publish(args.target, args.site, branch=args.branch, folder=args.folder,
|
|
53
|
+
remote=args.remote)
|
|
54
|
+
print(f"Published to {where}")
|
|
55
|
+
elif args.command == "bootstrap":
|
|
56
|
+
from sciencelogo_documenter.bootstrap import racket_bin
|
|
57
|
+
|
|
58
|
+
print(racket_bin())
|
|
59
|
+
except Exception as e: # noqa: BLE001 - every failure ends with a readable message
|
|
60
|
+
name = type(e).__name__
|
|
61
|
+
if name in ("BuildError", "PublishError", "ConfigError", "BootstrapError"):
|
|
62
|
+
print(f"error: {e}", file=sys.stderr)
|
|
63
|
+
return 1
|
|
64
|
+
raise
|
|
65
|
+
return 0
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""Settings: the standard style, overridden by an optional TOML file."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import copy
|
|
6
|
+
import tomllib
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
CONFIG_NAME = "sciencelogo-documenter.toml"
|
|
10
|
+
|
|
11
|
+
# The standard style. Colours of the categories are Okabe-Ito hues, used as
|
|
12
|
+
# markers next to a type style that carries the meaning on its own.
|
|
13
|
+
DEFAULTS: dict = {
|
|
14
|
+
"title": None,
|
|
15
|
+
"site": {"logo": None},
|
|
16
|
+
"layout": {"page_depth": 3},
|
|
17
|
+
"booklet": {"paper": "a4", "body_size": "10.5pt", "logo": None},
|
|
18
|
+
"fonts": {
|
|
19
|
+
"text": "Atkinson Hyperlegible Next",
|
|
20
|
+
"code": "Atkinson Hyperlegible Mono",
|
|
21
|
+
"faces": [],
|
|
22
|
+
},
|
|
23
|
+
"colours": {
|
|
24
|
+
"light": {
|
|
25
|
+
"background": "#ffffff",
|
|
26
|
+
"text": "#1a1a1a",
|
|
27
|
+
"muted": "#555555",
|
|
28
|
+
"link": "#1d4f91",
|
|
29
|
+
"border": "#d0d0d0",
|
|
30
|
+
"code_background": "#f4f4f4",
|
|
31
|
+
},
|
|
32
|
+
"dark": {
|
|
33
|
+
"background": "#121212",
|
|
34
|
+
"text": "#ececec",
|
|
35
|
+
"muted": "#b0b0b0",
|
|
36
|
+
"link": "#8ab4f8",
|
|
37
|
+
"border": "#3a3a3a",
|
|
38
|
+
"code_background": "#1e1e1e",
|
|
39
|
+
},
|
|
40
|
+
"categories": {
|
|
41
|
+
"light": {"stage": "#0072B2", "performer": "#E69F00", "procedure": "#009E73", "uncertainty": "#D55E00"},
|
|
42
|
+
"dark": {"stage": "#56B4E9", "performer": "#E69F00", "procedure": "#009E73", "uncertainty": "#D55E00"},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
"index": {"kinds": ["Stages", "Procedures", "Performers", "Record types", "Requirements"]},
|
|
46
|
+
"versions": {
|
|
47
|
+
"racket_url": None,
|
|
48
|
+
"racket_sha256": None,
|
|
49
|
+
"sciencelogo_url": None,
|
|
50
|
+
"sciencelogo_checksum": None,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ConfigError(ValueError):
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _merge(base: dict, override: dict, where: str, warnings: list[str]) -> dict:
|
|
60
|
+
result = copy.deepcopy(base)
|
|
61
|
+
for key, value in override.items():
|
|
62
|
+
name = f"{where}.{key}" if where else key
|
|
63
|
+
if key not in base:
|
|
64
|
+
warnings.append(f"unknown setting {name!r} is ignored")
|
|
65
|
+
continue
|
|
66
|
+
if isinstance(base[key], dict) and isinstance(value, dict):
|
|
67
|
+
result[key] = _merge(base[key], value, name, warnings)
|
|
68
|
+
else:
|
|
69
|
+
result[key] = value
|
|
70
|
+
return result
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _luminance(colour: str) -> float:
|
|
74
|
+
c = colour.lstrip("#")
|
|
75
|
+
if len(c) == 3:
|
|
76
|
+
c = "".join(ch * 2 for ch in c)
|
|
77
|
+
channels = [int(c[i:i + 2], 16) / 255 for i in (0, 2, 4)]
|
|
78
|
+
linear = [ch / 12.92 if ch <= 0.03928 else ((ch + 0.055) / 1.055) ** 2.4 for ch in channels]
|
|
79
|
+
return 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def contrast(a: str, b: str) -> float:
|
|
83
|
+
"""WCAG contrast ratio of two colours written as #rrggbb."""
|
|
84
|
+
la, lb = sorted((_luminance(a), _luminance(b)), reverse=True)
|
|
85
|
+
return (la + 0.05) / (lb + 0.05)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def contrast_warnings(settings: dict) -> list[str]:
|
|
89
|
+
warnings = []
|
|
90
|
+
for mode in ("light", "dark"):
|
|
91
|
+
palette = settings["colours"][mode]
|
|
92
|
+
for key in ("text", "muted", "link"):
|
|
93
|
+
try:
|
|
94
|
+
ratio = contrast(palette[key], palette["background"])
|
|
95
|
+
except (KeyError, ValueError):
|
|
96
|
+
warnings.append(f"colours.{mode}.{key} is not a #rrggbb colour")
|
|
97
|
+
continue
|
|
98
|
+
if ratio < 4.5:
|
|
99
|
+
warnings.append(
|
|
100
|
+
f"colours.{mode}.{key} has a contrast of {ratio:.1f}:1 with the background, below 4.5:1"
|
|
101
|
+
)
|
|
102
|
+
return warnings
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def load(path: Path | None) -> tuple[dict, list[str]]:
|
|
106
|
+
"""Return the settings and any warnings. Paths in the file are resolved
|
|
107
|
+
against the file's folder."""
|
|
108
|
+
warnings: list[str] = []
|
|
109
|
+
if path is None:
|
|
110
|
+
settings = copy.deepcopy(DEFAULTS)
|
|
111
|
+
else:
|
|
112
|
+
try:
|
|
113
|
+
with open(path, "rb") as f:
|
|
114
|
+
data = tomllib.load(f)
|
|
115
|
+
except OSError as e:
|
|
116
|
+
raise ConfigError(f"cannot read {path}: {e}") from None
|
|
117
|
+
except tomllib.TOMLDecodeError as e:
|
|
118
|
+
raise ConfigError(f"{path} is not valid TOML: {e}") from None
|
|
119
|
+
settings = _merge(DEFAULTS, data, "", warnings)
|
|
120
|
+
base = path.parent
|
|
121
|
+
for section in ("site", "booklet"):
|
|
122
|
+
logo = settings[section].get("logo")
|
|
123
|
+
if logo:
|
|
124
|
+
resolved = (base / logo).resolve()
|
|
125
|
+
if not resolved.is_file():
|
|
126
|
+
raise ConfigError(f"{section}.logo: {logo} does not exist")
|
|
127
|
+
settings[section]["logo"] = str(resolved)
|
|
128
|
+
faces = []
|
|
129
|
+
for face in settings["fonts"].get("faces") or []:
|
|
130
|
+
if not isinstance(face, dict) or "family" not in face or "file" not in face:
|
|
131
|
+
raise ConfigError("each fonts.faces entry needs a family and a file")
|
|
132
|
+
resolved = (base / face["file"]).resolve()
|
|
133
|
+
if not resolved.is_file():
|
|
134
|
+
raise ConfigError(f"fonts.faces: {face['file']} does not exist")
|
|
135
|
+
faces.append({**face, "file": str(resolved)})
|
|
136
|
+
settings["fonts"]["faces"] = faces
|
|
137
|
+
try:
|
|
138
|
+
depth = int(settings["layout"]["page_depth"])
|
|
139
|
+
except (TypeError, ValueError):
|
|
140
|
+
raise ConfigError("layout.page_depth must be a number") from None
|
|
141
|
+
settings["layout"]["page_depth"] = depth
|
|
142
|
+
warnings.extend(contrast_warnings(settings))
|
|
143
|
+
return settings, warnings
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2020-2024 The Atkinson Hyperlegible Mono Project Authors (https://github.com/googlefonts/atkinson-hyperlegible-next-mono)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
https://openfontlicense.org
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
sciencelogo_documenter/fonts/atkinson-hyperlegible-next/AtkinsonHyperlegibleNext-BoldItalic.ttf
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2020-2024 The Atkinson Hyperlegible Next Project Authors (https://github.com/googlefonts/atkinson-hyperlegible-next)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
https://openfontlicense.org
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|