Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca9242f

Browse files
committed
Merge with 3.2 for Issue #19286.
2 parents 0aade62 + 32bf5e1 commit ca9242f

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

Lib/distutils/command/build_py.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ def find_data_files(self, package, src_dir):
127127
# Each pattern has to be converted to a platform-specific path
128128
filelist = glob(os.path.join(src_dir, convert_path(pattern)))
129129
# Files that match more than one pattern are only added once
130-
files.extend([fn for fn in filelist if fn not in files])
130+
files.extend([fn for fn in filelist if fn not in files
131+
and os.path.isfile(fn)])
131132
return files
132133

133134
def build_package_data(self):

Lib/distutils/tests/test_build_py.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,37 @@ def test_byte_compile_optimized(self):
121121
found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
122122
self.assertEqual(sorted(found), ['boiledeggs.%s.pyo' % imp.get_tag()])
123123

124+
def test_dir_in_package_data(self):
125+
"""
126+
A directory in package_data should not be added to the filelist.
127+
"""
128+
# See bug 19286
129+
sources = self.mkdtemp()
130+
pkg_dir = os.path.join(sources, "pkg")
131+
132+
os.mkdir(pkg_dir)
133+
open(os.path.join(pkg_dir, "__init__.py"), "w").close()
134+
135+
docdir = os.path.join(pkg_dir, "doc")
136+
os.mkdir(docdir)
137+
open(os.path.join(docdir, "testfile"), "w").close()
138+
139+
# create the directory that could be incorrectly detected as a file
140+
os.mkdir(os.path.join(docdir, 'otherdir'))
141+
142+
os.chdir(sources)
143+
dist = Distribution({"packages": ["pkg"],
144+
"package_data": {"pkg": ["doc/*"]}})
145+
# script_name need not exist, it just need to be initialized
146+
dist.script_name = os.path.join(sources, "setup.py")
147+
dist.script_args = ["build"]
148+
dist.parse_command_line()
149+
150+
try:
151+
dist.run_commands()
152+
except DistutilsFileError:
153+
self.fail("failed package_data when data dir includes a dir")
154+
124155
def test_dont_write_bytecode(self):
125156
# makes sure byte_compile is not used
126157
dist = self.create_dist()[1]

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #19286: Directories in ``package_data`` are no longer added to
17+
the filelist, preventing failure outlined in the ticket.
18+
1619
- Issue #19435: Fix directory traversal attack on CGIHttpRequestHandler.
1720

1821
Tests

0 commit comments

Comments
 (0)