summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2019-12-31 12:57:54 -0500
committerGitHub <noreply@github.com>2019-12-31 12:57:54 -0500
commitd971118ebff9b829db8489f229401374dc5c991a (patch)
treeec851df56fc7eaadd595266a937b05ca0d6a999d
parente6bdf25f6ab5bf4d32b0f9affa0ab98ea35f3a29 (diff)
parent2eb3ba19f3153f83eb8b2470deb8ec02d21fca52 (diff)
downloadpython-setuptools-git-d971118ebff9b829db8489f229401374dc5c991a.tar.gz
Merge pull request #1650 from pypa/feature/include-pyproject.toml
Include pyproject.toml in sdist
-rw-r--r--changelog.d/1634.breaking.rst1
-rw-r--r--setuptools/command/sdist.py8
-rw-r--r--setuptools/tests/test_build_meta.py21
-rw-r--r--setuptools/tests/test_sdist.py32
4 files changed, 62 insertions, 0 deletions
diff --git a/changelog.d/1634.breaking.rst b/changelog.d/1634.breaking.rst
new file mode 100644
index 00000000..b65e5d9f
--- /dev/null
+++ b/changelog.d/1634.breaking.rst
@@ -0,0 +1 @@
+Include ``pyproject.toml`` in source distribution by default. Projects relying on the previous behavior where ``pyproject.toml`` was excluded by default should stop relying on that behavior or add ``exclude pyproject.toml`` to their MANIFEST.in file.
diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py
index eebdfd19..a851453f 100644
--- a/setuptools/command/sdist.py
+++ b/setuptools/command/sdist.py
@@ -121,6 +121,14 @@ class sdist(sdist_add_defaults, orig.sdist):
if has_leaky_handle:
read_template = __read_template_hack
+ def _add_defaults_optional(self):
+ if six.PY2:
+ sdist_add_defaults._add_defaults_optional(self)
+ else:
+ super()._add_defaults_optional()
+ if os.path.isfile('pyproject.toml'):
+ self.filelist.append('pyproject.toml')
+
def _add_defaults_python(self):
"""getting python files"""
if self.distribution.has_pure_modules():
diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py
index e1efe561..326b4f5d 100644
--- a/setuptools/tests/test_build_meta.py
+++ b/setuptools/tests/test_build_meta.py
@@ -262,6 +262,27 @@ class TestBuildMetaBackend:
assert os.path.isfile(
os.path.join(os.path.abspath("out_sdist"), sdist_name))
+ def test_build_sdist_pyproject_toml_exists(self, tmpdir_cwd):
+ files = {
+ 'setup.py': DALS("""
+ __import__('setuptools').setup(
+ name='foo',
+ version='0.0.0',
+ py_modules=['hello']
+ )"""),
+ 'hello.py': '',
+ 'pyproject.toml': DALS("""
+ [build-system]
+ requires = ["setuptools", "wheel"]
+ build-backend = "setuptools.build_meta
+ """),
+ }
+ build_files(files)
+ build_backend = self.get_build_backend()
+ targz_path = build_backend.build_sdist("temp")
+ with tarfile.open(os.path.join("temp", targz_path)) as tar:
+ assert any('pyproject.toml' in name for name in tar.getnames())
+
def test_build_sdist_setup_py_exists(self, tmpdir_cwd):
# If build_sdist is called from a script other than setup.py,
# ensure setup.py is included
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
index d2c4e0cf..b27c4a83 100644
--- a/setuptools/tests/test_sdist.py
+++ b/setuptools/tests/test_sdist.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""sdist tests"""
+from __future__ import print_function
+
import os
import shutil
import sys
@@ -449,6 +451,36 @@ class TestSdistTest:
except UnicodeDecodeError:
filename not in cmd.filelist.files
+ def test_pyproject_toml_in_sdist(self):
+ """
+ Check if pyproject.toml is included in source distribution if present
+ """
+ open(os.path.join(self.temp_dir, 'pyproject.toml'), 'w').close()
+ dist = Distribution(SETUP_ATTRS)
+ dist.script_name = 'setup.py'
+ cmd = sdist(dist)
+ cmd.ensure_finalized()
+ with quiet():
+ cmd.run()
+ manifest = cmd.filelist.files
+ assert 'pyproject.toml' in manifest
+
+ def test_pyproject_toml_excluded(self):
+ """
+ Check that pyproject.toml can excluded even if present
+ """
+ open(os.path.join(self.temp_dir, 'pyproject.toml'), 'w').close()
+ with open('MANIFEST.in', 'w') as mts:
+ print('exclude pyproject.toml', file=mts)
+ dist = Distribution(SETUP_ATTRS)
+ dist.script_name = 'setup.py'
+ cmd = sdist(dist)
+ cmd.ensure_finalized()
+ with quiet():
+ cmd.run()
+ manifest = cmd.filelist.files
+ assert 'pyproject.toml' not in manifest
+
def test_default_revctrl():
"""