Marc Foley [Thu, 29 Sep 2022 08:46:26 +0000 (09:46 +0100)]
Pin protobuf to 3.19.4
Currently, we use the latest protobuf. Unfortunately there are breaking changes between v3 and v4. All our other tools such as gftools use 3.19.4 hence why I'm pinning to this version. If I install gflanguages in a repo such as gftools, I get the following traceback
```
Traceback (most recent call last):
File "/Users/marcfoley/Type/font-browser-tests-action/test.py", line 8, in <module>
from diffenator import run_proofing_tools, run_diffing_tools
File "/Users/marcfoley/Type/font-browser-tests-action/venv/lib/python3.10/site-packages/diffenator/__init__.py", line 20, in <module>
from diffenator.screenshot import screenshot_dir
File "/Users/marcfoley/Type/font-browser-tests-action/venv/lib/python3.10/site-packages/diffenator/screenshot.py", line 6, in <module>
from diffenator.utils import gen_gifs
File "/Users/marcfoley/Type/font-browser-tests-action/venv/lib/python3.10/site-packages/diffenator/utils.py", line 22, in <module>
from gflanguages import LoadLanguages
File "/Users/marcfoley/Type/font-browser-tests-action/venv/lib/python3.10/site-packages/gflanguages/__init__.py", line 28, in <module>
from gflanguages import languages_public_pb2
File "/Users/marcfoley/Type/font-browser-tests-action/venv/lib/python3.10/site-packages/gflanguages/languages_public_pb2.py", line 36, in <module>
_descriptor.FieldDescriptor(
File "/Users/marcfoley/Type/font-browser-tests-action/venv/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 560, in __new__
_message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
1. Downgrade the protobuf package to 3.20.x or lower.
2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
- Simplify API by removing the `lang_support` module. Now one does `from gflanguages import LoadLanguages` instead of `from gflanguages.lang_support import LoadLanguages` (issue #6)
- Also, all `Load_*` methods now accept base_dir as optional argument. (motivated by: https://github.com/googlefonts/gftools/pull/511#issuecomment-1059081028)
- This will be the v0.3.0 API.
- Removed SupportedLanguages method as it relies on hyperglot, which is under the GPLv3, to keep gftranslate under Apache 2.0
- The method is still available as a separate code-snippet (not part of gflanguages itself), and any program using that snippet will need to comply with the GPLv3.
- For more details, see: https://github.com/googlefonts/fontbakery/pull/3617#issuecomment-1044898812
to workaround this kind of problem when using the module
on projects that also import `fonts_public_pb2.py`:
https://github.com/protocolbuffers/protobuf/issues/3002
This python module provides an API with data about languages/regions/scripts for use in the language-support categorization of the font families in the Google Fonts collection.
You can also directly access the raw **textproto** files on the `Lib/languages/data` directory:
* [`languages`](https://github.com/felipesanches/languages/tree/main/Lib/languages/data/languages)
* [`regions`](https://github.com/felipesanches/languages/tree/main/Lib/languages/data/regions)
* [`scripts`](https://github.com/felipesanches/languages/tree/main/Lib/languages/data/scripts)
Most of the code in this project was copied from the `gftools` repository (https://github.com/googlefonts/gftools/) so that language/region/script data can be easily available to all our tools without having to also get the large dependency tree of `gftools`. The most immediate user of this module is `Font Bakery`, which needs to validate language support on font binaries being checked. (see https://github.com/googlefonts/fontbakery/issues/3605)
The second obvious user of this `languages` module will be `gftools` itself. I'll be sending a pull request soon.
Language/region/script definitions are still being gradualy updated on the `google/fonts` repo, on its **lang/** directory (https://github.com/google/fonts/tree/main/lang) and this `languages` module will try to be kept in sync.
Ideally at some point this module would become the main place to update these definitions, avoiding data duplication and guaranteeing uniformity across tools. But that will require coordination with the Google Fonts team, so I hope this module can serve, for now, as a prototype for such proposed integration.