Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bcf99ac

Browse files
committed
Branch merge
2 parents 2e7ddd3 + 17b288c commit bcf99ac

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

Lib/distutils/command/sdist.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ def read_template(self):
306306

307307
try:
308308
self.filelist.process_template_line(line)
309-
except DistutilsTemplateError as msg:
309+
# the call above can raise a DistutilsTemplateError for
310+
# malformed lines, or a ValueError from the lower-level
311+
# convert_path function
312+
except (DistutilsTemplateError, ValueError) as msg:
310313
self.warn("%s, line %d: %s" % (template.filename,
311314
template.current_line,
312315
msg))

Lib/distutils/tests/test_sdist.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from distutils.errors import DistutilsOptionError
1616
from distutils.spawn import find_executable
1717
from distutils.log import WARN
18+
from distutils.filelist import FileList
1819
from distutils.archive_util import ARCHIVE_FORMATS
1920

2021
SETUP_PY = """
@@ -78,9 +79,6 @@ def get_cmd(self, metadata=None):
7879
dist.include_package_data = True
7980
cmd = sdist(dist)
8081
cmd.dist_dir = 'dist'
81-
def _warn(*args):
82-
pass
83-
cmd.warn = _warn
8482
return dist, cmd
8583

8684
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
@@ -235,7 +233,8 @@ def test_metadata_check_option(self):
235233
# with the `check` subcommand
236234
cmd.ensure_finalized()
237235
cmd.run()
238-
warnings = self.get_logs(WARN)
236+
warnings = [msg for msg in self.get_logs(WARN) if
237+
msg.startswith('warning: check:')]
239238
self.assertEqual(len(warnings), 2)
240239

241240
# trying with a complete set of metadata
@@ -244,7 +243,8 @@ def test_metadata_check_option(self):
244243
cmd.ensure_finalized()
245244
cmd.metadata_check = 0
246245
cmd.run()
247-
warnings = self.get_logs(WARN)
246+
warnings = [msg for msg in self.get_logs(WARN) if
247+
msg.startswith('warning: check:')]
248248
self.assertEqual(len(warnings), 0)
249249

250250
def test_check_metadata_deprecated(self):
@@ -266,7 +266,6 @@ def test_show_formats(self):
266266
self.assertEqual(len(output), num_formats)
267267

268268
def test_finalize_options(self):
269-
270269
dist, cmd = self.get_cmd()
271270
cmd.finalize_options()
272271

@@ -286,6 +285,32 @@ def test_finalize_options(self):
286285
cmd.formats = 'supazipa'
287286
self.assertRaises(DistutilsOptionError, cmd.finalize_options)
288287

288+
# the following tests make sure there is a nice error message instead
289+
# of a traceback when parsing an invalid manifest template
290+
291+
def _test_template(self, content):
292+
dist, cmd = self.get_cmd()
293+
os.chdir(self.tmp_dir)
294+
self.write_file('MANIFEST.in', content)
295+
cmd.ensure_finalized()
296+
cmd.filelist = FileList()
297+
cmd.read_template()
298+
warnings = self.get_logs(WARN)
299+
self.assertEqual(len(warnings), 1)
300+
301+
def test_invalid_template_unknown_command(self):
302+
self._test_template('taunt knights *')
303+
304+
def test_invalid_template_wrong_arguments(self):
305+
# this manifest command takes one argument
306+
self._test_template('prune')
307+
308+
@unittest.skipIf(os.name != 'nt', 'test relevant for Windows only')
309+
def test_invalid_template_wrong_path(self):
310+
# on Windows, trailing slashes are not allowed
311+
# this used to crash instead of raising a warning: #8286
312+
self._test_template('include examples/')
313+
289314
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
290315
def test_get_file_list(self):
291316
# make sure MANIFEST is recalculated

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ Core and Builtins
7272

7373
Library
7474
-------
75+
76+
- Issue #8286: The distutils command sdist will print a warning message instead
77+
of crashing when an invalid path is given in the manifest template.
7578

7679
- Issue #12841: tarfile unnecessarily checked the existence of numerical user
7780
and group ids on extraction. If one of them did not exist the respective id

0 commit comments

Comments
 (0)