Index: Lib/distutils/command/sdist.py =================================================================== --- Lib/distutils/command/sdist.py (revision 88286) +++ Lib/distutils/command/sdist.py (working copy) @@ -6,6 +6,7 @@ import os import string +import re import sys from glob import glob from warnings import warn @@ -182,33 +183,39 @@ reading the manifest, or just using the default file set -- it all depends on the user's options. """ - # new behavior: + # new behavior when using a template: # the file list is recalculated everytime because # even if MANIFEST.in or setup.py are not changed # the user might have added some files in the tree that # need to be included. # - # This makes --force the default and only behavior. + # This makes --force the default and only behavior with templates template_exists = os.path.isfile(self.template) if not template_exists: - self.warn(("manifest template '%s' does not exist " + - "(using default file list)") % - self.template) - self.filelist.findall() + manifest_exists = os.path.isfile(self.manifest) + if manifest_exists: + self.read_manifest() + return + else: + self.warn(("manifest template '%s' does not exist " + + "(using default file list)") % + self.template) - if self.use_defaults: - self.add_defaults() + self.filelist.findall() - if template_exists: - self.read_template() + if self.use_defaults: + self.add_defaults() - if self.prune: - self.prune_file_list() + if template_exists: + self.read_template() - self.filelist.sort() - self.filelist.remove_duplicates() - self.write_manifest() + if self.prune: + self.prune_file_list() + self.filelist.sort() + self.filelist.remove_duplicates() + self.write_manifest() + def add_defaults(self): """Add all the default files to self.filelist: - README or README.txt @@ -372,13 +379,18 @@ distribution. """ log.info("reading manifest file '%s'", self.manifest) + + # regular expression to match from # comment char to end of line + comment_regexp = re.compile('#.*') + manifest = open(self.manifest) - while 1: - line = manifest.readline() - if line == '': # end of file - break - if line[-1] == '\n': - line = line[0:-1] + for line in manifest.readlines(): + # kill comments, will leave some whitespace + line = comment_regexp.sub('', line) + # trim leading/trailing whitespace, but preserve embedded whitespace + line = line.strip() + # skip lines without any non-whitespace character remaining + if len(line) == 0: continue self.filelist.append(line) manifest.close()