@@ -126,14 +126,27 @@ def _add_defaults_python(self):
126
126
if self .distribution .has_pure_modules ():
127
127
build_py = self .get_finalized_command ('build_py' )
128
128
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
+ )
137
150
138
151
def _add_defaults_data_files (self ):
139
152
try :
0 commit comments