python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.34k stars 448 forks source link

Fix for PyBabel Compatibility with Python 3.12 and Third-Party Extractors #1093

Closed podgorniy94 closed 4 months ago

podgorniy94 commented 5 months ago

PyBabel currently fails to work with Python 3.12 when using third-party extractors. Specifically, the extraction method for Jinja2 templates throws a ValueError:

[python: **.py]
[jinja2: templates/**.html]
ValueError: Unknown extraction method 'jinja2'

This issue does not occur with Python 3.11, where the same setup functions correctly.

Issue: https://github.com/python-babel/babel/issues/861

akx commented 5 months ago

I don't think all of our currently supported platforms have importlib.metadata, so this will likely fail CI, but we'll see...

j123b567 commented 5 months ago

@akx you are right, it should try pkg_resources first and if it is not there, then try importlib.metadata and if it is not there, then do the fallback to predefined list

podgorniy94 commented 4 months ago

Another fallback was needed, this time for importlib.metadata, specifically for entry_points().

Error message:
AttributeError: 'str' object has no attribute 'group'

According to the documentation:

Compatibility The "selectable" entry points were introduced in importlib_metadata 3.6 and Python 3.10. Prior to those changes, entry_points accepted no parameters and always returned a dictionary of entry points, keyed by group. With importlib_metadata 5.0 and Python 3.12, entry_points always returns an EntryPoints object. See backports.entry_points_selectable for compatibility options.

codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 69.69697% with 10 lines in your changes missing coverage. Please review.

Project coverage is 90.87%. Comparing base (e0d1018) to head (8f9e1de). Report is 17 commits behind head on master.

Files Patch % Lines
babel/messages/checkers.py 64.70% 6 Missing :warning:
babel/messages/extract.py 75.00% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1093 +/- ## ========================================== - Coverage 90.99% 90.87% -0.13% ========================================== Files 26 26 Lines 4444 4481 +37 ========================================== + Hits 4044 4072 +28 - Misses 400 409 +9 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

podgorniy94 commented 4 months ago

@akx I'm preparing fixes, as I see you are planning to finish the update. I needed to let you know that I'm working on it and plan to finish it

akx commented 4 months ago

@podgorniy94 I wasn't sure you were doing that, so please just see #1102 instead – the commit has you as a co-author :)