Add a PEP517 interface

pep517 defines a new module method of specifying build backends.
To allow pbr to exist in this world, we should define the interface
that's needed. For this to be used, one will put:

  [build-system]
  requires = ["pbr>=5.7.0", "setuptools>=36.6.0", "wheel"]
  build-backend = "pbr.build"

Into pyproject.toml - and the pep517 interface will be used.

This doesn't really change anything else - it just makes us support this.
So by itself this commit isn't SUPER helpful. But maybe let's take baby
steps with something this prone to strife, yeah?

After this we can start teasing some things apart and doing our
own things directly.

Co-Authored-By: Clark Boylan <clark.boylan@gmail.com>
Change-Id: I293f59b5074a38c78adffe580de2f1533bb01ce7
This commit is contained in:
Monty Taylor 2021-06-24 08:24:30 -04:00 committed by Clark Boylan
parent 8c0d5c3141
commit 09ee153410
5 changed files with 140 additions and 1 deletions

View File

@ -34,6 +34,18 @@ something like this::
While one can pass any arguments supported by setuptools to ``setup()``,
any conflicting arguments supplied in ``setup.cfg`` will take precedence.
``pyproject.toml``
------------------
As an alternative to writing a ``setup.py`` you can instead setup PBR
through the PEP 517 build-system configuration in ``pyproject.toml``.
Your build-system block in ``pyproject.toml`` will need to look something
like this::
[build-system]
requires = ["pbr>=5.7.0", "setuptools>=36.6.0", "wheel"]
build-backend = "pbr.build"
.. _setup_cfg:
``setup.cfg``

61
pbr/build.py Normal file
View File

@ -0,0 +1,61 @@
# Copyright 2021 Monty Taylor
#
# 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.
"""pep-517 support
Add::
[build-system]
requires = ["pbr>=5.7.0", "setuptools>=36.6.0", "wheel"]
build-backend = "pbr.build"
to pyproject.toml to use this
"""
from setuptools import build_meta
__all__ = [
'get_requires_for_build_sdist',
'get_requires_for_build_wheel',
'prepare_metadata_for_build_wheel',
'build_wheel',
'build_sdist',
]
def get_requires_for_build_wheel(config_settings=None):
return build_meta.get_requires_for_build_wheel(config_settings)
def get_requires_for_build_sdist(config_settings=None):
return build_meta.get_requires_for_build_sdist(config_settings)
def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
return build_meta.prepare_metadata_for_build_wheel(
metadata_directory, config_settings)
def build_wheel(
wheel_directory,
config_settings=None,
metadata_directory=None,
):
return build_meta.build_wheel(
wheel_directory, config_settings, metadata_directory,
)
def build_sdist(sdist_directory, config_settings=None):
return build_meta.build_sdist(sdist_directory, config_settings)

View File

@ -172,7 +172,7 @@ class Venv(fixtures.Fixture):
"""
self._reason = reason
if modules == ():
modules = ['pip', 'wheel', PBR_ROOT]
modules = ['pip', 'wheel', 'build', PBR_ROOT]
self.modules = modules
if pip_cmd is None:
self.pip_cmd = ['-m', 'pip', '-v', 'install']
@ -922,6 +922,56 @@ class TestRequirementParsing(base.BaseTestCase):
self.assertEqual(exp_parsed, gen_parsed)
class TestPEP517Support(base.BaseTestCase):
def test_pep_517_support(self):
pkgs = {
'test_pep517':
{
'requirements.txt': textwrap.dedent("""\
sphinx
iso8601
"""),
# Override no setup.py.
'setup.py': '',
'setup.cfg': textwrap.dedent("""\
[metadata]
name = test_pep517
summary = A tiny test project
author = PBR Team
author-email = foo@example.com
home-page = https://example.com/
classifier =
Intended Audience :: Information Technology
Intended Audience :: System Administrators
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
"""),
'pyproject.toml': textwrap.dedent("""\
[build-system]
requires = ["pbr", "setuptools>=36.6.0", "wheel"]
build-backend = "pbr.build"
""")},
}
pkg_dirs = self.useFixture(CreatePackages(pkgs)).package_dirs
pkg_dir = pkg_dirs['test_pep517']
venv = self.useFixture(Venv('PEP517'))
# Test building sdists and wheels works. Note we do not use pip here
# because pip will forcefully install the latest version of PBR on
# pypi to satisfy the build-system requires. This means we can't self
# test changes using pip. Build with --no-isolation appears to avoid
# this problem.
self._run_cmd(venv.python, ('-m', 'build', '--no-isolation', '.'),
allow_fail=False, cwd=pkg_dir)
class TestRepositoryURLDependencies(base.BaseTestCase):
def setUp(self):

9
pyproject.toml.future Normal file
View File

@ -0,0 +1,9 @@
# PBR doesn't use the pyproject.toml interface internally yet as
# fixing issues in the system will be difficult if PBR itself
# depends on it. We will put this file into place at pyproject.toml
# once we are more confident it works generally.
[build-system]
requires = ["setuptools>=36.6.0", "wheel"]
build-backend = "pbr.build"
backend-path = ["."]

View File

@ -0,0 +1,7 @@
---
features:
- |
PBR now includes a PEP 517 build-backend and can be used in
pyproject.toml build-system configuration. Setuptools continues
to be the underlying mechanism with PBR acting as a driver via
PEP 517 entrypoints.