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.
This commit is contained in:
Éric Araujo 2011-05-31 18:04:32 +02:00
parent a94bdee2e4
commit 9deedf696e
3 changed files with 6 additions and 102 deletions

View File

@ -1,10 +1,9 @@
"""Create a source distribution."""
import os
import sys
import re
import sys
from io import StringIO
from glob import glob
from shutil import get_archive_formats, rmtree
from packaging import logger
@ -203,45 +202,14 @@ class sdist(Command):
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)

View File

@ -13,7 +13,6 @@ It is used under the hood by the command classes. Do not use directly.
import getopt
import re
import sys
import string
import textwrap
from packaging.errors import PackagingGetoptError, PackagingArgError
@ -378,68 +377,6 @@ def fancy_getopt(options, negative_opt, object, args):
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."""

View File

@ -33,7 +33,6 @@ setup(name='fake')
MANIFEST = """\
# file GENERATED by packaging, do NOT edit
README
inroot.txt
data%(sep)sdata.dt
scripts%(sep)sscript.py
@ -129,7 +128,7 @@ class SDistTestCase(support.TempdirManager,
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 @@ class SDistTestCase(support.TempdirManager,
# 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 @@ class SDistTestCase(support.TempdirManager,
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 @@ class SDistTestCase(support.TempdirManager,
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