]> granicus.if.org Git - python/commitdiff
Merged revisions 83993 via svnmerge from
authorÉric Araujo <merwok@netwok.org>
Sat, 14 Aug 2010 03:07:46 +0000 (03:07 +0000)
committerÉric Araujo <merwok@netwok.org>
Sat, 14 Aug 2010 03:07:46 +0000 (03:07 +0000)
svn+ssh://pythondev@svn.python.org/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.
........

Doc/distutils/sourcedist.rst
Lib/distutils/command/sdist.py
Lib/distutils/tests/test_sdist.py
Misc/NEWS

index 2cfdf698dd54eaebe9f9bfdb10545759109f8e5b..739964e7fb17f4d8db882dab9cd3cd12f3fbe284 100644 (file)
@@ -162,6 +162,10 @@ This mechanism can be used when the default list of files is not enough.
 Principle
 ---------
 
+.. versionadded:: 2.7
+   :file:`MANIFEST` files start with a comment indicated they are generated.
+   Files without this comment are not overwritten or removed.
+
 The manifest template has one command per line, where each command specifies a
 set of files to include or exclude from the source distribution.  For an
 example, let's look at the Distutils' own manifest template::
@@ -268,3 +272,7 @@ character, and ``[range]`` matches any of the characters in *range* (e.g.,
 character" is platform-specific: on Unix it is anything except slash; on Windows
 anything except backslash or colon.
 
+.. versionchanged:: 2.7
+    An existing generated :file:`MANIFEST` will be regenerated without
+    :command:`sdist` comparing its modification time to the one of
+    :file:`MANIFEST.in` or :file:`setup.py`.
index 087ae9dcc66eb3c494e8434f1b8aadce40c4662b..f2d2f94beb51e26b97cde66d183d65db855007c4 100644 (file)
@@ -349,8 +349,21 @@ class sdist(Command):
         by 'add_defaults()' and 'read_template()') to the manifest file
         named by 'self.manifest'.
         """
-        self.execute(file_util.write_file,
-                     (self.manifest, self.filelist.files),
+        if os.path.isfile(self.manifest):
+            fp = open(self.manifest)
+            try:
+                first_line = fp.readline()
+            finally:
+                fp.close()
+
+            if first_line != '# file GENERATED by distutils, do NOT edit\n':
+                log.info("not writing to manually maintained "
+                         "manifest file '%s'" % self.manifest)
+                return
+
+        content = self.filelist.files[:]
+        content.insert(0, '# file GENERATED by distutils, do NOT edit')
+        self.execute(file_util.write_file, (self.manifest, content),
                      "writing manifest file '%s'" % self.manifest)
 
     def read_manifest(self):
index f83b9f29b64f74f2c6cbde8247ce8c4ef748cb93..87adb458943450842e9a75f4bbb191b6b6ba8b37 100644 (file)
@@ -45,6 +45,7 @@ setup(name='fake')
 """
 
 MANIFEST = """\
+# file GENERATED by distutils, do NOT edit
 README
 inroot.txt
 setup.py
@@ -364,7 +365,7 @@ class SDistTestCase(PyPIRCCommandTestCase):
         finally:
             f.close()
 
-        self.assertEquals(len(manifest), 4)
+        self.assertEquals(len(manifest), 5)
 
         # adding a file
         self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#')
@@ -384,9 +385,40 @@ class SDistTestCase(PyPIRCCommandTestCase):
             f.close()
 
         # do we have the new file in MANIFEST ?
-        self.assertEquals(len(manifest2), 5)
+        self.assertEquals(len(manifest2), 6)
         self.assertIn('doc2.txt', manifest2[-1])
 
+    def test_manifest_marker(self):
+        # check that autogenerated MANIFESTs have a marker
+        dist, cmd = self.get_cmd()
+        cmd.ensure_finalized()
+        cmd.run()
+
+        f = open(cmd.manifest)
+        try:
+            manifest = [line.strip() for line in f.read().split('\n')
+                        if line.strip() != '']
+        finally:
+            f.close()
+
+        self.assertEqual(manifest[0],
+                         '# file GENERATED by distutils, do NOT edit')
+
+    def test_manual_manifest(self):
+        # check that a MANIFEST without a marker is left alone
+        dist, cmd = self.get_cmd()
+        cmd.ensure_finalized()
+        self.write_file((self.tmp_dir, cmd.manifest), 'README.manual')
+        cmd.run()
+
+        f = open(cmd.manifest)
+        try:
+            manifest = [line.strip() for line in f.read().split('\n')
+                        if line.strip() != '']
+        finally:
+            f.close()
+
+        self.assertEqual(manifest, ['README.manual'])
 
 def test_suite():
     return unittest.makeSuite(SDistTestCase)
index fdb61eb2e42b6c29946b395c29776fc508d1aa78..4524f8bd9e0d7d147f3bfa674fb7e97690f60a90 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #8688: MANIFEST files created by distutils now include a magic
+  comment indicating they are generated.  Manually maintained MANIFESTs
+  without this marker will not be overwritten or removed.
+
 - Issue #7467: when reading a file from a ZIP archive, its CRC is checked
   and a BadZipfile error is raised if it doesn't match (as used to be the
   case in Python 2.5 and earlier).