Description: Replace pkg_resources usage setuptools 82 dropped pkg_resources, so both setup.py and the test suite's conftest.py now fail on import. Make the setup.py import optional -- its only consumer is a workaround for setuptools older than 18.5, which cannot be the case when pkg_resources is missing -- and port conftest.py to packaging plus importlib.metadata. . Adapted from the upstream pull request, without its importlib_metadata fallback: this fork requires Python >= 3.8, where importlib.metadata is part of the standard library. Author: Dale Richards Origin: upstream, https://github.com/html5lib/html5lib-python/pull/594 Bug: https://github.com/html5lib/html5lib-python/issues/593 Bug-Debian: https://bugs.debian.org/1147391 Forwarded: https://github.com/html5lib/html5lib-python/pull/594 Last-Update: 2026-09-18 --- a/html5lib/tests/conftest.py +++ b/html5lib/tests/conftest.py @@ -1,7 +1,9 @@ import os.path import sys -import pkg_resources +from importlib import metadata +from packaging.requirements import Requirement +from packaging.markers import Marker import pytest from .tree_construction import TreeConstructionFile @@ -63,17 +65,16 @@ def pytest_configure(config): spec, marker = line.strip().split(";", 1) else: spec, marker = line.strip(), None - req = pkg_resources.Requirement.parse(spec) - if marker and not pkg_resources.evaluate_marker(marker): + req = Requirement(spec) + if marker and not Marker(marker).evaluate(): msgs.append("%s not available in this environment" % spec) else: try: - installed = pkg_resources.working_set.find(req) - except pkg_resources.VersionConflict: - msgs.append("Outdated version of %s installed, need %s" % (req.name, spec)) - else: - if not installed: - msgs.append("Need %s" % spec) + installed = metadata.version(req.name) + if not req.specifier.contains(installed, prereleases=True): + msgs.append("Outdated version of %s installed, need %s" % (req.name, spec)) + except metadata.PackageNotFoundError: + msgs.append("Need %s" % spec) # Check cElementTree import xml.etree.ElementTree as ElementTree --- a/requirements-test.txt +++ b/requirements-test.txt @@ -9,3 +9,4 @@ pytest-expect>=1.1.0,<2 six>=1.9 # required by pytest-expect mock>=3.0.5,<4 ; python_version < '3.3' setuptools; python_version >= '3.12' +packaging --- a/setup.py +++ b/setup.py @@ -5,9 +5,12 @@ import sys from os.path import join, dirname from setuptools import setup, find_packages, __version__ as setuptools_version -from pkg_resources import parse_version -import pkg_resources +try: + import pkg_resources + from pkg_resources import parse_version +except ImportError: + pkg_resources = None try: import _markerlib.markers