File: assemble_description.py

package info (click to toggle)
python-glyphsets 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,396 kB
  • sloc: python: 973; xml: 432; sh: 11; makefile: 3
file content (76 lines) | stat: -rw-r--r-- 2,561 bytes parent folder | download
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Assemble .nam files from .nam stub files and language definitions.
"""

import sys
import os

# Insert local module path at beginning of sys.path
# so that up-to-date version of glyphsets package is used
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "Lib"))
from glyphsets import (
    defined_glyphsets,
    defined_scripts,
    glyphsets_per_script,
    description_per_glyphset,
)  # noqa: E402

if __name__ == "__main__":
    root_folder = os.path.abspath(
        os.path.join(os.path.dirname(__file__), "..", "GF_Glyphsets")
    )

    repo_root_folder = os.path.abspath(
        os.path.join(
            os.path.dirname(__file__),
            "..",
        )
    )

    md = []

    # TOC
    md.append("# Table of Contents:\n\n")

    # Get scripts
    scripts = defined_scripts()
    script_dict = {}
    max_glyphsets = 0
    md.append("| " + " | ".join(scripts) + " |")
    md.append("| " + " | ".join(["---"] * len(scripts)) + " |")
    for script in scripts:
        max_glyphsets = max(max_glyphsets, len(glyphsets_per_script(script)))
        script_dict[script] = glyphsets_per_script(script)
    for i in range(max_glyphsets):
        row = []
        for script in scripts:
            if i < len(script_dict[script]):
                glyphset_name = script_dict[script][i]
                abbr = glyphset_name.split("_")[-1]
                _new_md, warning = description_per_glyphset(glyphset_name)
                warning_md = "✅"
                if warning:
                    warning_md = "🛑"
                row.append(
                    f"[{warning_md} {abbr}](#{glyphset_name.lower().replace('_', '-')})"
                )
            else:
                row.append("")
        md.append("| " + " | ".join(row) + " |")

    md.append(
        "\n> [!NOTE]  \n> This document is a human-readable representation of the glyphset defintions defined in `.yaml` files [here](/Lib/glyphsets/definitions/) and gets updated automatically as part of the `sh build.sh` command.\n"
    )
    md.append(
        "\n> [!NOTE]  \n> The symbols ✅ and 🛑 above denote whether or not this glyphset is available as part of Fontbakery's `shape_languages` check; in other words, whether or not language codes are defined for it.\n"
    )

    md.append("\n")

    # Content
    for glyphset_name in defined_glyphsets():
        new_md, _warning = description_per_glyphset(glyphset_name)
        md.append(new_md)

    with open(os.path.join(repo_root_folder, "GLYPHSETS.md"), "w") as f:
        f.write("\n".join(md))