88import sysconfig
99
1010from distutils import log
11- from distutils import text_file
1211from distutils .errors import *
1312from distutils .core import Extension , setup
1413from distutils .command .build_ext import build_ext
@@ -230,7 +229,12 @@ def build_extensions(self):
230229 headers = [sysconfig .get_config_h_filename ()]
231230 headers += glob (os .path .join (sysconfig .get_path ('include' ), "*.h" ))
232231
233- for ext in self .extensions [:]:
232+ # The sysconfig variable built by makesetup, listing the already
233+ # built modules as configured by the Setup files.
234+ modnames = sysconfig .get_config_var ('MODNAMES' ).split ()
235+
236+ removed_modules = []
237+ for ext in self .extensions :
234238 ext .sources = [ find_module_file (filename , moddirlist )
235239 for filename in ext .sources ]
236240 if ext .depends is not None :
@@ -241,26 +245,14 @@ def build_extensions(self):
241245 # re-compile extensions if a header file has been changed
242246 ext .depends .extend (headers )
243247
244- # If a module has already been built statically,
245- # don't build it here
246- if ext .name in sys .builtin_module_names :
247- self .extensions .remove (ext )
248-
249- # Parse Modules/Setup and Modules/Setup.local to figure out which
250- # modules are turned on in the file.
251- remove_modules = []
252- for filename in ('Modules/Setup' , 'Modules/Setup.local' ):
253- input = text_file .TextFile (filename , join_lines = 1 )
254- while 1 :
255- line = input .readline ()
256- if not line : break
257- line = line .split ()
258- remove_modules .append (line [0 ])
259- input .close ()
260-
261- for ext in self .extensions [:]:
262- if ext .name in remove_modules :
263- self .extensions .remove (ext )
248+ # If a module has already been built by the Makefile,
249+ # don't build it here.
250+ if ext .name in modnames :
251+ removed_modules .append (ext )
252+
253+ if removed_modules :
254+ self .extensions = [x for x in self .extensions if x not in
255+ removed_modules ]
264256
265257 # When you run "make CC=altcc" or something similar, you really want
266258 # those environment variables passed into the setup.py phase. Here's
@@ -303,6 +295,13 @@ def print_three_column(lst):
303295 " detect_modules() for the module's name." )
304296 print ()
305297
298+ if removed_modules :
299+ print ("The following modules found by detect_modules() in"
300+ " setup.py, have been" )
301+ print ("built by the Makefile instead, as configured by the"
302+ " Setup files:" )
303+ print_three_column ([ext .name for ext in removed_modules ])
304+
306305 if self .failed :
307306 failed = self .failed [:]
308307 print ()
0 commit comments