diff --git a/requirements/dev-requirements.in b/requirements/dev-requirements.in index d25bd6178..aa86c12fc 100644 --- a/requirements/dev-requirements.in +++ b/requirements/dev-requirements.in @@ -7,4 +7,3 @@ pytest-env pytest-xdist pytest-timeout pyftpdlib -setuptools diff --git a/requirements/dev-requirements.txt b/requirements/dev-requirements.txt index 369044e15..1833daf09 100644 --- a/requirements/dev-requirements.txt +++ b/requirements/dev-requirements.txt @@ -7,7 +7,6 @@ pytest-env==1.1.5 pytest-xdist==3.6.1 pytest-timeout==2.3.1 pyftpdlib==2.0.1 -setuptools==75.6.0 ## The following requirements were added by pip freeze: astroid==3.3.7 dill==0.3.9 diff --git a/tests/conftest.py b/tests/conftest.py index 79c5a489d..aa8e60838 100755 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,8 +16,8 @@ # Tristan Maat # import os +import sys -import pkg_resources import pytest from buildstream._testing import register_repo_kind, sourcetests_collection_hook @@ -29,6 +29,11 @@ from tests.testutils.repo.tar import Tar +if sys.version_info >= (3, 10): + from importlib.metadata import entry_points +else: + from importlib_metadata import entry_points + # # This file is loaded by pytest, we use it to add a custom @@ -132,7 +137,7 @@ def remote_services(request): def pytest_sessionstart(session): if session.config.getvalue("plugins"): # Enable all plugins that implement the 'buildstream.tests.source_plugins' hook - for entrypoint in pkg_resources.iter_entry_points("buildstream.tests.source_plugins"): + for entrypoint in entry_points(group="buildstream.tests.source_plugins"): module = entrypoint.load() module.register_sources() diff --git a/tests/testutils/setuptools.py b/tests/testutils/setuptools.py deleted file mode 100644 index d14c70b26..000000000 --- a/tests/testutils/setuptools.py +++ /dev/null @@ -1,55 +0,0 @@ -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import pytest -import pkg_resources - - -# A mock setuptools dist object. -class MockDist: - def __init__(self, datafiles, module_name): - self.datafiles = datafiles - self.module_name = module_name - - def get_resource_filename(self, *_args, **_kwargs): - return os.path.join(self.datafiles, self.module_name) - - -# A mock setuptools entry object. -class MockEntry: - def __init__(self, datafiles, module_name): - self.dist = MockDist(datafiles, module_name) - self.module_name = module_name - - -# Patch setuptools.get_entry_info -# -# Use result = entry_fixture(datafiles, entry_point, lookup_string) to -# patch setuptools for external plugin loading. -# -@pytest.fixture() -def entry_fixture(monkeypatch): - def patch(datafiles, entry_point, lookup_string): - dist, package = lookup_string.split(":") - - def mock_entry(pdist, pentry_point, ppackage): - assert pdist == dist - assert pentry_point == entry_point - assert ppackage == package - - return MockEntry(datafiles, package) - - monkeypatch.setattr(pkg_resources, "get_entry_info", mock_entry) - - return patch diff --git a/tests/testutils/site.py b/tests/testutils/site.py index 57857ee61..c9b96802f 100644 --- a/tests/testutils/site.py +++ b/tests/testutils/site.py @@ -20,10 +20,10 @@ # to test that BuildStream works when integrated in your system. # def pip_sample_packages(): - import pkg_resources + import importlib.metadata required = {"sample-plugins"} - installed = {pkg.key for pkg in pkg_resources.working_set} # pylint: disable=not-an-iterable + installed = {dist.name for dist in importlib.metadata.distributions()} missing = required - installed if missing: diff --git a/tox.ini b/tox.ini index 2967e9bc8..ae887a6ef 100644 --- a/tox.ini +++ b/tox.ini @@ -167,6 +167,7 @@ commands = deps = -rrequirements/requirements.txt -rrequirements/dev-requirements.txt + setuptools Cython # @@ -179,7 +180,6 @@ commands = deps = mypy==1.13.0 types-protobuf==5.28.3.20241030 - types-setuptools==75.6.0.20241126 types-ujson==5.10.0.20240515 -rrequirements/requirements.txt -rrequirements/dev-requirements.txt