Replace pkg_resources with importlib.resources for Python 3.14 compatibility

This commit is contained in:
wave1martian
2026-03-08 20:24:24 +01:00
parent c89fc132b8
commit 17c304066a
11 changed files with 32 additions and 44 deletions
+4 -6
View File
@@ -1,7 +1,7 @@
import collections
import functools
import operator
import pkg_resources
from importlib.resources import files
import re
import urllib.parse
@@ -719,9 +719,8 @@ def commit_nav_toc(container, toc, lang=None, landmarks=None,
if previous_nav is not None:
root = previous_nav[1]
else:
with open(pkg_resources.
resource_filename('ebook_converter',
'data/new_nav.html')) as fobj:
with open(str(files('ebook_converter')
.joinpath('data/new_nav.html'))) as fobj:
root = container.parse_xhtml(fobj.read())
container.replace(tocname, root)
else:
@@ -874,8 +873,7 @@ def toc_to_html(toc, container, toc_name, title, lang=None):
E = ElementMaker(namespace=const.XHTML_NS, nsmap={None: const.XHTML_NS})
# TODO(gryf): revisit lack of css.
css_f = pkg_resources.resource_filename('ebook_converter',
'data/inline_toc_styles.css')
css_f = str(files('ebook_converter').joinpath('data/inline_toc_styles.css'))
html = E.html(E.head(E.title(title),
E.style(css_f, type='text/css')),
E.body(E.h2(title), E.ul(),