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.
This commit is contained in:
Miro Hrončok 2020-02-05 13:10:51 +01:00
parent 52b92ea408
commit 6210f94e46
2 changed files with 19 additions and 4 deletions

View File

@ -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 <mhroncok@redhat.com> - 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 <releng@fedoraproject.org> - 0-11
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

View File

@ -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):