Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patched sdist in PEP 517 to include pyproject.toml #1949

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1632.breaking
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Include ``pyproject.toml`` in sdist built with PEP 517 build hooks.
11 changes: 8 additions & 3 deletions setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import setuptools
import distutils
from setuptools.py31compat import TemporaryDirectory
from setuptools.command.sdist import sdist

from pkg_resources import parse_requirements
from pkg_resources.py31compat import makedirs
Expand Down Expand Up @@ -209,9 +210,13 @@ def build_wheel(self, wheel_directory, config_settings=None,
wheel_directory, config_settings)

def build_sdist(self, sdist_directory, config_settings=None):
return self._build_with_temp_dir(['sdist', '--formats', 'gztar'],
'.tar.gz', sdist_directory,
config_settings)
orig, sdist.include_pyproject_toml = sdist.include_pyproject_toml, True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This monkeypatching style is not threadsafe. Overlapping calls could leave the original unset. I don't believe thread safety is needed here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love for this not to be monkey-patched, but assuming that's how it must be, this patch should be a one-line call to encapsulate the monkeypatch behavior and decouple it from the underlying call. Something like with self._enable_pyproject_toml():.

try:
return self._build_with_temp_dir(['sdist', '--formats', 'gztar'],
'.tar.gz', sdist_directory,
config_settings)
finally:
sdist.include_pyproject_toml = orig


class _BuildMetaLegacyBackend(_BuildMetaBackend):
Expand Down
4 changes: 4 additions & 0 deletions setuptools/command/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def walk_revctrl(dirname=''):
class sdist(sdist_add_defaults, orig.sdist):
"""Smart sdist that finds anything supported by revision control"""

include_pyproject_toml = False

user_options = [
('formats=', None,
"formats for source distribution (comma-separated list)"),
Expand All @@ -45,6 +47,8 @@ def run(self):
ei_cmd = self.get_finalized_command('egg_info')
self.filelist = ei_cmd.filelist
self.filelist.append(os.path.join(ei_cmd.egg_info, 'SOURCES.txt'))
if self.include_pyproject_toml:
self.filelist.append('pyproject.toml')
self.check_readme()

# Run sub commands
Expand Down
21 changes: 21 additions & 0 deletions setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,27 @@ def test_build_sdist_version_change(self, build_backend):
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
Expand Down