[Python-checkins] cpython: Re-apply distutils2 changes lost before the merge of packaging.

eric.araujo python-checkins at python.org
Wed Jun 1 19:47:51 CEST 2011


http://hg.python.org/cpython/rev/dece7112b286
changeset:   70584:dece7112b286
user:        Éric Araujo <merwok at netwok.org>
date:        Tue May 31 18:04:32 2011 +0200
summary:
  Re-apply distutils2 changes lost before the merge of packaging.

wrap_text was removed in favor of standard textwrap but the removal of the
function was lost in a bad merge; a change in sdist mysteriously disappeared.

files:
  Lib/packaging/command/sdist.py            |  36 +-----
  Lib/packaging/fancy_getopt.py             |  63 -----------
  Lib/packaging/tests/test_command_sdist.py |   9 +-
  3 files changed, 6 insertions(+), 102 deletions(-)


diff --git a/Lib/packaging/command/sdist.py b/Lib/packaging/command/sdist.py
--- a/Lib/packaging/command/sdist.py
+++ b/Lib/packaging/command/sdist.py
@@ -1,10 +1,9 @@
 """Create a source distribution."""
 
 import os
+import re
 import sys
-import re
 from io import StringIO
-from glob import glob
 from shutil import get_archive_formats, rmtree
 
 from packaging import logger
@@ -203,45 +202,14 @@
 
     def add_defaults(self):
         """Add all the default files to self.filelist:
-          - README or README.txt
-          - test/test*.py
           - all pure Python modules mentioned in setup script
           - all files pointed by package_data (build_py)
           - all files defined in data_files.
           - all files defined as scripts.
           - all C sources listed as part of extensions or C libraries
             in the setup script (doesn't catch C headers!)
-        Warns if (README or README.txt) or setup.py are missing; everything
-        else is optional.
+        Everything is optional.
         """
-        standards = [('README', 'README.txt')]
-        for fn in standards:
-            if isinstance(fn, tuple):
-                alts = fn
-                got_it = False
-                for fn in alts:
-                    if os.path.exists(fn):
-                        got_it = True
-                        self.filelist.append(fn)
-                        break
-
-                if not got_it:
-                    logger.warning(
-                        '%s: standard file not found: should have one of %s',
-                        self.get_command_name(), ', '.join(alts))
-            else:
-                if os.path.exists(fn):
-                    self.filelist.append(fn)
-                else:
-                    logger.warning('%s: standard file %r not found',
-                                   self.get_command_name(), fn)
-
-        optional = ['test/test*.py', 'setup.cfg']
-        for pattern in optional:
-            files = [f for f in glob(pattern) if os.path.isfile(f)]
-            if files:
-                self.filelist.extend(files)
-
         for cmd_name in get_command_names():
             try:
                 cmd_obj = self.get_finalized_command(cmd_name)
diff --git a/Lib/packaging/fancy_getopt.py b/Lib/packaging/fancy_getopt.py
--- a/Lib/packaging/fancy_getopt.py
+++ b/Lib/packaging/fancy_getopt.py
@@ -13,7 +13,6 @@
 import getopt
 import re
 import sys
-import string
 import textwrap
 
 from packaging.errors import PackagingGetoptError, PackagingArgError
@@ -378,68 +377,6 @@
     return parser.getopt(args, object)
 
 
-WS_TRANS = str.maketrans(string.whitespace, ' ' * len(string.whitespace))
-
-
-def wrap_text(text, width):
-    """Split *text* into lines of no more than *width* characters each.
-
-    *text* is a str and *width* an int.  Returns a list of str.
-    """
-
-    if text is None:
-        return []
-    if len(text) <= width:
-        return [text]
-
-    text = text.expandtabs()
-    text = text.translate(WS_TRANS)
-
-    chunks = re.split(r'( +|-+)', text)
-    chunks = [_f for _f in chunks if _f]      # ' - ' results in empty strings
-    lines = []
-
-    while chunks:
-
-        cur_line = []                   # list of chunks (to-be-joined)
-        cur_len = 0                     # length of current line
-
-        while chunks:
-            l = len(chunks[0])
-            if cur_len + l <= width:    # can squeeze (at least) this chunk in
-                cur_line.append(chunks[0])
-                del chunks[0]
-                cur_len = cur_len + l
-            else:                       # this line is full
-                # drop last chunk if all space
-                if cur_line and cur_line[-1][0] == ' ':
-                    del cur_line[-1]
-                break
-
-        if chunks:                      # any chunks left to process?
-
-            # if the current line is still empty, then we had a single
-            # chunk that's too big too fit on a line -- so we break
-            # down and break it up at the line width
-            if cur_len == 0:
-                cur_line.append(chunks[0][0:width])
-                chunks[0] = chunks[0][width:]
-
-            # all-whitespace chunks at the end of a line can be discarded
-            # (and we know from the re.split above that if a chunk has
-            # *any* whitespace, it is *all* whitespace)
-            if chunks[0][0] == ' ':
-                del chunks[0]
-
-        # and store this line in the list-of-all-lines -- as a single
-        # string, of course!
-        lines.append(''.join(cur_line))
-
-    # while chunks
-
-    return lines
-
-
 class OptionDummy:
     """Dummy class just used as a place to hold command-line option
     values as instance attributes."""
diff --git a/Lib/packaging/tests/test_command_sdist.py b/Lib/packaging/tests/test_command_sdist.py
--- a/Lib/packaging/tests/test_command_sdist.py
+++ b/Lib/packaging/tests/test_command_sdist.py
@@ -33,7 +33,6 @@
 
 MANIFEST = """\
 # file GENERATED by packaging, do NOT edit
-README
 inroot.txt
 data%(sep)sdata.dt
 scripts%(sep)sscript.py
@@ -129,7 +128,7 @@
             content = zip_file.namelist()
 
         # making sure everything has been pruned correctly
-        self.assertEqual(len(content), 3)
+        self.assertEqual(len(content), 2)
 
     @requires_zlib
     @unittest.skipIf(find_executable('tar') is None or
@@ -214,7 +213,7 @@
 
         # Making sure everything was added. This includes 9 code and data
         # files in addition to PKG-INFO.
-        self.assertEqual(len(content), 10)
+        self.assertEqual(len(content), 9)
 
         # Checking the MANIFEST
         with open(join(self.tmp_dir, 'MANIFEST')) as fp:
@@ -331,7 +330,7 @@
         with open(cmd.manifest) as f:
             manifest = [line.strip() for line in f.read().split('\n')
                         if line.strip() != '']
-        self.assertEqual(len(manifest), 4)
+        self.assertEqual(len(manifest), 3)
 
         # Adding a file
         self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#')
@@ -348,7 +347,7 @@
                          if line.strip() != '']
 
         # Do we have the new file in MANIFEST?
-        self.assertEqual(len(manifest2), 5)
+        self.assertEqual(len(manifest2), 4)
         self.assertIn('doc2.txt', manifest2[-1])
 
     @requires_zlib

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


More information about the Python-checkins mailing list