Debian Codegraph @

debian/patches/0005-Replace-pkg_resources-usage.patch

raw
1 Description: Replace pkg_resources usage
2 setuptools 82 dropped pkg_resources, so both setup.py and the test suite's
3 conftest.py now fail on import. Make the setup.py import optional -- its
4 only consumer is a workaround for setuptools older than 18.5, which cannot
5 be the case when pkg_resources is missing -- and port conftest.py to
6 packaging plus importlib.metadata.
7 .
8 Adapted from the upstream pull request, without its importlib_metadata
9 fallback: this fork requires Python >= 3.8, where importlib.metadata is part
10 of the standard library.
11 Author: Dale Richards <[email protected]>
12 Origin: upstream, https://github.com/html5lib/html5lib-python/pull/594
13 Bug: https://github.com/html5lib/html5lib-python/issues/593
14 Bug-Debian: https://bugs.debian.org/1147391
15 Forwarded: https://github.com/html5lib/html5lib-python/pull/594
16 Last-Update: 2026-09-18
17 --- a/html5lib/tests/conftest.py
18 +++ b/html5lib/tests/conftest.py
19 @@ -1,7 +1,9 @@
20 import os.path
21 import sys
22
23 -import pkg_resources
24 +from importlib import metadata
25 +from packaging.requirements import Requirement
26 +from packaging.markers import Marker
27 import pytest
28
29 from .tree_construction import TreeConstructionFile
30 @@ -63,17 +65,16 @@ def pytest_configure(config):
31 spec, marker = line.strip().split(";", 1)
32 else:
33 spec, marker = line.strip(), None
34 - req = pkg_resources.Requirement.parse(spec)
35 - if marker and not pkg_resources.evaluate_marker(marker):
36 + req = Requirement(spec)
37 + if marker and not Marker(marker).evaluate():
38 msgs.append("%s not available in this environment" % spec)
39 else:
40 try:
41 - installed = pkg_resources.working_set.find(req)
42 - except pkg_resources.VersionConflict:
43 - msgs.append("Outdated version of %s installed, need %s" % (req.name, spec))
44 - else:
45 - if not installed:
46 - msgs.append("Need %s" % spec)
47 + installed = metadata.version(req.name)
48 + if not req.specifier.contains(installed, prereleases=True):
49 + msgs.append("Outdated version of %s installed, need %s" % (req.name, spec))
50 + except metadata.PackageNotFoundError:
51 + msgs.append("Need %s" % spec)
52
53 # Check cElementTree
54 import xml.etree.ElementTree as ElementTree
55 --- a/requirements-test.txt
56 +++ b/requirements-test.txt
57 @@ -9,3 +9,4 @@ pytest-expect>=1.1.0,<2
58 six>=1.9 # required by pytest-expect
59 mock>=3.0.5,<4 ; python_version < '3.3'
60 setuptools; python_version >= '3.12'
61 +packaging
62 --- a/setup.py
63 +++ b/setup.py
64 @@ -5,9 +5,12 @@ import sys
65
66 from os.path import join, dirname
67 from setuptools import setup, find_packages, __version__ as setuptools_version
68 -from pkg_resources import parse_version
69
70 -import pkg_resources
71 +try:
72 + import pkg_resources
73 + from pkg_resources import parse_version
74 +except ImportError:
75 + pkg_resources = None
76
77 try:
78 import _markerlib.markers