Skip to content

Commit b6a2be0

Browse files
authored
Merge pull request #6260 from cjerdonek/issue-6259
Improve logging in the case of a failed legacy build.
2 parents f048eb7 + d3a1b85 commit b6a2be0

File tree

2 files changed

+89
-26
lines changed

2 files changed

+89
-26
lines changed

src/pip/_internal/wheel.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,31 @@ def should_use_ephemeral_cache(
779779
return True
780780

781781

782+
def format_command(
783+
command_args, # type: List[str]
784+
command_output, # type: str
785+
):
786+
# type: (...) -> str
787+
"""
788+
Format command information for logging.
789+
"""
790+
text = 'Command arguments: {}\n'.format(command_args)
791+
792+
if not command_output:
793+
text += 'Command output: None'
794+
elif logger.getEffectiveLevel() > logging.DEBUG:
795+
text += 'Command output: [use --verbose to show]'
796+
else:
797+
if not command_output.endswith('\n'):
798+
command_output += '\n'
799+
text += (
800+
'Command output:\n{}'
801+
'-----------------------------------------'
802+
).format(command_output)
803+
804+
return text
805+
806+
782807
def get_legacy_build_wheel_path(
783808
names, # type: List[str]
784809
temp_dir, # type: str
@@ -793,23 +818,19 @@ def get_legacy_build_wheel_path(
793818
# Sort for determinism.
794819
names = sorted(names)
795820
if not names:
796-
# call_subprocess() ensures that the command output ends in a newline.
797821
msg = (
798-
'Failed building wheel for {} with args: {}\n'
799-
'Command output:\n{}'
800-
'-----------------------------------------'
801-
).format(req.name, command_args, command_output)
802-
logger.error(msg)
822+
'Legacy build of wheel for {!r} created no files.\n'
823+
).format(req.name)
824+
msg += format_command(command_args, command_output)
825+
logger.warning(msg)
803826
return None
827+
804828
if len(names) > 1:
805-
# call_subprocess() ensures that the command output ends in a newline.
806829
msg = (
807-
'Found more than one file after building wheel for {} '
808-
'with args: {}\n'
809-
'Names: {}\n'
810-
'Command output:\n{}'
811-
'-----------------------------------------'
812-
).format(req.name, command_args, names, command_output)
830+
'Legacy build of wheel for {!r} created more than one file.\n'
831+
'Filenames (choosing first): {}\n'
832+
).format(req.name, names)
833+
msg += format_command(command_args, command_output)
813834
logger.warning(msg)
814835

815836
return os.path.join(temp_dir, names[0])

tests/unit/test_wheel.py

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,53 @@ def test_should_use_ephemeral_cache__issue_6197(
9999
assert ephem_cache is expected
100100

101101

102+
def test_format_command__INFO(caplog):
103+
104+
caplog.set_level(logging.INFO)
105+
actual = wheel.format_command(
106+
command_args=['arg1', 'arg2'],
107+
command_output='output line 1\noutput line 2\n',
108+
)
109+
assert actual.splitlines() == [
110+
"Command arguments: ['arg1', 'arg2']",
111+
'Command output: [use --verbose to show]',
112+
]
113+
114+
115+
@pytest.mark.parametrize('command_output', [
116+
# Test trailing newline.
117+
'output line 1\noutput line 2\n',
118+
# Test no trailing newline.
119+
'output line 1\noutput line 2',
120+
])
121+
def test_format_command__DEBUG(caplog, command_output):
122+
caplog.set_level(logging.DEBUG)
123+
actual = wheel.format_command(
124+
command_args=['arg1', 'arg2'],
125+
command_output=command_output,
126+
)
127+
assert actual.splitlines() == [
128+
"Command arguments: ['arg1', 'arg2']",
129+
'Command output:',
130+
'output line 1',
131+
'output line 2',
132+
'-----------------------------------------',
133+
]
134+
135+
136+
@pytest.mark.parametrize('log_level', ['DEBUG', 'INFO'])
137+
def test_format_command__empty_output(caplog, log_level):
138+
caplog.set_level(log_level)
139+
actual = wheel.format_command(
140+
command_args=['arg1', 'arg2'],
141+
command_output='',
142+
)
143+
assert actual.splitlines() == [
144+
"Command arguments: ['arg1', 'arg2']",
145+
'Command output: None',
146+
]
147+
148+
102149
def call_get_legacy_build_wheel_path(caplog, names):
103150
req = make_test_install_req()
104151
wheel_path = wheel.get_legacy_build_wheel_path(
@@ -122,13 +169,11 @@ def test_get_legacy_build_wheel_path__no_names(caplog):
122169
assert actual is None
123170
assert len(caplog.records) == 1
124171
record = caplog.records[0]
125-
assert record.levelname == 'ERROR'
172+
assert record.levelname == 'WARNING'
126173
assert record.message.splitlines() == [
127-
"Failed building wheel for pendulum with args: ['arg1', 'arg2']",
128-
"Command output:",
129-
"output line 1",
130-
"output line 2",
131-
"-----------------------------------------",
174+
"Legacy build of wheel for 'pendulum' created no files.",
175+
"Command arguments: ['arg1', 'arg2']",
176+
'Command output: [use --verbose to show]',
132177
]
133178

134179

@@ -142,13 +187,10 @@ def test_get_legacy_build_wheel_path__multiple_names(caplog):
142187
record = caplog.records[0]
143188
assert record.levelname == 'WARNING'
144189
assert record.message.splitlines() == [
145-
("Found more than one file after building wheel for pendulum "
146-
"with args: ['arg1', 'arg2']"),
147-
"Names: ['name1', 'name2']",
148-
"Command output:",
149-
"output line 1",
150-
"output line 2",
151-
"-----------------------------------------",
190+
"Legacy build of wheel for 'pendulum' created more than one file.",
191+
"Filenames (choosing first): ['name1', 'name2']",
192+
"Command arguments: ['arg1', 'arg2']",
193+
'Command output: [use --verbose to show]',
152194
]
153195

154196

0 commit comments

Comments
 (0)