Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update template #11

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
SOURCES=$(shell yq e '.sources.[] | sub("^","sources/")' sources/config.yaml )
FAMILY=$(shell yq e '.familyName' sources/config.yaml )
SOURCES=$(shell python3 scripts/read-config.py --sources )
FAMILY=$(shell python3 scripts/read-config.py --family )
DRAWBOT_SCRIPTS=$(shell ls documentation/*.py)
DRAWBOT_OUTPUT=$(shell ls documentation/*.py | sed 's/\.py/.png/g')

help:
@echo "###"
@echo "# Build targets for $(FAMILY)"
@echo "###"
@echo
@echo " make build: Builds the fonts and places them in the fonts/ directory"
@echo " make test: Tests the fonts with fontbakery"
@echo " make proof: Creates HTML proof documents in the proof/ directory"
@echo " make build: Builds the fonts and places them in the fonts/ directory"
@echo " make test: Tests the fonts with fontbakery"
@echo " make proof: Creates HTML proof documents in the proof/ directory"
@echo " make images: Creates PNG specimen images in the documentation/ directory"
@echo

build: build.stamp sources/config.yaml $(SOURCES)
build: build.stamp

venv: venv/touchfile

build.stamp: venv
. venv/bin/activate; gftools builder sources/config.yaml && touch build.stamp
build.stamp: venv .init.stamp sources/config.yaml $(SOURCES)
. venv/bin/activate; rm -rf fonts/; gftools builder sources/config.yaml && touch build.stamp

.init.stamp: venv
. venv/bin/activate; python3 scripts/first-run.py

venv/touchfile: requirements.txt
test -d venv || python3 -m venv venv
. venv/bin/activate; pip install -Ur requirements.txt
touch venv/touchfile

test: venv build.stamp
. venv/bin/activate; fontbakery check-googlefonts --html fontbakery-report.html --ghmarkdown fontbakery-report.md $(shell find fonts -type f)
. venv/bin/activate; mkdir -p out/ out/fontbakery; fontbakery check-googlefonts -l WARN --full-lists --succinct --badges out/badges --html out/fontbakery/fontbakery-report.html --ghmarkdown out/fontbakery/fontbakery-report.md $(shell find fonts/ttf -type f) || echo '::warning file=sources/config.yaml,title=Fontbakery failures::The fontbakery QA check reported errors in your font. Please check the generated report.'

proof: venv build.stamp
. venv/bin/activate; gftools gen-html proof $(shell find fonts -type f) -o proof
. venv/bin/activate; mkdir -p out/ out/proof; gftools gen-html proof $(shell find fonts/ttf -type f) -o out/proof

images: venv build.stamp $(DRAWBOT_OUTPUT)
git add documentation/*.png && git commit -m "Rebuild images" documentation/*.png

%.png: %.py build.stamp
python3 $< --output $@

clean:
rm -rf venv
find -iname "*.pyc" -delete
find . -name "*.pyc" | xargs rm delete

update-project-template:
npx update-template https://github.com/googlefonts/googlefonts-project-template/

update:
pip install --upgrade $(dependency); pip freeze > requirements.txt
125 changes: 121 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,121 @@
git+git://github.com/simoncozens/glyphsLib@glyphs3
fontmake>=2.4
fontbakery>=0.7
gftools>=0.7
absl-py==1.4.0
appdirs==1.4.4
async-generator==1.10
attrs==23.1.0
axisregistry==0.4.2
babelfont==3.0.0
beautifulsoup4==4.12.2
beziers==0.5.0
blackrenderer==0.6.0
booleanOperations==0.9.0
Brotli==1.0.9
bump2version==1.0.1
bumpfontversion==0.4.1
cattrs==22.2.0
certifi==2022.12.7
cffi==1.15.1
cffsubr==0.2.9.post1
charset-normalizer==3.1.0
click==8.1.3
cmarkgfm==2022.10.27
collidoscope==0.4.1
colorlog==6.7.0
commandlines==0.4.1
compreffor==0.5.3
cryptography==40.0.2
cu2qu==1.6.7.post2
defcon==0.10.2
dehinter==4.0.0
Deprecated==1.2.13
diffenator2==0.1.1
drawbot-skia==0.5.0
exceptiongroup==1.1.1
font-v==2.1.0
fontbakery==0.8.11
fontFeatures==1.7.4
fontmake==3.5.1
fontMath==0.9.3
fonttools==4.39.3
freetype-py==2.3.0
fs==2.4.16
gflanguages==0.4.7
gftools==0.9.28
gitdb==4.0.10
GitPython==3.1.31
glyphsets==0.6.0
glyphsLib==6.2.1
glyphtools==0.8.0
h11==0.14.0
hyperglot==0.4.5
idna==3.4
Jinja2==3.1.2
lxml==4.9.2
markdown-it-py==2.2.0
MarkupSafe==2.1.2
mdurl==0.1.2
munkres==1.1.4
nanoemoji==0.15.1
ninja==1.11.1
numpy==1.24.3
openstep-plist==0.3.0.post1
opentype-sanitizer==9.0.0
opentypespec==1.9.1
orjson==3.8.11
outcome==1.2.0
packaging==23.1
picosvg==0.20.6
Pillow==9.5.0
pip-api==0.0.30
pngquant-cli==2.17.0.post5
protobuf==3.20.3
pyahocorasick==2.0.0
pybind11==2.10.4
pyclipper==1.3.0.post4
pycparser==2.21
pygit2==1.12.0
PyGithub==1.58.1
Pygments==2.15.1
PyJWT==2.6.0
PyNaCl==1.5.0
pyparsing==3.0.9
PySocks==1.7.1
python-bidi==0.4.2
python-dateutil==2.8.2
PyYAML==6.0
regex==2023.3.23
requests==2.29.0
resvg-cli==0.22.0.post3
rich==13.3.5
rstr==3.2.1
selenium==4.9.0
sh==2.0.3
six==1.16.0
skia-pathops==0.7.4
skia-python==87.5
smmap==5.0.0
sniffio==1.3.0
sortedcontainers==2.4.0
soupsieve==2.4.1
sre-yield==1.2
statmake==0.6.0
strictyaml==1.7.3
stringbrewer==0.0.1
tabulate==0.9.0
toml==0.10.2
tqdm==4.65.0
trio==0.22.0
trio-websocket==0.10.2
ttfautohint-py==0.5.1
ufo2ft==2.31.1
ufoLib2==0.14.0
ufolint==1.2.0
uharfbuzz==0.36.0
unicodedata2==15.0.0
Unidecode==1.3.6
urllib3==1.26.15
vharfbuzz==0.2.0
vttLib==0.12.0
wrapt==1.15.0
wsproto==1.2.0
youseedee==0.3.0
zopfli==0.2.2
127 changes: 127 additions & 0 deletions scripts/first-run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env python3

# This script is run the first time any action is performed after the repository
# is cloned. If you are reading this because the automatic initialization failed,
# skip down to the section headed "INITIALIZATION STEPS".

from sh import git
import datetime
import re
import sys
from urllib.parse import quote
import subprocess

BASE_OWNER = "googlefonts"
BASE_REPONAME = "googlefonts-project-template"
DUMMY_URL = "https://yourname.github.io/your-font-repository-name"


def repo_url(owner, name):
return f"https://github.com/{owner}/{name}"


def web_url(owner, name):
return f"https://{owner}.github.io/{name}"


def raw_url(owner, name):
return f"https://raw.githubusercontent.com/{owner}/{name}"


def touch():
open(".init.stamp", "w").close()


def lose(msg, e=None):
print(msg)
print("You will need to do the initialization steps manually.")
print("Read scripts/first-run.py for more instructions how to do this.")
if e:
print(
"\nHere's an additional error message which may help diagnose the problem."
)
raise e
sys.exit(1)


try:
my_repo_url = git.remote("get-url", "origin")
except Exception as e:
lose("Could not use git to find my own repository URL", e)

m = re.match(r"(?:https://github.com/|[email protected]:)(.*)/(.*)/?", str(my_repo_url))
if not m:
lose(
f"My git repository URL ({my_repo_url}) didn't look what I expected - are you hosting this on github?"
)

owner, reponame = m[1], m[2]

if owner == BASE_OWNER and reponame == BASE_REPONAME:
print("I am being run on the upstream repository (probably due to CI)")
print("All I'm going to do is create the touch file and quit.")
touch()
sys.exit()

# INITIALIZATION STEPS

# First, the README file contains URLs to pages in the `gh-pages` branch of the
# repo. When initially cloned, these URLs will point to the
# googlefonts/Unified-Font-Repository itself. But downstream users want links
# and badges about their own font, not ours! So any URLs need to be adjusted to
# refer to the end user's repository.

# We will also pin the dependencies so future builds are reproducible.

readme = open("README.md").read()

print(
"Fixing URLs:", web_url(BASE_OWNER, BASE_REPONAME), "->", web_url(owner, reponame)
)

readme = readme.replace(web_url(BASE_OWNER, BASE_REPONAME), web_url(owner, reponame))
# In the badges, the URLs to raw.githubusercontent.com are URL-encoded as they
# are passed to shields.io.
print(
"Fixing URLs:",
quote(raw_url(BASE_OWNER, BASE_REPONAME), safe=""),
"->",
quote(raw_url(owner, reponame), safe=""),
)
readme = readme.replace(
quote(raw_url(BASE_OWNER, BASE_REPONAME), safe=""),
quote(raw_url(owner, reponame), safe=""),
)

print(
"Fixing URLs:",
DUMMY_URL,
"->",
web_url(owner, reponame),
)
readme = readme.replace(
f"`{DUMMY_URL}`",
web_url(owner, reponame),
)

with open("README.md", "w") as fh:
fh.write(readme)

# Fix the OFL

ofl = open("OFL.txt").read()
ofl = ofl.replace(web_url(BASE_OWNER, BASE_REPONAME), web_url(owner, reponame))
ofl = ofl.replace("My Font", reponame.title())
ofl = ofl.replace("20**", str(datetime.date.today().year))
with open("OFL.txt", "w") as fh:
fh.write(ofl)

# Pin the dependencies
print("Pinning dependencies")
dependencies = subprocess.check_output(["pip", "freeze"])
with open("requirements.txt", "wb") as dependency_file:
dependency_file.write(dependencies)

# Finally, we add a "touch file" called ".init.stamp" to the repository which
# prevents this first-run process from being run again.
touch()
25 changes: 25 additions & 0 deletions scripts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>My Font development</title>
</head>
<body>
<h1>My Font testing pages</h1>
<ul>
<li>
<a href="fontbakery/fontbakery-report.html">FontBakery Report</a>
</li>
<li>
<a href="proof/glyphs.html">All glyphs</a>
</li>
<li>
<a href="proof/text.html">Sample text</a>
</li>
<li>
<a href="proof/waterfall.html">Waterfall test</a>
</li>
</ul>
</body>
</html>
45 changes: 45 additions & 0 deletions scripts/read-config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
# Yes, this is a Bad YAML Parser, but at this stage we are not in the
# venv and do not know what modules the user has available, so for
# maximum compatibility, we are just assuming a plain Python distribution.
import argparse
import re
import sys
import os

parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--sources',action='store_true')
group.add_argument('--family',action='store_true')
args = parser.parse_args()

with open(os.path.join("sources", "config.yaml")) as config:
data = config.read()

if args.family:
m = re.search(r"(?m)^familyName: (.*)", data)
if m:
print(m[1])
sys.exit(0)
else:
print("Could not determine family name from config file!")
sys.exit(1)

toggle = False
sources = []
for line in data.splitlines():
if re.match("^sources:", line):
toggle = True
continue
if toggle:
m = re.match(r"^\s+-\s*(.*)", line)
if m:
sources.append("sources/"+m[1])
else:
toggle = False
if sources:
print(" ".join(sources))
sys.exit(0)
else:
print("Could not determine sources from config file!")
sys.exit(1)