[Python-checkins] distutils2: Branch merge

tarek.ziade python-checkins at python.org
Sat Oct 23 22:36:31 CEST 2010


tarek.ziade pushed 2e43b0c51ce6 to distutils2:

http://hg.python.org/distutils2/rev/2e43b0c51ce6
changeset:   775:2e43b0c51ce6
parent:      774:b89616a4b0e3
parent:      772:b62d428316a8
user:        Alexis Metaireau <ametaireau at gmail.com>
date:        Sun Oct 17 23:37:47 2010 +0100
summary:     Branch merge
files:       distutils2/dist.py

diff --git a/CHANGES.txt b/CHANGES.txt
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,9 +2,14 @@
 CHANGES
 =======
 
-1.0a3 - ?
+1.0a4 - ?
 ---------
 
+- The setup runner supports more options:
+
+1.0a3 - 2010-10-08
+------------------
+
 - Provided a Tox configuration for cross-python testing [holger]
 - Fixed the installation when using easy_install and Pip by switching
   setup.py to distutils1 [holger/tarek]
diff --git a/distutils2/command/sdist.py b/distutils2/command/sdist.py
--- a/distutils2/command/sdist.py
+++ b/distutils2/command/sdist.py
@@ -1,8 +1,6 @@
 """distutils.command.sdist
 
 Implements the Distutils 'sdist' command (create a source distribution)."""
-
-
 import os
 import string
 import sys
@@ -10,6 +8,7 @@
 from warnings import warn
 from shutil import rmtree
 import re
+from StringIO import StringIO
 
 try:
     from shutil import get_archive_formats
@@ -44,8 +43,6 @@
     description = "create a source distribution (tarball, zip file, etc.)"
 
     user_options = [
-        ('template=', 't',
-         "name of manifest template file [default: MANIFEST.in]"),
         ('manifest=', 'm',
          "name of manifest file [default: MANIFEST]"),
         ('use-defaults', None,
@@ -93,9 +90,6 @@
                       'nt': 'zip' }
 
     def initialize_options(self):
-        # 'template' and 'manifest' are, respectively, the names of
-        # the manifest template and manifest file.
-        self.template = None
         self.manifest = None
 
         # 'use_defaults': if true, we will include the default file set
@@ -123,8 +117,6 @@
     def finalize_options(self):
         if self.manifest is None:
             self.manifest = "MANIFEST"
-        if self.template is None:
-            self.template = "MANIFEST.in"
 
         self.ensure_string_list('formats')
         if self.formats is None:
@@ -176,18 +168,16 @@
         reading the manifest, or just using the default file set -- it all
         depends on the user's options.
         """
-        template_exists = os.path.isfile(self.template)
+        template_exists = len(self.distribution.extra_files) > 0
         if not template_exists:
-            self.warn(("manifest template '%s' does not exist " +
-                        "(using default file list)") %
-                        self.template)
-
+            self.warn('Using default file list')
         self.filelist.findall()
 
         if self.use_defaults:
             self.add_defaults()
         if template_exists:
-            self.filelist.read_template(self.template)
+            template = '\n'.join(self.distribution.extra_files)
+            self.filelist.read_template(StringIO(template))
         if self.prune:
             self.prune_file_list()
 
diff --git a/distutils2/config.py b/distutils2/config.py
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -176,7 +176,7 @@
                 self.dist.data_files.append((key, values))
 
             # manifest template
-            # XXX see later
+            self.dist.extra_files = files.get('extra_files', [])
 
     def parse_config_files(self, filenames=None):
         if filenames is None:
diff --git a/distutils2/dist.py b/distutils2/dist.py
--- a/distutils2/dist.py
+++ b/distutils2/dist.py
@@ -202,6 +202,7 @@
         self.password = ''
         self.use_2to3 = False
         self.convert_2to3_doctests = []
+        self.extra_files = []
 
         # And now initialize bookkeeping stuff that can't be supplied by
         # the caller at all.  'command_obj' maps command names to
diff --git a/distutils2/manifest.py b/distutils2/manifest.py
--- a/distutils2/manifest.py
+++ b/distutils2/manifest.py
@@ -66,12 +66,17 @@
             if self.files[i] == self.files[i - 1]:
                 del self.files[i]
 
-    def read_template(self, path):
+    def read_template(self, path_or_file):
         """Read and parse a manifest template file.
+        'path' can be a path or a file-like object.
 
         Updates the list accordingly.
         """
-        f = open(path)
+        if isinstance(path_or_file, str):
+            f = open(path_or_file)
+        else:
+            f = path_or_file
+
         try:
             content = f.read()
             # first, let's unwrap collapsed lines
@@ -89,7 +94,7 @@
             try:
                 self._process_template_line(line)
             except DistutilsTemplateError, msg:
-                logging.warning("%s, %s" % (path, msg))
+                logging.warning("%s, %s" % (path_or_file, msg))
 
     def write(self, path):
         """Write the file list in 'self.filelist' (presumably as filled in
diff --git a/distutils2/tests/test_command_sdist.py b/distutils2/tests/test_command_sdist.py
--- a/distutils2/tests/test_command_sdist.py
+++ b/distutils2/tests/test_command_sdist.py
@@ -279,7 +279,6 @@
 
         # default options set by finalize
         self.assertEqual(cmd.manifest, 'MANIFEST')
-        self.assertEqual(cmd.template, 'MANIFEST.in')
         self.assertEqual(cmd.dist_dir, 'dist')
 
         # formats has to be a string splitable on (' ', ',') or
@@ -415,6 +414,21 @@
 
         self.assertEqual(manifest, ['README.manual'])
 
+    def test_template(self):
+        dist, cmd = self.get_cmd()
+        dist.extra_files = ['include yeah']
+        cmd.ensure_finalized()
+        self.write_file((self.tmp_dir, 'yeah'), 'xxx')
+        cmd.run()
+        f = open(cmd.manifest)
+        try:
+            content = f.read()
+        finally:
+            f.close()
+
+        self.assertIn('yeah', content)
+
+
 def test_suite():
     return unittest.makeSuite(SDistTestCase)
 
diff --git a/distutils2/tests/test_manifest.py b/distutils2/tests/test_manifest.py
--- a/distutils2/tests/test_manifest.py
+++ b/distutils2/tests/test_manifest.py
@@ -48,6 +48,17 @@
         for warn in warns:
             self.assertIn('warning: no files found matching', warn)
 
+        # manifest also accepts file-like objects
+        old_warn = logging.warning
+        logging.warning = _warn
+        try:
+            manifest.read_template(open(MANIFEST))
+        finally:
+            logging.warning = old_warn
+
+        # the manifest should have been read
+        # and 3 warnings issued (we ddidn't provided the files)
+        self.assertEqual(len(warns), 6)
 
 
 def test_suite():

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list