Skip to content

Commit

Permalink
Merge pull request #251 from plone/drop-pkg-resources-usage
Browse files Browse the repository at this point in the history
Drop pkg_resources usage
  • Loading branch information
gforcada authored Mar 5, 2025
2 parents 8fc5048 + b2b7ca9 commit aa0829c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
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

0 comments on commit aa0829c

Please sign in to comment.