Commit ebd84d7f authored by Éric Araujo's avatar Éric Araujo

Merge fixes for #9860, #11104/#8688 and #12331 from 3.2

parents df0c8a52 2659dbff
...@@ -174,14 +174,20 @@ class sdist(Command): ...@@ -174,14 +174,20 @@ class sdist(Command):
reading the manifest, or just using the default file set -- it all reading the manifest, or just using the default file set -- it all
depends on the user's options. depends on the user's options.
""" """
# new behavior: # new behavior when using a template:
# the file list is recalculated everytime because # the file list is recalculated everytime because
# even if MANIFEST.in or setup.py are not changed # even if MANIFEST.in or setup.py are not changed
# the user might have added some files in the tree that # the user might have added some files in the tree that
# need to be included. # 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) template_exists = os.path.isfile(self.template)
if not template_exists and self._manifest_is_not_generated():
self.read_manifest()
self.filelist.sort()
self.filelist.remove_duplicates()
return
if not template_exists: if not template_exists:
self.warn(("manifest template '%s' does not exist " + self.warn(("manifest template '%s' does not exist " +
"(using default file list)") % "(using default file list)") %
...@@ -336,14 +342,7 @@ class sdist(Command): ...@@ -336,14 +342,7 @@ class sdist(Command):
by 'add_defaults()' and 'read_template()') to the manifest file by 'add_defaults()' and 'read_template()') to the manifest file
named by 'self.manifest'. named by 'self.manifest'.
""" """
if os.path.isfile(self.manifest): if self._manifest_is_not_generated():
fp = open(self.manifest)
try:
first_line = fp.readline()
finally:
fp.close()
if first_line != '# file GENERATED by distutils, do NOT edit\n':
log.info("not writing to manually maintained " log.info("not writing to manually maintained "
"manifest file '%s'" % self.manifest) "manifest file '%s'" % self.manifest)
return return
...@@ -353,6 +352,18 @@ class sdist(Command): ...@@ -353,6 +352,18 @@ class sdist(Command):
self.execute(file_util.write_file, (self.manifest, content), self.execute(file_util.write_file, (self.manifest, content),
"writing manifest file '%s'" % self.manifest) "writing manifest file '%s'" % self.manifest)
def _manifest_is_not_generated(self):
# check for special comment used in 3.1.3 and higher
if not os.path.isfile(self.manifest):
return False
fp = open(self.manifest)
try:
first_line = fp.readline()
finally:
fp.close()
return first_line != '# file GENERATED by distutils, do NOT edit\n'
def read_manifest(self): def read_manifest(self):
"""Read the manifest file (named by 'self.manifest') and use it to """Read the manifest file (named by 'self.manifest') and use it to
fill in 'self.filelist', the list of files to include in the source fill in 'self.filelist', the list of files to include in the source
...@@ -360,12 +371,11 @@ class sdist(Command): ...@@ -360,12 +371,11 @@ class sdist(Command):
""" """
log.info("reading manifest file '%s'", self.manifest) log.info("reading manifest file '%s'", self.manifest)
manifest = open(self.manifest) manifest = open(self.manifest)
while True: for line in manifest:
line = manifest.readline() # ignore comments and blank lines
if line == '': # end of file line = line.strip()
break if line.startswith('#') or not line:
if line[-1] == '\n': continue
line = line[0:-1]
self.filelist.append(line) self.filelist.append(line)
manifest.close() manifest.close()
......
"""Tests for distutils.command.sdist.""" """Tests for distutils.command.sdist."""
import os import os
import tarfile
import unittest import unittest
import shutil import warnings
import zipfile import zipfile
from os.path import join from os.path import join
import sys from textwrap import dedent
import tempfile
import warnings
from test.support import captured_stdout, check_warnings, run_unittest from test.support import captured_stdout, check_warnings, run_unittest
from distutils.command.sdist import sdist, show_formats from distutils.command.sdist import sdist, show_formats
from distutils.core import Distribution from distutils.core import Distribution
from distutils.tests.test_config import PyPIRCCommandTestCase from distutils.tests.test_config import PyPIRCCommandTestCase
from distutils.errors import DistutilsExecError, DistutilsOptionError from distutils.errors import DistutilsOptionError
from distutils.spawn import find_executable from distutils.spawn import find_executable
from distutils.tests import support
from distutils.log import WARN from distutils.log import WARN
from distutils.archive_util import ARCHIVE_FORMATS from distutils.archive_util import ARCHIVE_FORMATS
...@@ -346,13 +344,33 @@ class SDistTestCase(PyPIRCCommandTestCase): ...@@ -346,13 +344,33 @@ class SDistTestCase(PyPIRCCommandTestCase):
self.assertEqual(manifest[0], self.assertEqual(manifest[0],
'# file GENERATED by distutils, do NOT edit') '# file GENERATED by distutils, do NOT edit')
@unittest.skipUnless(ZLIB_SUPPORT, "Need zlib support to run")
def test_manifest_comments(self):
# make sure comments don't cause exceptions or wrong includes
contents = dedent("""\
# bad.py
#bad.py
good.py
""")
dist, cmd = self.get_cmd()
cmd.ensure_finalized()
self.write_file((self.tmp_dir, cmd.manifest), contents)
self.write_file((self.tmp_dir, 'good.py'), '# pick me!')
self.write_file((self.tmp_dir, 'bad.py'), "# don't pick me!")
self.write_file((self.tmp_dir, '#bad.py'), "# don't pick me!")
cmd.run()
self.assertEqual(cmd.filelist.files, ['good.py'])
@unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run')
def test_manual_manifest(self): def test_manual_manifest(self):
# check that a MANIFEST without a marker is left alone # check that a MANIFEST without a marker is left alone
dist, cmd = self.get_cmd() dist, cmd = self.get_cmd()
cmd.ensure_finalized() cmd.ensure_finalized()
self.write_file((self.tmp_dir, cmd.manifest), 'README.manual') self.write_file((self.tmp_dir, cmd.manifest), 'README.manual')
self.write_file((self.tmp_dir, 'README.manual'),
'This project maintains its MANIFEST file itself.')
cmd.run() cmd.run()
self.assertEqual(cmd.filelist.files, ['README.manual'])
f = open(cmd.manifest) f = open(cmd.manifest)
try: try:
...@@ -363,6 +381,15 @@ class SDistTestCase(PyPIRCCommandTestCase): ...@@ -363,6 +381,15 @@ class SDistTestCase(PyPIRCCommandTestCase):
self.assertEqual(manifest, ['README.manual']) self.assertEqual(manifest, ['README.manual'])
archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
archive = tarfile.open(archive_name)
try:
filenames = [tarinfo.name for tarinfo in archive]
finally:
archive.close()
self.assertEqual(sorted(filenames), ['fake-1.0', 'fake-1.0/PKG-INFO',
'fake-1.0/README.manual'])
def test_suite(): def test_suite():
return unittest.makeSuite(SDistTestCase) return unittest.makeSuite(SDistTestCase)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment