Skip to content

Commit 3910bbb

Browse files
committed
Extract methods to separate _safe_data_files behavior and _add_data_files.
1 parent 1d03fdc commit 3910bbb

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

setuptools/command/sdist.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,27 @@ def _add_defaults_python(self):
126126
if self.distribution.has_pure_modules():
127127
build_py = self.get_finalized_command('build_py')
128128
self.filelist.extend(build_py.get_source_files())
129-
# This functionality is incompatible with include_package_data, and
130-
# will in fact create an infinite recursion if include_package_data
131-
# is True. Use of include_package_data will imply that
132-
# distutils-style automatic handling of package_data is disabled
133-
if not self.distribution.include_package_data:
134-
for _, src_dir, _, filenames in build_py.data_files:
135-
self.filelist.extend([os.path.join(src_dir, filename)
136-
for filename in filenames])
129+
self._add_data_files(self._safe_data_files(build_py))
130+
131+
def _safe_data_files(self, build_py):
132+
"""
133+
Extracting data_files from build_py is known to cause
134+
infinite recursion errors when `include_package_data`
135+
is enabled, so suppress it in that case.
136+
"""
137+
if self.distribution.include_package_data:
138+
return ()
139+
return build_py.data_files
140+
141+
def _add_data_files(self, data_files):
142+
"""
143+
Add data files as found in build_py.data_files.
144+
"""
145+
self.filelist.extend(
146+
os.path.join(src_dir, name)
147+
for _, src_dir, _, filenames in data_files
148+
for name in filenames
149+
)
137150

138151
def _add_defaults_data_files(self):
139152
try:

0 commit comments

Comments
 (0)