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

Skip to content

Commit 60a95b7

Browse files
committed
Merged revisions 83993 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r83993 | eric.araujo | 2010-08-14 04:30:34 +0200 (sam., 14 août 2010) | 2 lines Use a marker in generated MANIFEST files, don't touch files without it. Fixes #8688. ........
1 parent f263c05 commit 60a95b7

4 files changed

Lines changed: 61 additions & 9 deletions

File tree

Doc/distutils/sourcedist.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ per line, regular files (or symlinks to them) only. If you do supply your own
103103
:file:`MANIFEST`, you must specify everything: the default set of files
104104
described above does not apply in this case.
105105

106+
.. versionadded:: 3.2
107+
:file:`MANIFEST` files start with a comment indicated they are generated.
108+
Files without this comment are not overwritten or removed.
109+
106110
The manifest template has one command per line, where each command specifies a
107111
set of files to include or exclude from the source distribution. For an
108112
example, again we turn to the Distutils' own manifest template::
@@ -187,10 +191,6 @@ The normal course of operations for the :command:`sdist` command is as follows:
187191
* if neither :file:`MANIFEST` nor :file:`MANIFEST.in` exist, create a manifest
188192
with just the default file set
189193

190-
* if either :file:`MANIFEST.in` or the setup script (:file:`setup.py`) are more
191-
recent than :file:`MANIFEST`, recreate :file:`MANIFEST` by reading
192-
:file:`MANIFEST.in`
193-
194194
* use the list of files now in :file:`MANIFEST` (either just generated or read
195195
in) to create the source distribution archive(s)
196196

@@ -205,4 +205,7 @@ distribution::
205205

206206
:option:`-o` is a shortcut for :option:`--manifest-only`.
207207

208-
208+
.. versionchanged:: 3.2
209+
An existing generated :file:`MANIFEST` will be regenerated without
210+
:command:`sdist` comparing its modification time to the one of
211+
:file:`MANIFEST.in` or :file:`setup.py`.

Lib/distutils/command/sdist.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,21 @@ def write_manifest(self):
335335
by 'add_defaults()' and 'read_template()') to the manifest file
336336
named by 'self.manifest'.
337337
"""
338-
self.execute(file_util.write_file,
339-
(self.manifest, self.filelist.files),
338+
if os.path.isfile(self.manifest):
339+
fp = open(self.manifest)
340+
try:
341+
first_line = fp.readline()
342+
finally:
343+
fp.close()
344+
345+
if first_line != '# file GENERATED by distutils, do NOT edit\n':
346+
log.info("not writing to manually maintained "
347+
"manifest file '%s'" % self.manifest)
348+
return
349+
350+
content = self.filelist.files[:]
351+
content.insert(0, '# file GENERATED by distutils, do NOT edit')
352+
self.execute(file_util.write_file, (self.manifest, content),
340353
"writing manifest file '%s'" % self.manifest)
341354

342355
def read_manifest(self):

Lib/distutils/tests/test_sdist.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"""
3030

3131
MANIFEST = """\
32+
# file GENERATED by distutils, do NOT edit
3233
README
3334
inroot.txt
3435
setup.py
@@ -294,7 +295,7 @@ def test_get_file_list(self):
294295
finally:
295296
f.close()
296297

297-
self.assertEquals(len(manifest), 4)
298+
self.assertEquals(len(manifest), 5)
298299

299300
# adding a file
300301
self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#')
@@ -314,9 +315,40 @@ def test_get_file_list(self):
314315
f.close()
315316

316317
# do we have the new file in MANIFEST ?
317-
self.assertEquals(len(manifest2), 5)
318+
self.assertEquals(len(manifest2), 6)
318319
self.assertIn('doc2.txt', manifest2[-1])
319320

321+
def test_manifest_marker(self):
322+
# check that autogenerated MANIFESTs have a marker
323+
dist, cmd = self.get_cmd()
324+
cmd.ensure_finalized()
325+
cmd.run()
326+
327+
f = open(cmd.manifest)
328+
try:
329+
manifest = [line.strip() for line in f.read().split('\n')
330+
if line.strip() != '']
331+
finally:
332+
f.close()
333+
334+
self.assertEqual(manifest[0],
335+
'# file GENERATED by distutils, do NOT edit')
336+
337+
def test_manual_manifest(self):
338+
# check that a MANIFEST without a marker is left alone
339+
dist, cmd = self.get_cmd()
340+
cmd.ensure_finalized()
341+
self.write_file((self.tmp_dir, cmd.manifest), 'README.manual')
342+
cmd.run()
343+
344+
f = open(cmd.manifest)
345+
try:
346+
manifest = [line.strip() for line in f.read().split('\n')
347+
if line.strip() != '']
348+
finally:
349+
f.close()
350+
351+
self.assertEqual(manifest, ['README.manual'])
320352

321353
def test_suite():
322354
return unittest.makeSuite(SDistTestCase)

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ C-API
9393
Library
9494
-------
9595

96+
- Issue #8688: MANIFEST files created by distutils now include a magic
97+
comment indicating they are generated. Manually maintained MANIFESTs
98+
without this marker will not be overwritten or removed.
99+
96100
- Issue #7467: when reading a file from a ZIP archive, its CRC is checked
97101
and a BadZipfile error is raised if it doesn't match (as used to be the
98102
case in Python 2.5 and earlier).

0 commit comments

Comments
 (0)