-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
PLIP Replace pkg_resources in normal code #4126
Comments
I second and will participate. Old packages that use Sphinx to build their docs might need to implement this fix in their |
@mauritsvanrees you can add myself as seconder if you need someone :) It would be nice to have a flake8 plugin for that, so we do not get regressions. |
I support this PLIP. |
Are you planning to convert code in place or have some utils functions that wraps up the calls to importlib? For example:
This thin wrapper can help in the future? Maybe there will be other changes in the packaging world in the future. Moreover, could be this wrap work an help to the future work on the namespace problem? |
If we have multiple lines that belong together and are used often, then a wrapper function could help. But for 99% of the cases I could prefer to simply call |
I do not think one layer more is needed here. importlib in Python is stable, it in the standard library and not so part of an add-on. |
Branch: refs/heads/master Date: 2025-02-28T20:02:34+01:00 Author: Gil Forcada Codinachs (gforcada) <[email protected]> Commit: plone/plone.app.contentmenu@0a3497d fix: replace pkg_resources with importlib See plone/Products.CMFPlone#4126 Files changed: M plone/app/contentmenu/menu.py Repository: plone.app.contentmenu Branch: refs/heads/master Date: 2025-02-28T20:02:35+01:00 Author: Gil Forcada Codinachs (gforcada) <[email protected]> Commit: plone/plone.app.contentmenu@eeeec82 Add news entry Files changed: A news/4126.bugfix Repository: plone.app.contentmenu Branch: refs/heads/master Date: 2025-03-01T22:14:11+01:00 Author: Gil Forcada Codinachs (gforcada) <[email protected]> Commit: plone/plone.app.contentmenu@e563170 Merge pull request #75 from plone/4126-replace-pkg-resources Replace pkg_resources Files changed: A news/4126.bugfix M plone/app/contentmenu/menu.py
Branch: refs/heads/master Date: 2025-02-28T20:02:34+01:00 Author: Gil Forcada Codinachs (gforcada) <[email protected]> Commit: plone/plone.app.contentmenu@0a3497d fix: replace pkg_resources with importlib See plone/Products.CMFPlone#4126 Files changed: M plone/app/contentmenu/menu.py Repository: plone.app.contentmenu Branch: refs/heads/master Date: 2025-02-28T20:02:35+01:00 Author: Gil Forcada Codinachs (gforcada) <[email protected]> Commit: plone/plone.app.contentmenu@eeeec82 Add news entry Files changed: A news/4126.bugfix Repository: plone.app.contentmenu Branch: refs/heads/master Date: 2025-03-01T22:14:11+01:00 Author: Gil Forcada Codinachs (gforcada) <[email protected]> Commit: plone/plone.app.contentmenu@e563170 Merge pull request #75 from plone/4126-replace-pkg-resources Replace pkg_resources Files changed: A news/4126.bugfix M plone/app/contentmenu/menu.py
Branch: refs/heads/master Date: 2025-02-28T20:02:34+01:00 Author: Gil Forcada Codinachs (gforcada) <[email protected]> Commit: plone/plone.app.contentmenu@0a3497d fix: replace pkg_resources with importlib See plone/Products.CMFPlone#4126 Files changed: M plone/app/contentmenu/menu.py Repository: plone.app.contentmenu Branch: refs/heads/master Date: 2025-02-28T20:02:35+01:00 Author: Gil Forcada Codinachs (gforcada) <[email protected]> Commit: plone/plone.app.contentmenu@eeeec82 Add news entry Files changed: A news/4126.bugfix Repository: plone.app.contentmenu Branch: refs/heads/master Date: 2025-03-01T22:14:11+01:00 Author: Gil Forcada Codinachs (gforcada) <[email protected]> Commit: plone/plone.app.contentmenu@e563170 Merge pull request #75 from plone/4126-replace-pkg-resources Replace pkg_resources Files changed: A news/4126.bugfix M plone/app/contentmenu/menu.py
|
PLIP (Plone Improvement Proposal)
We already want to get rid of
pkg_resources
style namespaces, see issue #3928.But
pkg_resources
in its entirety is basically deprecated, so we should stop calling it in "normal" Python code as well. In fact, some code already does not work anymore, but it depends on how you have installed Plone. See several comments by me starting here in a PR on CMFPlone.Technically, this does not need to be a PLIP, and we do not need explicit improvement from any team, and this can all be done in a bugfix release of Plone. But I wanted to make it more visible and more easily findable. And this affects lots of packages.
Responsible Persons
Proposer: Maurits van Rees (@mauritsvanrees)
Seconder: Steve Piercy (@stevepiercy), Gil Forcada Codinachs (@gforcada)
Abstract
Go through all code used in Plone 6, including in Zope code. Main target is branches that are used in Plone 6.1 and 6.2. If we have time, fixing it in 6.0 would be welcome as well.
Motivation
Several uses of
pkg_resources
actually do not work anymore in Python 3.13. This was kind-of known, but I did not really notice any problems until now. But here it is.In a checkout of
buildout.coredev
6.2, start a Zope instance based on pip, so using the Makefile.Very important: use Python 3.13. For example with
export PRIMARY_PYTHON=python3.13
. Or otherwise make sure thatpython3
resolves to python3.13.Maybe first call
make install
twice, just to be sure, there is some stuff still to fix there. But technically, just onemake
command should be enough:What is happening here? With Python 3.13, in a pip-only install, and
Products.CMFPlone
in editable install, you cannot even start a Zope instance.Similarly, running tests then also fails, see my comments that I link above.
BTW, good old Buildout is running fine, wondering what the fuzz is about, though it has its own problems. ;-)
There also seems to be a problem with entry points, probably caused by the
setuptools
change, resulting in an error during install:See for example plone/buildout.coredev#990
Assumptions
We want to be able to run Plone with Python 3.13 in a pip-only environment, so without Buildout, and use editable install for some packages.
Proposal & Implementation
Go through all used packages and replace any usage of
pkg_resources
with something else. Ignore the namespaces, that is a different topic.Some links:
pkg_resources
documentation, which says at the top: "Use of pkg_resources is deprecated in favor of importlib.resources, importlib.metadata and their backports (importlib_resources, importlib_metadata). Some useful APIs are also provided by packaging (e.g. requirements and version parsing). Users should refrain from new usage of pkg_resources and should work to port to importlib-based solutions."pkg_resources
toimport lib.metadata
pkg_resources
toimportlib.resources
.Note that we don't need the back ports packages (those with underscores), but we can use the standard lib:
importlib.metadata
andimportlib.resources
.Let's gather some code samples here:
Another one:
And files as well:
Tip
Note that
importlib.resources.files
returns apathlib.Path
, but most of the times our code expects a string, that's why it is converted to it alreadyVersion parsing:
Deliverables
Grepping in 6.2 code, I see at least these:
Products.CMFCore
Drop pkg_resources usage zopefoundation/Products.CMFCore#146Products.CMFPlone
Replace pkg_resources usage #4129Products.GenericSetup
Replace pkg_resources with importlib.metadata and packaging. zopefoundation/Products.GenericSetup#136Zope
Drop pkg_resources usage zopefoundation/Zope#1253collective.monkeypatcher
Config with plone.meta and drop pkg_resources collective.monkeypatcher#15diazo
Replace pkg_resources diazo#90five.intid
Replace pkg_resources five.intid#35paste
Remove pkg_resources usage pasteorg/paste#105plone.api
Replace pkg_resources plone.api#567plone.app.caching
Replace pkg_resources plone.app.caching#147plone.app.contentmenu
Replace pkg_resources plone.app.contentmenu#75plone.app.contenttypes
Replace pkg_resources plone.app.contenttypes#719plone.app.dexterity
Replace pkg_resources plone.app.dexterity#403plone.app.layout
Drop pkg_resources usage plone.app.layout#394plone.app.multilingual
Drop pkg_resources usage plone.app.multilingual#485plone.app.relationfield
Drop pkg_resources usage plone.app.relationfield#62plone.app.robotframework
Drop pkg_resources usage plone.app.robotframework#169plone.app.theming
Drop pkg_resources usage plone.app.theming#251plone.app.upgrade
Drop pkg_resources usage plone.app.upgrade#337plone.app.users
Drop pkg_resources usage plone.app.users#137plone.autoinclude
Replace pkg_resources plone.autoinclude#31plone.distribution
Drop pkg_resources usage plone.distribution#112plone.restapi
Drop pkg_resources usage plone.restapi#1882plone.schemaeditor
Drop pkg_resources usage plone.schemaeditor#132plone.testing
Drop pkg resources usage plone.testing#106plone.volto
Drop pkg_resources usage plone.volto#188robotsuite
Drop pkg_resources usage collective/robotsuite#30zope.publisher
Drop pkg resources usage zopefoundation/zope.publisher#84zope.testrunner
Drop pkg_resources usage zopefoundation/zope.testrunner#193For the entry points problem, maybe some of it will be fixed when all of the above have been handled. But it may need some fixes in other places. Some issues/PRs:
zc.buildout
4.14.1
needs currentsetuptools
buildout/buildout#679, fixed by Fix error adding minimumzc.buildout
version as requirement. buildout/buildout#680, released inzc.buildout
4.1.1.zc.buildout
4.1.2.Risks
If we find the correct replacements, this should have no adverse effects.
Participants
The text was updated successfully, but these errors were encountered: