3 from typing import List, Optional
5 from pip._internal.cli.spinners import open_spinner
6 from pip._internal.utils.setuptools_build import make_setuptools_bdist_wheel_args
7 from pip._internal.utils.subprocess import call_subprocess, format_command_args
9 logger = logging.getLogger(__name__)
12 def format_command_result(
13 command_args: List[str],
16 """Format command information for logging."""
17 command_desc = format_command_args(command_args)
18 text = f"Command arguments: {command_desc}\n"
20 if not command_output:
21 text += "Command output: None"
22 elif logger.getEffectiveLevel() > logging.DEBUG:
23 text += "Command output: [use --verbose to show]"
25 if not command_output.endswith("\n"):
26 command_output += "\n"
27 text += f"Command output:\n{command_output}"
32 def get_legacy_build_wheel_path(
36 command_args: List[str],
39 """Return the path to the wheel in the temporary build directory."""
40 # Sort for determinism.
43 msg = ("Legacy build of wheel for {!r} created no files.\n").format(name)
44 msg += format_command_result(command_args, command_output)
50 "Legacy build of wheel for {!r} created more than one file.\n"
51 "Filenames (choosing first): {}\n"
53 msg += format_command_result(command_args, command_output)
56 return os.path.join(temp_dir, names[0])
59 def build_wheel_legacy(
63 global_options: List[str],
64 build_options: List[str],
67 """Build one unpacked package using the "legacy" build process.
69 Returns path to wheel if successfully built. Otherwise, returns None.
71 wheel_args = make_setuptools_bdist_wheel_args(
73 global_options=global_options,
74 build_options=build_options,
75 destination_dir=tempd,
78 spin_message = f"Building wheel for {name} (setup.py)"
79 with open_spinner(spin_message) as spinner:
80 logger.debug("Destination directory: %s", tempd)
83 output = call_subprocess(
85 command_desc="python setup.py bdist_wheel",
90 spinner.finish("error")
91 logger.error("Failed building wheel for %s", name)
94 names = os.listdir(tempd)
95 wheel_path = get_legacy_build_wheel_path(
99 command_args=wheel_args,
100 command_output=output,