babel icon indicating copy to clipboard operation
babel copied to clipboard

RFE: Replace use of `pkg_resources` with `importlib.metadata`

Open kloczek opened this issue 3 years ago • 6 comments

See discussions: astropy/astropy#11091 pypa/pip#7413

[tkloczko@devel-g2v SRPMS]$ rpm -ql python-babel | grep py$ | xargs grep pkg_resources
/usr/lib/python3.8/site-packages/babel/messages/checkers.py:        from pkg_resources import working_set
/usr/lib/python3.8/site-packages/babel/messages/checkers.py:        # if pkg_resources is not available or no usable egg-info was found
/usr/lib/python3.8/site-packages/babel/messages/extract.py:            from pkg_resources import working_set
/usr/lib/python3.8/site-packages/babel/messages/extract.py:            # if pkg_resources is not available or no usable egg-info was found

kloczek avatar Apr 22 '22 13:04 kloczek

In this case if babel sphinx extension is used in copy.py in some cases it casues effect described in setuptools ticket https://github.com/pypa/setuptools/issues/3279

kloczek avatar Apr 22 '22 13:04 kloczek

I start to see deprecation warnings in some unit test suites:

babel/messages/checkers.py:160: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    from pkg_resources import working_set

azmeuk avatar Dec 24 '23 11:12 azmeuk

It is really bad because pybabel essentially does not work with python 3.12 with third party extractors.

[python: **.py]
[jinja2: templates/**.html]

ValueError: Unknown extraction method 'jinja2'

With python 3.11, it works ok.

j123b567 avatar Jul 02 '24 16:07 j123b567

Can this be solved on Python >= 3.12 by doing pip install setuptools?

https://docs.python.org/3/whatsnew/3.12.html

gh-95299: Do not pre-install setuptools in virtual environments created with venv. This means that distutils, setuptools, pkg_resources, and easy_install will no longer available by default; to access these run pip install setuptools in the activated virtual environment.

cclauss avatar Jul 03 '24 04:07 cclauss

@cclauss thank you. It works, so it is good workaround for now.

We are working on a patch to introduce fallback to importlib.metadata

j123b567 avatar Jul 03 '24 05:07 j123b567

I also get the error ValueError: Unknown extraction method 'jinja2'. Installing setuptools via pip install setuptools doesn't solve this problem for me. I have tried it on MacOS 15.1 with Python 3.9 and ArchLinux with Python 3.12.

Edit: I also tried to install setuptools with brew install python-setuptools (Mac) respectively sudo pacman -S python-setuptools (Linux), but that also doesn't help.

Edit 2: I have found a workaround. Instead of directly using pybabel, I now use ./venv/bin/pybabel, which is working fine. :)

jhemmje avatar Nov 08 '24 15:11 jhemmje