cpython: ade53661607a (original) (raw)
Mercurial > cpython
changeset 102997:ade53661607a 3.5
Issue #12285: Merge with 3.4 [#12285]
Jason R. Coombs jaraco@jaraco.com | |
---|---|
date | Thu, 01 Sep 2016 21:15:04 -0400 |
parents | 546b1f70cbed(current diff)13619a3e0737(diff) |
children | 79422fab2ef4 0561fcc33211 |
files | Misc/NEWS |
diffstat | 3 files changed, 60 insertions(+), 30 deletions(-)[+] [-] Lib/distutils/filelist.py 46 Lib/distutils/tests/test_filelist.py 42 Misc/NEWS 2 |
line wrap: on
line diff
--- a/Lib/distutils/filelist.py +++ b/Lib/distutils/filelist.py @@ -6,6 +6,7 @@ and building lists of files. import os, re import fnmatch +import functools from distutils.util import convert_path from distutils.errors import DistutilsTemplateError, DistutilsInternalError from distutils import log @@ -242,35 +243,28 @@ class FileList:
----------------------------------------------------------------------
Utility functions
- results = (
os.path.join(base, file)[](#l1.33)
for base, dirs, files in os.walk(path, followlinks=True)[](#l1.34)
for file in files[](#l1.35)
- )
- return filter(os.path.isfile, results)
for name in names:[](#l1.39)
if dir != os.curdir: # avoid the dreaded "./" syndrome[](#l1.40)
fullname = os.path.join(dir, name)[](#l1.41)
else:[](#l1.42)
fullname = name[](#l1.43)
# Avoid excess stat calls -- just one will do, thank you
stat = os.stat(fullname)[](#l1.46)
mode = stat[ST_MODE][](#l1.47)
if S_ISREG(mode):[](#l1.48)
list.append(fullname)[](#l1.49)
elif S_ISDIR(mode) and not S_ISLNK(mode):[](#l1.50)
push(fullname)[](#l1.51)
- return list
- """
- Find all files under 'dir' and return the list of full filenames.
- Unless dir is '.', return full filenames with dir prepended.
- """
- files = _find_all_simple(dir)
- if dir == os.curdir:
make_rel = functools.partial(os.path.relpath, start=dir)[](#l1.60)
files = map(make_rel, files)[](#l1.61)
- return list(files)
--- a/Lib/distutils/tests/test_filelist.py +++ b/Lib/distutils/tests/test_filelist.py @@ -6,8 +6,10 @@ from distutils import debug from distutils.log import WARN from distutils.errors import DistutilsTemplateError from distutils.filelist import glob_to_re, translate_pattern, FileList +from distutils import filelist -from test.support import captured_stdout, run_unittest +import test.support +from test.support import captured_stdout from distutils.tests import support MANIFEST_IN = """[](#l2.14) @@ -292,8 +294,40 @@ class FileListTestCase(support.LoggingSi self.assertWarnings() -def test_suite():
+class FindAllTestCase(unittest.TestCase):
- @test.support.skip_unless_symlink
- def test_missing_symlink(self):
with test.support.temp_cwd():[](#l2.24)
os.symlink('foo', 'bar')[](#l2.25)
self.assertEqual(filelist.findall(), [])[](#l2.26)
- def test_basic_discovery(self):
"""[](#l2.29)
When findall is called with no parameters or with[](#l2.30)
'.' as the parameter, the dot should be omitted from[](#l2.31)
the results.[](#l2.32)
"""[](#l2.33)
with test.support.temp_cwd():[](#l2.34)
os.mkdir('foo')[](#l2.35)
file1 = os.path.join('foo', 'file1.txt')[](#l2.36)
test.support.create_empty_file(file1)[](#l2.37)
os.mkdir('bar')[](#l2.38)
file2 = os.path.join('bar', 'file2.txt')[](#l2.39)
test.support.create_empty_file(file2)[](#l2.40)
expected = [file2, file1][](#l2.41)
self.assertEqual(sorted(filelist.findall()), expected)[](#l2.42)
- def test_non_local_discovery(self):
"""[](#l2.45)
When findall is called with another path, the full[](#l2.46)
path name should be returned.[](#l2.47)
"""[](#l2.48)
with test.support.temp_dir() as temp_dir:[](#l2.49)
file1 = os.path.join(temp_dir, 'file1.txt')[](#l2.50)
test.support.create_empty_file(file1)[](#l2.51)
expected = [file1][](#l2.52)
self.assertEqual(filelist.findall(temp_dir), expected)[](#l2.53)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -50,6 +50,8 @@ Core and Builtins Library ------- +- Issue #12285: Fix error when distutils encounters symlink. +