From 4ef82cdba7e0666abf7bb686e3b39e0df2d01374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Fri, 26 Jul 2024 14:36:07 +0200 Subject: [PATCH 1/3] pluginoriginpip.py: Fix error type for setuptools 70 --- setup.cfg | 2 +- src/buildstream/_pluginfactory/pluginoriginpip.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7be278651..63cbbcbb4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,7 +42,7 @@ warn_no_return = True # Ignore missing stubs for third-party packages. # In future, these should be re-enabled if/when stubs for them become available. -[mypy-copyreg,grpc,pluginbase,psutil,pyroaring,ruamel,multiprocessing.forkserver] +[mypy-copyreg,grpc,pluginbase,psutil,pyroaring,ruamel,multiprocessing.forkserver,pkg_resources.extern] ignore_missing_imports=True # Ignore issues with generated files and vendored code diff --git a/src/buildstream/_pluginfactory/pluginoriginpip.py b/src/buildstream/_pluginfactory/pluginoriginpip.py index a50534f60..542776e0b 100644 --- a/src/buildstream/_pluginfactory/pluginoriginpip.py +++ b/src/buildstream/_pluginfactory/pluginoriginpip.py @@ -34,6 +34,13 @@ def get_plugin_paths(self, kind, plugin_type): import pkg_resources + try: + # For setuptools >= 70 + import packaging + except ImportError: + # For setuptools < 70 + from pkg_resources.extern import packaging + # Sources and elements are looked up in separate # entrypoint groups from the same package. # @@ -66,7 +73,7 @@ def get_plugin_paths(self, kind, plugin_type): # For setuptools < 49.0.0 pkg_resources.RequirementParseError, # For setuptools >= 49.0.0 - pkg_resources.extern.packaging.requirements.InvalidRequirement, + packaging.requirements.InvalidRequirement, ) as e: raise PluginError( "{}: Malformed package-name '{}' encountered: {}".format( From 8df8873e8a02d199c1e7c2f829c45681ce3b324f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Fri, 26 Jul 2024 14:55:01 +0200 Subject: [PATCH 2/3] _testing/runcli.py: Use `_yaml.roundtrip_dump()` to work with new ruamel `yaml.safe_dump()` has been removed. --- src/buildstream/_testing/runcli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/buildstream/_testing/runcli.py b/src/buildstream/_testing/runcli.py index 2443e9093..d91e40034 100644 --- a/src/buildstream/_testing/runcli.py +++ b/src/buildstream/_testing/runcli.py @@ -549,7 +549,7 @@ def run_project_config(self, *, project_config=None, **kwargs): temp_project = os.path.join(scratchdir, "project.conf") with open(temp_project, "w", encoding="utf-8") as f: - yaml.safe_dump(project_config, f) + _yaml.roundtrip_dump(project_config, f) project_config = _yaml.load(temp_project, shortname="project.conf") From 52b7212ac28c03cfcb352163ecf8834284ce5fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Fri, 26 Jul 2024 13:24:50 +0200 Subject: [PATCH 3/3] pytest: Set `testpaths` to fix test collection pytest 8 had breaking changes in test collection, which prevented the main test suite from being picked up in combination with our `sourcetests_collection_hook`. --- setup.cfg | 1 + src/buildstream/_testing/__init__.py | 19 +++---------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/setup.cfg b/setup.cfg index 63cbbcbb4..469e2b257 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,6 +22,7 @@ parentdir_prefix = BuildStream- [tool:pytest] addopts = --verbose --basetemp ./tmp --durations=20 --timeout=1800 +testpaths = tests norecursedirs = src tests/integration/project tests/plugins/loading tests/plugins/sample-plugins integration-cache tmp __pycache__ .eggs python_files = tests/*/*.py env = diff --git a/src/buildstream/_testing/__init__.py b/src/buildstream/_testing/__init__.py index a7520c819..7fa3643a2 100644 --- a/src/buildstream/_testing/__init__.py +++ b/src/buildstream/_testing/__init__.py @@ -100,23 +100,10 @@ def sourcetests_collection_hook(session): """ def should_collect_tests(config): - args = config.args - rootdir = config.rootdir - # When no args are supplied, pytest defaults the arg list to - # just include the session's root_dir. We want to collect + # When no args are supplied, pytest defaults the arg list to the + # value of the `testpaths` configuration option. We want to collect # tests as part of the default collection - if args == [str(rootdir)]: - return True - - # If specific tests are passed, don't collect - # everything. Pytest will handle this correctly without - # modification. - if len(args) > 1 or rootdir not in args: - return False - - # If in doubt, collect them, this will be an easier bug to - # spot and is less likely to result in bug not being found. - return True + return config.args_source != pytest.Config.ArgsSource.ARGS from . import _sourcetests