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

Copy the correct file during PEP 517's build process #6236

Merged
merged 4 commits into from
Feb 5, 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 news/6196.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure the correct wheel file is copied when building PEP 517 distribution is built.
40 changes: 25 additions & 15 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,15 +818,14 @@ def _build_one_inside_env(self, req, output_dir, python_tag=None):
builder = self._build_one_pep517
else:
builder = self._build_one_legacy
if builder(req, temp_dir.path, python_tag=python_tag):
wheel_path = builder(req, temp_dir.path, python_tag=python_tag)
if wheel_path is not None:
wheel_name = os.path.basename(wheel_path)
dest_path = os.path.join(output_dir, wheel_name)
try:
wheel_name = os.listdir(temp_dir.path)[0]
wheel_path = os.path.join(output_dir, wheel_name)
shutil.move(
os.path.join(temp_dir.path, wheel_name), wheel_path
)
shutil.move(wheel_path, dest_path)
logger.info('Stored in directory: %s', output_dir)
return wheel_path
return dest_path
except Exception:
pass
Copy link
Member

Choose a reason for hiding this comment

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

Note for future: should this be swallowing an exception without logging anything?

Copy link
Member Author

Choose a reason for hiding this comment

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

No clue. :)

# Ignore return, we can't do anything else useful.
Expand All @@ -844,29 +843,39 @@ def _base_setup_args(self, req):
] + list(self.global_options)

def _build_one_pep517(self, req, tempd, python_tag=None):
"""Build one InstallRequirement using the PEP 517 build process.

Returns path to wheel if successfully built. Otherwise, returns None.
"""
assert req.metadata_directory is not None
try:
req.spin_message = 'Building wheel for %s (PEP 517)' % (req.name,)
logger.debug('Destination directory: %s', tempd)
wheelname = req.pep517_backend.build_wheel(
wheel_name = req.pep517_backend.build_wheel(
tempd,
metadata_directory=req.metadata_directory
)
if python_tag:
# General PEP 517 backends don't necessarily support
# a "--python-tag" option, so we rename the wheel
# file directly.
newname = replace_python_tag(wheelname, python_tag)
new_name = replace_python_tag(wheel_name, python_tag)
os.rename(
os.path.join(tempd, wheelname),
os.path.join(tempd, newname)
os.path.join(tempd, wheel_name),
os.path.join(tempd, new_name)
)
return True
# Reassign to simplify the return at the end of function
wheel_name = new_name
except Exception:
logger.error('Failed building wheel for %s', req.name)
return False
return None
return os.path.join(tempd, wheel_name)

def _build_one_legacy(self, req, tempd, python_tag=None):
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
"""Build one InstallRequirement using the "legacy" build process.

Returns path to wheel if successfully built. Otherwise, returns None.
"""
base_args = self._base_setup_args(req)

spin_message = 'Building wheel for %s (setup.py)' % (req.name,)
Expand All @@ -881,11 +890,12 @@ def _build_one_legacy(self, req, tempd, python_tag=None):
try:
call_subprocess(wheel_args, cwd=req.setup_py_dir,
show_stdout=False, spinner=spinner)
return True
except Exception:
spinner.finish("error")
logger.error('Failed building wheel for %s', req.name)
return False
return None
# listdir's return value is sorted to be deterministic
return os.path.join(tempd, sorted(os.listdir(tempd))[0])

def _clean_one(self, req):
base_args = self._base_setup_args(req)
Expand Down
35 changes: 35 additions & 0 deletions tests/functional/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ def auto_with_wheel(with_wheel):
pass


def add_files_to_dist_directory(folder):
(folder / 'dist').makedirs()
(folder / 'dist' / 'a_name-0.0.1.tar.gz').write("hello")
# Not adding a wheel file since that confuses setuptools' backend.
# (folder / 'dist' / 'a_name-0.0.1-py2.py3-none-any.whl').write("hello")


def test_wheel_exit_status_code_when_no_requirements(script):
"""
Test wheel exit status code when no requirements specified
Expand Down Expand Up @@ -210,3 +217,31 @@ def test_pip_wheel_with_user_set_in_config(script, data, common_wheels):
'--no-index', '-f', common_wheels
)
assert "Successfully built withpyproject" in result.stdout, result.stdout


def test_pep517_wheels_are_not_confused_with_other_files(script, tmpdir, data):
"""Check correct wheels are copied. (#6196)
"""
pkg_to_wheel = data.src / 'withpyproject'
add_files_to_dist_directory(pkg_to_wheel)

result = script.pip('wheel', pkg_to_wheel, '-w', script.scratch_path)
assert "Installing build dependencies" in result.stdout, result.stdout

wheel_file_name = 'withpyproject-0.0.1-py%s-none-any.whl' % pyversion[0]
wheel_file_path = script.scratch / wheel_file_name
assert wheel_file_path in result.files_created, result.stdout


def test_legacy_wheels_are_not_confused_with_other_files(script, tmpdir, data):
"""Check correct wheels are copied. (#6196)
"""
pkg_to_wheel = data.src / 'simplewheel-1.0'
add_files_to_dist_directory(pkg_to_wheel)

result = script.pip('wheel', pkg_to_wheel, '-w', script.scratch_path)
assert "Installing build dependencies" not in result.stdout, result.stdout
Copy link
Member

Choose a reason for hiding this comment

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

I would assert something positive here or else make "Installing build dependencies" a variable that's used in both this test and the previous. Otherwise, if the message ever changes, the test can continue to pass but for the wrong reason.

Copy link
Member Author

@pradyunsg pradyunsg Feb 4, 2019

Choose a reason for hiding this comment

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

That's the same pattern as existing tests; we can fix this in a follow up.


wheel_file_name = 'simplewheel-1.0-py%s-none-any.whl' % pyversion[0]
wheel_file_path = script.scratch / wheel_file_name
assert wheel_file_path in result.files_created, result.stdout