Skip to content

Comments

Package ttx-diff as a standalone PyPI package#1717

Merged
anthrotype merged 15 commits intomainfrom
standalone-ttx-diff
Oct 24, 2025
Merged

Package ttx-diff as a standalone PyPI package#1717
anthrotype merged 15 commits intomainfrom
standalone-ttx-diff

Conversation

@anthrotype
Copy link
Member

This migrates ttx_diff.py from resources/scripts/ into a standalone Python package under ttx_diff/ that can be published to PyPI.

Making ttx-diff available as a standalone package enables easier installation for external users (pip install ttx-diff), better dependency management and reusability outside the fontc repository, e.g. to aid projects transitioning from fontmake to fontc.

The ttx_diff/src/ttx_diff/core.py module is the same old resources/scripts/ttx_diff.py (moved via git mv to preserve git history), with additional logic to be able to run from anywhere (not just fontc repo root as it was currently). It also accepts pre-compile fontc and otl-normalizer binaries via CLI flags, or falls back to searching in $PATH for globally installed binaries.

When running ttx-diff script from inside the fontc workspace, it will continue to automatically build fontc and otl-normalizer from source like it currently does, unless provided with explicit binary paths.

The ttx-diff dependencies are now stored in its pyproject.toml but the old requirements.in and requirements.txt are kept, so fontc_crater runs use pinned versions and are reproducible.

We can finally add tests to ttx-diff, no more excuses...

I added a new python.yml workflow (to mimic the existing rust.yml one) that tests ttx-diff on linux and mac (no windows 🤷 ) and on Python 3.10 (the minimum nowadays) up to 3.14 (but skipped a few in between because if it works on 3.10 and 3.14, really ought to work on 3.11...)

The version is determined dynamically from git tags formatted as ttx-diff-v* (it's a monorepo and we have other tags like fontc-v*). It works.

Moved from resources/scripts/ttx_diff.py to ttx_diff/src/ttx_diff/core.py
using 'git mv' to preserve commit history.
but keep building rust from source if within the fontc repo
- only runs when changes happen in ttx_diff/ directory
- we only test Linux and Mac for now, 3.10 (min), 3.13 and 3.14. Those in between help themselves.
…ls pinned

so we don't duplicate deps in both requirements.in and ttx_diff/pyproject.toml
};
let mut cmd = format!(
"python3 resources/scripts/ttx_diff.py '{repo_url}{sha_part}#{}'",
"python3 -m ttx_diff '{repo_url}{sha_part}#{}'",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just ttx-diff, people should install it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wanted to avoid fontc_crater falling into a trap of invoking a random ttx-diff on PATH. The previous code was calling python3 with the script path. This is the equivalent, to ensure it runs the ttx_diff installed within the same environment as python3 itself.

Comment on lines +28 to +29
cd fontc/ttx_diff
pip install -e .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: pip install -e ./fontc/ttx_diff/ saves a line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well usually one cd into a git repository they have just cloned. They may as well cd into the ttx_diff directory and do the canonical -e . for clarity's sake

@anthrotype
Copy link
Member Author

amazing.. we haven't even merged this and pygit2 already broke us 🤣
https://github.com/googlefonts/fontc/actions/runs/18788046631/job/53611237030?pr=1717

@anthrotype anthrotype added this pull request to the merge queue Oct 24, 2025
Merged via the queue into main with commit 0984263 Oct 24, 2025
17 checks passed
@anthrotype anthrotype deleted the standalone-ttx-diff branch October 24, 2025 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants