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

Fix error with PEP 517 builds when wheel exists (GH #1761) #1745

Merged
merged 2 commits into from
Apr 22, 2019
Merged
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/1671.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed issue with the PEP 517 backend that prevented building a wheel when the ``dist/`` directory contained existing ``.whl`` files.
23 changes: 16 additions & 7 deletions setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import setuptools
import distutils
from setuptools.py31compat import TemporaryDirectory

from pkg_resources import parse_requirements

Expand Down Expand Up @@ -182,14 +183,22 @@ def build_wheel(self, wheel_directory, config_settings=None,
metadata_directory=None):
config_settings = self._fix_config(config_settings)
wheel_directory = os.path.abspath(wheel_directory)
sys.argv = sys.argv[:1] + ['bdist_wheel'] + \
config_settings["--global-option"]
self.run_setup()
if wheel_directory != 'dist':
shutil.rmtree(wheel_directory)
shutil.copytree('dist', wheel_directory)

return _file_with_extension(wheel_directory, '.whl')
# Build the wheel in a temporary directory, then copy to the target
with TemporaryDirectory(dir=wheel_directory) as tmp_dist_dir:
sys.argv = (sys.argv[:1] +
['bdist_wheel', '--dist-dir', tmp_dist_dir] +
config_settings["--global-option"])
self.run_setup()

wheel_basename = _file_with_extension(tmp_dist_dir, '.whl')
wheel_path = os.path.join(wheel_directory, wheel_basename)
if os.path.exists(wheel_path):
# os.rename will fail overwriting on non-unix env
os.remove(wheel_path)
os.rename(os.path.join(tmp_dist_dir, wheel_basename), wheel_path)

return wheel_basename

def build_sdist(self, sdist_directory, config_settings=None):
config_settings = self._fix_config(config_settings)
Expand Down
4 changes: 2 additions & 2 deletions setuptools/py31compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class TemporaryDirectory:
errors on deletion.
"""

def __init__(self):
def __init__(self, **kwargs):
self.name = None # Handle mkdtemp raising an exception
self.name = tempfile.mkdtemp()
self.name = tempfile.mkdtemp(**kwargs)

def __enter__(self):
return self.name
Expand Down
7 changes: 6 additions & 1 deletion setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def test_build_wheel(self, build_backend):

assert os.path.isfile(os.path.join(dist_dir, wheel_name))

@pytest.mark.xfail(reason="Known error, see GH #1671")
def test_build_wheel_with_existing_wheel_file_present(self, tmpdir_cwd):
# Building a wheel should still succeed if there's already a wheel
# in the wheel directory
Expand Down Expand Up @@ -195,6 +194,12 @@ def test_build_wheel_with_existing_wheel_file_present(self, tmpdir_cwd):
assert os.path.isfile(os.path.join(dist_dir, wheel_one))
assert wheel_one != wheel_two

# and if rebuilding the same wheel?
open(os.path.join(dist_dir, wheel_two), 'w').close()
wheel_three = self.get_build_backend().build_wheel(dist_dir)
assert wheel_three == wheel_two
assert os.path.getsize(os.path.join(dist_dir, wheel_three)) > 0

def test_build_sdist(self, build_backend):
dist_dir = os.path.abspath('pip-sdist')
os.makedirs(dist_dir)
Expand Down