summaryrefslogtreecommitdiff
path: root/Lib/distutils/filelist.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2012-02-25 16:28:05 +0100
committerÉric Araujo <merwok@netwok.org>2012-02-25 16:28:05 +0100
commitb3880c519fec5adc6676ae67d8eae8dad7ad8bc7 (patch)
tree00c13ed8600ea59a9e6d04d45f5fa811adf08d84 /Lib/distutils/filelist.py
parentce7ff72bb9a5b432d40ff8b611ffe3c37733c3b3 (diff)
downloadcpython-b3880c519fec5adc6676ae67d8eae8dad7ad8bc7.tar.gz
Fix long-standing bugs with MANIFEST.in parsing on Windows (#6884).
These regex changes fix a number of issues for distutils on Windows: - #6884: impossible to include a file starting with 'build' - #9691 and #14004: sdist includes too many files - #13193: test_filelist failures This commit replaces the incorrect changes done in 0a94e2f807c7 and 90b30d62caf2 to fix #13193; we were too eager to fix the test failures and I did not study the code enough before greenlighting patches. This time we have unit tests from the problems reported by users to be sure we have the right fix. Thanks to Nadeem Vawda for his help.
Diffstat (limited to 'Lib/distutils/filelist.py')
-rw-r--r--Lib/distutils/filelist.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/Lib/distutils/filelist.py b/Lib/distutils/filelist.py
index 91220321a4..db3f7a9680 100644
--- a/Lib/distutils/filelist.py
+++ b/Lib/distutils/filelist.py
@@ -201,6 +201,7 @@ class FileList:
Return True if files are found, False otherwise.
"""
+ # XXX docstring lying about what the special chars are?
files_found = False
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
self.debug_print("include_pattern: applying regex r'%s'" %
@@ -284,11 +285,14 @@ def glob_to_re(pattern):
# IMHO is wrong -- '?' and '*' aren't supposed to match slash in Unix,
# and by extension they shouldn't match such "special characters" under
# any OS. So change all non-escaped dots in the RE to match any
- # character except the special characters.
- # XXX currently the "special characters" are just slash -- i.e. this is
- # Unix-only.
- pattern_re = re.sub(r'((?<!\\)(\\\\)*)\.', r'\1[^/]', pattern_re)
-
+ # character except the special characters (currently: just os.sep).
+ sep = os.sep
+ if os.sep == '\\':
+ # we're using a regex to manipulate a regex, so we need
+ # to escape the backslash twice
+ sep = r'\\\\'
+ escaped = r'\1[^%s]' % sep
+ pattern_re = re.sub(r'((?<!\\)(\\\\)*)\.', escaped, pattern_re)
return pattern_re
@@ -312,9 +316,11 @@ def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
if prefix is not None:
# 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)
+ prefix_re = glob_to_re(prefix)[:-len(empty_pattern)]
+ sep = os.sep
+ if os.sep == '\\':
+ sep = r'\\'
+ pattern_re = "^" + sep.join((prefix_re, ".*" + pattern_re))
else: # no prefix -- respect anchor flag
if anchor:
pattern_re = "^" + pattern_re