Skip to content

Fix ImportError in gflanguages.udhr after the move to gfmetadata - #276

Merged
simoncozens merged 1 commit into
googlefonts:mainfrom
hosiet:pr-fix-gflanguages-udhr-import
Sep 28, 2026
Merged

simoncozens merged 1 commit into
googlefonts:mainfrom
hosiet:pr-fix-gflanguages-udhr-import

Conversation

@hosiet

@hosiet hosiet commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Since 0.7.8 (#260) the protobuf modules come from gfmetadata, and gflanguages no longer ships languages_public_pb2. Lib/gflanguages/udhr.py was not updated and still imports it from gflanguages, so the module can't be imported in 0.7.8 through 0.7.11:

$ python -c "import gflanguages.udhr"
ImportError: cannot import name 'languages_public_pb2' from 'gflanguages'

The existing tests didn't catch this because none of them import gflanguages.udhr.

This PR:

  • imports languages_public_pb2 from gfmetadata in udhr.py;
  • does the same in the five scripts under snippets/ that had the old import (add-all-scripts.py, fill_sample.py, fix-exemplars-bases.py, fix-exemplars-duplicates.py, lang_sample_text.py);
  • adds test_udhr_importable to tests/test_gflanguages_api.py.

Tested with gfmetadata 0.2.5: the new test fails without the fix and passes with it, and the full test suite passes. black --check is clean.

I ran into this while updating the Debian package of gflanguages to 0.7.11.

Since 027fa61 ("Use gfmetadata, comprehensive GH action", released in
0.7.8) the generated protobuf modules live in gfmetadata and
gflanguages no longer ships languages_public_pb2. __init__.py was
updated, but gflanguages/udhr.py still does

    from gflanguages import languages_public_pb2

so importing the module fails:

    >>> import gflanguages.udhr
    ImportError: cannot import name 'languages_public_pb2' from 'gflanguages'

Import it from gfmetadata instead, and do the same in the snippets that
carry the old import. Add a test that imports gflanguages.udhr, since
nothing in the test suite imported it before.
@simoncozens

Copy link
Copy Markdown
Contributor

Oops - thank you!

@simoncozens
simoncozens merged commit eb4c076 into googlefonts:main Sep 28, 2026
6 checks passed
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