Skip to content

Commit

Permalink
Updated googlefonts-project-template
Browse files Browse the repository at this point in the history
  • Loading branch information
weiweihuanghuang committed Mar 4, 2024
1 parent a406c96 commit 02774a2
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 163 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ jobs:
key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-venv-
- name: Do first-run script if necessary
run: make .init.stamp
if: github.repository != 'googlefonts/googlefonts-project-template'
- uses: stefanzweifel/git-auto-commit-action@v4
name: First-run setup
if: github.repository != 'googlefonts/googlefonts-project-template'
with:
file_pattern: .init.stamp README.md requirements.txt OFL.txt
commit_message: "Personalize for this repo"
- name: gen zip file name
id: zip-name
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ proof
node_modules
package-lock.json
package.json

working/
# OS generated files #
######################
.DS_Store
Expand Down
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,35 @@ build: build.stamp

venv: venv/touchfile

build.stamp: venv .init.stamp sources/config.yaml $(SOURCES)
venv-test: venv-test/touchfile

customize: venv
. venv/bin/activate; python3 scripts/customize.py

build.stamp: venv sources/config.yaml $(SOURCES)
rm -rf fonts
(for config in sources/config*.yaml; do . venv/bin/activate; gftools builder $$config; done) && 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; 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.'
venv-test/touchfile: requirements-test.txt
test -d venv-test || python3 -m venv venv-test
. venv-test/bin/activate; pip install -Ur requirements-test.txt
touch venv-test/touchfile

test: venv-test build.stamp
. venv-test/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; mkdir -p out/ out/proof; diffenator2 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
images: venv $(DRAWBOT_OUTPUT)

%.png: %.py build.stamp
python3 $< --output $@
. venv/bin/activate; python3 $< --output $@

clean:
rm -rf venv
Expand Down
128 changes: 7 additions & 121 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,121 +1,7 @@
absl-py==1.4.0
appdirs==1.4.4
attrs==23.1.0
axisregistry==0.4.3
babelfont==3.0.1
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==23.1.2
certifi==2023.7.22
cffi==1.15.1
cffsubr==0.2.9.post1
charset-normalizer==3.2.0
click==8.1.7
cmarkgfm==2022.10.27
collidoscope==0.6.5
colorlog==6.7.0
commandlines==0.4.1
compreffor==0.5.4
cryptography==41.0.3
cu2qu==1.6.7.post2
defcon==0.10.2
dehinter==4.0.0
Deprecated==1.2.14
diffenator2==0.2.12
drawbot-skia==0.5.0
exceptiongroup==1.1.3
font-v==2.1.0
fontbakery==0.8.13
fontFeatures==1.8.0
fontmake==3.7.1
fontMath==0.9.3
fonttools==4.42.0
freetype-py==2.4.0
fs==2.4.16
gflanguages==0.5.4
gftools==0.9.33
gitdb==4.0.10
GitPython==3.1.32
glyphsets==0.6.2
glyphsLib==6.3.0
h11==0.14.0
hyperglot==0.4.5
idna==3.4
Jinja2==3.1.2
kurbopy==0.9.0
lxml==4.9.3
markdown-it-py==3.0.0
MarkupSafe==2.1.3
mdurl==0.1.2
munkres==1.1.4
nanoemoji==0.15.1
ninja==1.11.1
numpy==1.25.2
openstep-plist==0.3.0.post1
opentype-sanitizer==9.1.0
opentypespec==1.9.1
orjson==3.9.5
outcome==1.2.0
packaging==23.1
picosvg==0.22.1
Pillow==10.0.0
pip-api==0.0.30
pngquant-cli==2.17.0.post5
protobuf==3.20.3
pyahocorasick==2.0.0
pybind11==2.11.1
pyclipper==1.3.0.post4
pycparser==2.21
pygit2==1.12.2
PyGithub==1.59.1
Pygments==2.16.1
PyJWT==2.8.0
PyNaCl==1.5.0
pyparsing==3.1.1
PySocks==1.7.1
python-bidi==0.4.2
python-dateutil==2.8.2
PyYAML==6.0.1
regex==2023.8.8
requests==2.31.0
resvg-cli==0.22.0.post3
rich==13.5.2
rstr==3.2.1
selenium==4.11.2
sh==2.0.6
six==1.16.0
skia-pathops==0.8.0
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.66.1
trio==0.22.2
trio-websocket==0.10.3
ttfautohint-py==0.5.1
typing_extensions==4.7.1
ufo2ft==2.33.4
ufoLib2==0.16.0
ufolint==1.2.0
uharfbuzz==0.37.2
unicodedata2==15.0.0
Unidecode==1.3.6
urllib3==2.0.4
vharfbuzz==0.2.0
vttLib==0.12.0
wrapt==1.15.0
wsproto==1.2.0
youseedee==0.3.0
zopfli==0.2.2
fontmake>=2.4
gftools[qa]>=0.9.23
drawbot-skia>=0.4.8
sh>=1.14.2
bumpfontversion>=0.2.0
diffenator2>=0.2.5

123 changes: 123 additions & 0 deletions scripts/customize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python3

# This script is run by the user using `make customize` after the repository
# is cloned. If you are reading this because `make customize` 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
import requests

BASE_OWNER = "googlefonts"
BASE_REPONAME = "googlefonts-project-template"
DUMMY_URL = "https://yourname.github.io/your-font-repository-name"
LATEST_OFL = "https://raw.githubusercontent.com/googlefonts/googlefonts-project-template/main/OFL.txt"


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 lose(msg, e=None):
print(msg)
print("You will need to do the initialization steps manually.")
print("Read scripts/customize.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/|git@github.com:)(.*)/(.*)/?", 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; don't do that")
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()
ghpages_url = web_url(owner, reponame)
project_url = repo_url(owner, reponame)

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

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

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

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

git.add("README.md")

# Fix the OFL
year = datetime.date.today().year
title = reponame.title()
copyright = f"Copyright {year} The {title} Project Authors ({project_url})\n"
print("Fetching the latest OFL..")
ofl = requests.get(LATEST_OFL).text.splitlines()
print("Writing an OFL for you")
print(copyright)
with open("OFL.txt", "w") as fh:
fh.write(copyright)
fh.write("\n".join(ofl[1:]))

git.add("OFL.txt")

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

# Did anything change?
result = git.status("--porcelain")
if any(line.startswith("M ") for line in result.splitlines()):
git.commit("-m", "Customize repository")

print("Pushing changes to GitHub")
git.push()
else:
print("Nothing changed, no need to push")
46 changes: 23 additions & 23 deletions scripts/read-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@

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')
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()
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)
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 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)
print(" ".join(sources))
sys.exit(0)
else:
print("Could not determine sources from config file!")
sys.exit(1)
print("Could not determine sources from config file!")
sys.exit(1)
8 changes: 8 additions & 0 deletions scripts/update-custom-filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import requests

GF_Latin_All = "https://github.com/googlefonts/glyphsets/raw/main/GF_glyphsets/Latin/glyphs/CustomFilter_GF_Latin.plist"
dest = "sources/CustomFilter_GF_Latin_All.plist"

r = requests.get(GF_Latin_All)
with open(dest, "wb") as f:
f.write(r.content)

0 comments on commit 02774a2

Please sign in to comment.