diff --git a/Lib/distutils/filelist.py b/Lib/distutils/filelist.py --- a/Lib/distutils/filelist.py +++ b/Lib/distutils/filelist.py @@ -328,8 +328,9 @@ def translate_pattern(pattern, anchor=1, # ditch end of pattern character empty_pattern = glob_to_re('') prefix_re = glob_to_re(prefix)[:-len(empty_pattern)] - # paths should always use / in manifest templates - pattern_re = "^%s/.*%s" % (prefix_re, pattern_re) + pattern_re = ".*" + pattern_re + # need to escape os.sep for Windows + pattern_re = "^" + re.escape(os.sep).join((prefix_re, pattern_re)) else: # no prefix -- respect anchor flag if anchor: pattern_re = "^" + pattern_re diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py --- a/Lib/distutils/tests/test_filelist.py +++ b/Lib/distutils/tests/test_filelist.py @@ -1,6 +1,7 @@ """Tests for distutils.filelist.""" import re import unittest +from os.path import join from distutils import debug from distutils.log import WARN from distutils.errors import DistutilsTemplateError @@ -14,6 +15,7 @@ include ok include xo exclude xo include foo.tmp +include buildout.cfg global-include *.x global-include *.txt global-exclude *.tmp @@ -53,15 +55,19 @@ class FileListTestCase(support.LoggingSi # simulated file list file_list.allfiles = ['foo.tmp', 'ok', 'xo', 'four.txt', - 'global/one.txt', - 'global/two.txt', - 'global/files.x', - 'global/here.tmp', - 'f/o/f.oo', - 'dir/graft-one', - 'dir/dir2/graft2', - 'dir3/ok', - 'dir3/sub/ok.txt', + 'buildout.cfg', + # filelist does not filter out VCS directories, + # it's sdist that does + join('.hg', 'last-message.txt'), + join('global', 'one.txt'), + join('global', 'two.txt'), + join('global', 'files.x'), + join('global', 'here.tmp'), + join('f', 'o', 'f.oo'), + join('dir', 'graft-one'), + join('dir', 'dir2', 'graft2'), + join('dir3', 'ok'), + join('dir3', 'sub', 'ok.txt'), ] for line in MANIFEST_IN.split('\n'): @@ -69,8 +75,10 @@ class FileListTestCase(support.LoggingSi continue file_list.process_template_line(line) - wanted = ['ok', 'four.txt', 'global/one.txt', 'global/two.txt', - 'f/o/f.oo', 'dir/graft-one', 'dir/dir2/graft2'] + wanted = ['ok', 'buildout.cfg', 'four.txt', + join('.hg', 'last-message.txt'), join('global', 'one.txt'), + join('global', 'two.txt'), join('f', 'o', 'f.oo'), + join('dir', 'graft-one'), join('dir', 'dir2', 'graft2')] self.assertEqual(file_list.files, wanted) diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py --- a/Lib/distutils/tests/test_sdist.py +++ b/Lib/distutils/tests/test_sdist.py @@ -42,6 +42,7 @@ setup(name='fake') MANIFEST = """\ # file GENERATED by distutils, do NOT edit README +buildout.cfg inroot.txt setup.py data%(sep)sdata.dt @@ -209,11 +210,18 @@ class SDistTestCase(PyPIRCCommandTestCas self.write_file((data_dir, 'data.dt'), '#') some_dir = join(self.tmp_dir, 'some') os.mkdir(some_dir) + # make sure VCS directories are pruned (#14004) + hg_dir = join(self.tmp_dir, '.hg') + os.mkdir(hg_dir) + self.write_file((hg_dir, 'last-message.txt'), '#') + # a buggy regex used to prevent this from working on windows (#6884) + self.write_file((self.tmp_dir, 'buildout.cfg'), '#') self.write_file((self.tmp_dir, 'inroot.txt'), '#') self.write_file((some_dir, 'file.txt'), '#') self.write_file((some_dir, 'other_file.txt'), '#') dist.data_files = [('data', ['data/data.dt', + 'buildout.cfg', 'inroot.txt', 'notexisting']), 'some/file.txt', @@ -243,15 +251,15 @@ class SDistTestCase(PyPIRCCommandTestCas zip_file.close() # making sure everything was added - self.assertEqual(len(content), 11) + self.assertEqual(len(content), 12) # checking the MANIFEST f = open(join(self.tmp_dir, 'MANIFEST')) try: manifest = f.read() - self.assertEqual(manifest, MANIFEST % {'sep': os.sep}) finally: f.close() + self.assertEqual(manifest, MANIFEST % {'sep': os.sep}) @unittest.skipUnless(zlib, "requires zlib") def test_metadata_check_option(self):