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

build_meta sdist directory delegate to --dist-dir #1481

Merged
merged 4 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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/1481.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
join the sdist ``--dist-dir`` and the ``build_meta`` sdist directory argument to point to the same (this means the build frontend no longer needs to clean manually the dist dir - to avoid multiple sdist presence, and we no longer need to handle conflicts between these two flags)
6 changes: 2 additions & 4 deletions setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,9 @@ def build_sdist(sdist_directory, config_settings=None):
config_settings = _fix_config(config_settings)
sdist_directory = os.path.abspath(sdist_directory)
sys.argv = sys.argv[:1] + ['sdist'] + \
config_settings["--global-option"]
config_settings["--global-option"] + \
["--dist-dir", sdist_directory]
_run_setup()
if sdist_directory != 'dist':
shutil.rmtree(sdist_directory)
shutil.copytree('dist', sdist_directory)

sdists = [f for f in os.listdir(sdist_directory)
if f.endswith('.tar.gz')]
Expand Down
36 changes: 35 additions & 1 deletion setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals

import os
import shutil

import pytest

Expand All @@ -9,7 +10,6 @@

__metaclass__ = type


futures = pytest.importorskip('concurrent.futures')
importlib = pytest.importorskip('importlib')

Expand All @@ -23,12 +23,14 @@ def __init__(self, cwd=None, env={}, backend_name='setuptools.build_meta'):

class BuildBackend(BuildBackendBase):
"""PEP 517 Build Backend"""

def __init__(self, *args, **kwargs):
super(BuildBackend, self).__init__(*args, **kwargs)
self.pool = futures.ProcessPoolExecutor()

def __getattr__(self, name):
"""Handles aribrary function invocations on the build backend."""

def method(*args, **kw):
root = os.path.abspath(self.cwd)
caller = BuildBackendCaller(root, self.env, self.backend_name)
Expand All @@ -51,6 +53,7 @@ def __call__(self, name, *args, **kw):
'setup.py': DALS("""
__import__('setuptools').setup(
name='foo',
version='0.0.0',
py_modules=['hello'],
setup_requires=['six'],
)
Expand All @@ -65,6 +68,7 @@ def run():
assert __name__ == '__main__'
__import__('setuptools').setup(
name='foo',
version='0.0.0',
py_modules=['hello'],
setup_requires=['six'],
)
Expand All @@ -82,6 +86,7 @@ def function():
assert variable
__import__('setuptools').setup(
name='foo',
version='0.0.0',
py_modules=['hello'],
setup_requires=['six'],
)
Expand Down Expand Up @@ -146,3 +151,32 @@ def test_prepare_metadata_for_build_wheel_with_str(build_backend):
dist_info = build_backend.prepare_metadata_for_build_wheel(dist_dir)

assert os.path.isfile(os.path.join(dist_dir, dist_info, 'METADATA'))


def test_build_sdist_explicit_dist(build_backend):
# explicitly specifying the dist folder should work
# the folder sdist_directory and the ``--dist-dir`` can be the same
dist_dir = os.path.abspath('dist')
sdist_name = build_backend.build_sdist(dist_dir)
assert os.path.isfile(os.path.join(dist_dir, sdist_name))


def test_build_sdist_version_change(build_backend):
sdist_into_directory = os.path.abspath("out_sdist")
os.makedirs(sdist_into_directory)

sdist_name = build_backend.build_sdist(sdist_into_directory)
assert os.path.isfile(os.path.join(sdist_into_directory, sdist_name))

# if the setup.py changes subsequent call of the build meta should still succeed, given the
# sdist_directory the frontend specifies is empty
with open(os.path.abspath("setup.py"), 'rt') as file_handler:
content = file_handler.read()
with open(os.path.abspath("setup.py"), 'wt') as file_handler:
file_handler.write(content.replace("version='0.0.0'", "version='0.0.1'"))

shutil.rmtree(sdist_into_directory)
os.makedirs(sdist_into_directory)

sdist_name = build_backend.build_sdist("out_sdist")
assert os.path.isfile(os.path.join(os.path.abspath("out_sdist"), sdist_name))