From 6210f94e467cde01df8d9940494212135aa0c176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 5 Feb 2020 13:10:51 +0100 Subject: [PATCH] Handle backends with colon, fallback to setuptools.build_meta:__legacy__ Falling back to setuptools.build_meta:__legacy__ is the standard behavior, not setuptools.build_meta. See PEP 517: https://www.python.org/dev/peps/pep-0517/ > If the pyproject.toml file is absent, or the build-backend key is missing, > the source tree is not using this specification, and tools should revert > to the legacy behaviour of running setup.py (either directly, or by > implicitly invoking the setuptools.build_meta:__legacy__ backend). Falling back to setuptools.build_meta had very similar results so far., but the behavior might change in the feature. While working on this, I have uncovered a problem in our code. It was not able to handle backends with ":". Looking at PEP 517 again: > build-backend is a string naming a Python object that will be used to > perform the build. This is formatted following the same module:object syntax > as a setuptools entry point. For instance, if the string is "flit.api:main", > this object would be looked up by executing the equivalent of: > > import flit.api > backend = flit.api.main > > It's also legal to leave out the :object part, e.g. > > build-backend = "flit.api" > > which acts like: > > import flit.api > backend = flit.api We now handle such cases properly. Witch the change of the default backend, we also test a backend with colon in our tests. --- pyproject-rpm-macros.spec | 6 +++++- pyproject_buildrequires.py | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index 3590d4e..6997652 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -6,7 +6,7 @@ License: MIT # Keep the version at zero and increment only release Version: 0 -Release: 11%{?dist} +Release: 12%{?dist} Source0: macros.pyproject Source1: pyproject_buildrequires.py @@ -87,6 +87,10 @@ install -m 644 pyproject_buildrequires.py %{buildroot}%{_rpmconfigdir}/redhat/ %license LICENSE %changelog +* Wed Feb 05 2020 Miro HronĨok - 0-12 +- Fallback to setuptools.build_meta:__legacy__ backend instead of setuptools.build_meta +- Properly handle backends with colon + * Thu Jan 30 2020 Fedora Release Engineering - 0-11 - Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild diff --git a/pyproject_buildrequires.py b/pyproject_buildrequires.py index fa6a8c4..aa87481 100644 --- a/pyproject_buildrequires.py +++ b/pyproject_buildrequires.py @@ -139,18 +139,29 @@ def get_backend(requirements): backend_name = buildsystem_data.get('build-backend') if not backend_name: + # https://www.python.org/dev/peps/pep-0517/: + # If the pyproject.toml file is absent, or the build-backend key is + # missing, the source tree is not using this specification, and tools + # should revert to the legacy behaviour of running setup.py + # (either directly, or by implicitly invoking the [following] backend). + backend_name = 'setuptools.build_meta:__legacy__' + requirements.add('setuptools >= 40.8', source='default build backend') requirements.add('wheel', source='default build backend') - backend_name = 'setuptools.build_meta' - requirements.check(source='build backend') backend_path = buildsystem_data.get('backend-path') if backend_path: sys.path.insert(0, backend_path) - return importlib.import_module(backend_name) + module_name, _, object_name = backend_name.partition(":") + backend_module = importlib.import_module(module_name) + + if object_name: + return getattr(backend_module, object_name) + + return backend_module def generate_build_requirements(backend, requirements):