Skip to content

Commit c08d07b

Browse files
committed
Extract methods to separate _safe_data_files behavior and _add_data_files. Simplify warning.
1 parent 751619d commit c08d07b

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

setuptools/command/sdist.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,31 @@ 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+
self._add_data_files(self._safe_data_files(build_py))
129130

130-
# This functionality is incompatible with include_package_data, and
131-
# will in fact create an infinite recursion if include_package_data
132-
# is True. Use of include_package_data will imply that
133-
# distutils-style automatic handling of package_data is disabled
134-
135-
if self.distribution.include_package_data:
136-
self.warn(
137-
"Either specify package_data manually, or use "
138-
"include_package_data=True, but not both. Proceeding as if "
139-
"package_data was not specified."
140-
)
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+
self.warn(
139+
"Distutils 'package_data' ignored due to "
140+
"'include_package_data'."
141+
)
142+
return ()
143+
return build_py.data_files
141144

142-
else:
143-
for _, src_dir, _, filenames in build_py.data_files:
144-
self.filelist.extend([os.path.join(src_dir, filename)
145-
for filename in filenames])
145+
def _add_data_files(self, data_files):
146+
"""
147+
Add data files as found in build_py.data_files.
148+
"""
149+
self.filelist.extend(
150+
os.path.join(src_dir, name)
151+
for _, src_dir, _, filenames in data_files
152+
for name in filenames
153+
)
146154

147155
def _add_defaults_data_files(self):
148156
try:

setuptools/tests/test_manifest.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,5 @@ def test_warning_on_meaningless_parameter_combination(self):
624624
mm.warn = mock.Mock()
625625
mm.run()
626626

627-
mm.warn.assert_called_with(
628-
"Either specify package_data manually, or use "
629-
"include_package_data=True, but not both. Proceeding as if "
630-
"package_data was not specified."
631-
)
627+
msg = "Distutils 'package_data' ignored due to 'include_package_data'."
628+
mm.warn.assert_called_with(msg)

0 commit comments

Comments
 (0)