Skip to content
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

Drop pkg_resources usage #251

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/4126.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace `pkg_resources` with `importlib.resources` @gforcada
8 changes: 5 additions & 3 deletions src/plone/app/theming/browser/help.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from importlib import resources
from zope.publisher.browser import BrowserView

import docutils.core
import pkg_resources


class Help(BrowserView):
def __call__(self):
rstSource = pkg_resources.resource_string(
"plone.app.theming.browser", "resources/userguide.rst"
ref = resources.files("plone.app.theming").joinpath(
"browser/resources/userguide.rst"
)
rstSource = str(ref.read_bytes())

parts = docutils.core.publish_parts(source=rstSource, writer_name="html")
html = parts["body_pre_docinfo"] + parts["fragment"]
return f"""<div class="content">{html:s}</div>"""
5 changes: 3 additions & 2 deletions src/plone/app/theming/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from configparser import ConfigParser
from diazo.compiler import compile_theme
from diazo.compiler import quote_param
from importlib import resources
from io import BytesIO
from io import StringIO
from lxml import etree
Expand Down Expand Up @@ -37,7 +38,6 @@

import logging
import os
import pkg_resources


LOGGER = logging.getLogger("plone.app.theming")
Expand Down Expand Up @@ -138,7 +138,8 @@ def resolvePythonURL(url):
assert url.lower().startswith("python://")
spec = url[9:]
package, resource_name = spec.split("/", 1)
return pkg_resources.resource_filename(package, resource_name)
ref = resources.files(package) / resource_name
return str(ref)


class InternalResolver(etree.Resolver):
Expand Down