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

Also open/save JSON UFOs #1017

Merged
merged 5 commits into from
Jul 28, 2023
Merged

Also open/save JSON UFOs #1017

merged 5 commits into from
Jul 28, 2023

Conversation

madig
Copy link
Collaborator

@madig madig commented Jul 20, 2023

Fixes #859

EDIT(anthrotype):

This PR adds the ability to parse and dump UFOs serialized as JSON using ufoLib2. This is experimental and unofficial (not meant to be a replacement for UFO format!) and as such subject to change. Thus we do not recommended not to rely on this for long-term storage of font source data at the moment.
You can enable this by installing fontmake with the 'json' extra, e.g. pip install fontmake[json] (or fontmake[all] which installs all the other extras including this). This will in turn install two additional ufoLib2 dependencies, i.e. cattrs and orjson. Only cattrs is strictly required for this feature to work, but orjson makes (de)serialization much faster than pure-python built-in json module (on CPython at least).

Also note, the --save-ufo-as-zip option is deprecated (though it will continue to work) and replaced by a new --ufo-structure option that defaults to "package" (.ufo), and can take two additional values "zip" (for .ufoz) and "json" for ufoLib2's json-flavored UFOs.

@madig
Copy link
Collaborator Author

madig commented Jul 20, 2023

Hm. Maybe we want a (hard|optional) dep on ufoLib2[json,msgpack]?

@anthrotype
Copy link
Member

Maybe we want a (hard|optional) dep on ufoLib2[json]?

hm maybe not for now. That will install not only cattrs but also orjson, which is a native dep.. They don't publish win32 wheels to PyPI for example, only win_amd64 (or fontmake CI windows runners currently test on win32 FWIW).
But even just installing cattrs (e.g. via ufoLib2[converters] extra) would be sufficient to enable this feature since, in absence of orjson, ufoLib2 will fall back to built-in json module.
Let's not advertise it too much maybe, and mark all this as experimental/unofficial/etc -- at least until we make a proper json schema for ufoLib2 classes, and we know what to make of this.

@anthrotype anthrotype changed the title Also open JSON UFOs Also open/save JSON UFOs Jul 27, 2023
@anthrotype
Copy link
Member

Maybe we want a (hard|optional) dep on ufoLib2[json]?

in the end, I added an optional 'json' to extras_require which fetches ufoLib2[json]

madig and others added 5 commits July 28, 2023 14:49
…option

the old --save-ufo-as-zip is deprecated (hidden) and the new --ufo-structure option will supersede it
and always sort_keys=True so output is deterministic
orjson doesn't provide win32 (32-bit) python wheels for windows, only 64-bit (win_amd64).

build from source takes total CI time to 5 min (from 2) so no good.

I tried to only install 64-bit wheels but environment markers don't let me select what I want.
@anthrotype anthrotype merged commit a4c83a0 into main Jul 28, 2023
12 checks passed
@anthrotype anthrotype deleted the also-open-json branch July 28, 2023 14:00
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.

Compile from ufoLib2 JSON dumps
2 participants