Existence of pyproject.toml does not imply PEP 517

As the PEP itself says, if pyproject.toml exists but doesn't have the
build-system table or the build-backend key in it, then tools should
fall back to legacy behaviour of running python setup.py.

See https://github.com/mgedmin/check-manifest/issues/110#issuecomment-571175201

See also #105.
This commit is contained in:
Marius Gedminas 2020-01-07 15:42:55 +02:00
parent a36dbda463
commit c9df78bd89
4 changed files with 68 additions and 1 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ tmp/
.coverage
build/
tags
coverage.xml

View File

@ -16,6 +16,11 @@ check:
coverage:
tox -e coverage
.PHONY: diff-cover
diff-cover: coverage
coverage xml
diff-cover coverage.xml
.PHONY: distcheck
distcheck: distcheck-self # also release.mk will add other checks

View File

@ -844,13 +844,29 @@ def extract_version_from_filename(filename):
return filename.partition('-')[2]
def should_use_pep_517():
"""Check if the project uses PEP-517 builds."""
# https://www.python.org/dev/peps/pep-0517/#build-system-table says
# "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".
if not os.path.exists('pyproject.toml'):
return False
config = toml.load("pyproject.toml")
if "build-system" not in config:
return False
if "build-backend" not in config["build-system"]:
return False
return True
def build_sdist(tempdir, python=sys.executable):
"""Build a source distribution in a temporary directory.
Should be run with the current working directory inside the Python package
you want to build.
"""
if os.path.exists('pyproject.toml'):
if should_use_pep_517():
# I could do this in-process with
# import pep517.envbuild
# pep517.envbuild.build_sdist('.', tempdir)

View File

@ -595,6 +595,51 @@ class Tests(unittest.TestCase):
"%s, line 2: continuation line immediately precedes end-of-file" % filename,
])
def test_should_use_pep517_no_pyproject_toml(self):
from check_manifest import should_use_pep_517, cd
src_dir = self.make_temp_dir()
with cd(src_dir):
self.assertFalse(should_use_pep_517())
def test_should_use_pep517_no_build_system(self):
from check_manifest import should_use_pep_517, cd
src_dir = self.make_temp_dir()
filename = os.path.join(src_dir, 'pyproject.toml')
self.create_file(filename, textwrap.dedent('''
[tool.check-manifest]
'''))
with cd(src_dir):
self.assertFalse(should_use_pep_517())
def test_should_use_pep517_no_build_backend(self):
from check_manifest import should_use_pep_517, cd
src_dir = self.make_temp_dir()
filename = os.path.join(src_dir, 'pyproject.toml')
self.create_file(filename, textwrap.dedent('''
[build-system]
requires = [
"setuptools >= 40.6.0",
"wheel",
]
'''))
with cd(src_dir):
self.assertFalse(should_use_pep_517())
def test_should_use_pep517_yes_please(self):
from check_manifest import should_use_pep_517, cd
src_dir = self.make_temp_dir()
filename = os.path.join(src_dir, 'pyproject.toml')
self.create_file(filename, textwrap.dedent('''
[build-system]
requires = [
"setuptools >= 40.6.0",
"wheel",
]
build-backend = "setuptools.build_meta"
'''))
with cd(src_dir):
self.assertTrue(should_use_pep_517())
def test_build_sdist(self):
from check_manifest import build_sdist, cd, get_one_file_in
src_dir = self.make_temp_dir()