Skip to content

Commit

Permalink
Merge pull request #1282 from googlefonts/tidy2
Browse files Browse the repository at this point in the history
CI for .glyphs tidyness
  • Loading branch information
rsheeter authored Feb 14, 2025
2 parents 2fe4a1c + 29c54d2 commit ba7f319
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,15 @@ jobs:

- name: build fontc for wasm32-unknown-unknown
run: cargo build -p fontc --target wasm32-unknown-unknown

# Make cursory effort to keep our testdata minimal
tidy-glyphs-files:
runs-on: ubuntu-latest
name: Check if .glyphs files have unnecessary elements

steps:
- name: Check out fontc source repository
uses: actions/checkout@v4

- name: run tidy_glyphs.py
run: python3 ./resources/scripts/tidy_glyphs.py just_check
19 changes: 15 additions & 4 deletions resources/scripts/tidy_glyphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pathlib import Path
import re
import sys


_EXEMPTIONS = {
Expand All @@ -25,7 +26,9 @@ def delete_key(plist_file: Path, plist: str, key: str) -> str:
return re.sub(f"(?sm)^{key} = .*?;\n", "", plist)


def main():
def main(argv):
exit_code = 0
just_check = any(v == "just_check" for v in argv)
testdata_dir = Path(__file__).parent.parent / "testdata"
assert testdata_dir.is_dir(), testdata_dir

Expand All @@ -37,13 +40,21 @@ def main():
assert len(plist_files) > 0

for plist_file in plist_files:
plist = plist_file.read_text()
original_plist = plist_file.read_text()
plist = original_plist

for key in _DELETE_ME:
plist = delete_key(plist_file, plist, key)

plist_file.write_text(plist)
if plist != original_plist:
if not just_check:
plist_file.write_text(plist)
else:
print(plist_file, "is not tidy")
exit_code = 1

sys.exit(exit_code)


if __name__ == "__main__":
main()
main(sys.argv)

0 comments on commit ba7f319

Please sign in to comment.