Skip to content

Commit fe2c9e4

Browse files
committed
Fix show_response behavior on Python 2
The `upload.show_response` feature was not added until Python 3. Rather than backport it, it is now enabled only if supported. This also adds a "smoke test" for the feature.
1 parent 727dd60 commit fe2c9e4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

setuptools/command/upload.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,11 @@ def upload_file(self, command, pyversion, filename):
172172
self.announce('Server response (%s): %s' % (status, reason),
173173
log.INFO)
174174
if self.show_response:
175-
text = self._read_pypi_response(result)
176-
msg = '\n'.join(('-' * 75, text, '-' * 75))
177-
self.announce(msg, log.INFO)
175+
text = getattr(self, '_read_pypi_response',
176+
lambda x: None)(result)
177+
if text is not None:
178+
msg = '\n'.join(('-' * 75, text, '-' * 75))
179+
self.announce(msg, log.INFO)
178180
else:
179181
msg = 'Upload failed (%s): %s' % (status, reason)
180182
self.announce(msg, log.ERROR)

setuptools/tests/test_upload.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,12 @@ def test_bdist_rpm_upload(self, platform, bdist, patched_upload):
223223
assert entries['comment'].startswith(u'built for')
224224
assert len(entries['comment']) > len(u'built for')
225225

226+
def test_show_response_no_error(self, patched_upload):
227+
# This test is just that show_response doesn't throw an error
228+
# It is not really important what the printed response looks like
229+
# in a deprecated command, but we don't want to introduce new
230+
# errors when importing this function from distutils
231+
232+
patched_upload.cmd.show_response = True
233+
patched_upload.cmd.ensure_finalized()
234+
patched_upload.cmd.run()

0 commit comments

Comments
 (0)