[Python-checkins] distutils2: making 'include' the default action

tarek.ziade python-checkins at python.org
Sat Oct 23 23:27:23 CEST 2010


tarek.ziade pushed 1f87724dd8c5 to distutils2:
http://hg.python.org/distutils2/rev/1f87724dd8c5
changeset: 780:1f87724dd8c5
tag: tip
user: Tarek Ziade <tarek at ziade.org>
date: Sat Oct 23 23:27:11 2010 +0200
summary: making 'include' the default action
files: distutils2/manifest.py, distutils2/tests/test_manifest.py
diff --git a/distutils2/manifest.py b/distutils2/manifest.py
--- a/distutils2/manifest.py
+++ b/distutils2/manifest.py
@@ -22,7 +22,7 @@
 
 # a \ followed by some spaces + EOL
 _COLLAPSE_PATTERN = re.compile('\\\w*\n', re.M)
-_COMMENTED_LINE = re.compile('#.*?(?=\n)|^\w*\n|\n(?=$)', re.M | re.S)
+_COMMENTED_LINE = re.compile('#.*?(?=\n)|\n(?=$)', re.M | re.S)
 
 class Manifest(object):
 """A list of files built by on exploring the filesystem and filtered by
@@ -81,7 +81,6 @@
 content = f.read()
 # first, let's unwrap collapsed lines
 content = _COLLAPSE_PATTERN.sub('', content)
-
 # next, let's remove commented lines and empty lines
 content = _COMMENTED_LINE.sub('', content)
 
@@ -91,6 +90,8 @@
 f.close()
 
 for line in lines:
+ if line == '':
+ continue
 try:
 self._process_template_line(line)
 except DistutilsTemplateError, msg:
@@ -156,8 +157,11 @@
 
 def _parse_template_line(self, line):
 words = line.split()
+ if len(words) == 1:
+ # no action given, let's use the default 'include'
+ words.insert(0, 'include')
+
 action = words[0]
-
 patterns = dir = dir_pattern = None
 
 if action in ('include', 'exclude',
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
@@ -2,6 +2,7 @@
 import os
 import sys
 import logging
+from StringIO import StringIO
 
 from distutils2.tests import run_unittest
 from distutils2.tests import unittest, support
@@ -17,6 +18,12 @@
 *.dat *.txt
 """
 
+_MANIFEST2 = """\
+README
+file1
+"""
+
+
 class ManifestTestCase(support.TempdirManager,
 unittest.TestCase):
 
@@ -60,6 +67,19 @@
 # and 3 warnings issued (we ddidn't provided the files)
 self.assertEqual(len(warns), 6)
 
+ def test_default_actions(self):
+ tmpdir = self.mkdtemp()
+ old_dir = os.getcwd()
+ os.chdir(tmpdir)
+ try:
+ self.write_file('README', 'xxx')
+ self.write_file('file1', 'xxx')
+ content = StringIO(_MANIFEST2)
+ manifest = Manifest()
+ manifest.read_template(content)
+ self.assertEqual(manifest.files, ['README', 'file1'])
+ finally:
+ os.chdir(old_dir)
 
 def test_suite():
 return unittest.makeSuite(ManifestTestCase)
--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /