@@ -303,38 +303,38 @@ def run(self):
303303
304304 # Setup the CCompiler object that we'll use to do all the
305305 # compiling and linking
306- self .compiler = new_compiler (compiler = self .compiler ,
306+ self ._compiler = new_compiler (compiler = self .compiler ,
307307 verbose = self .verbose ,
308308 dry_run = self .dry_run ,
309309 force = self .force )
310- customize_compiler (self .compiler )
310+ customize_compiler (self ._compiler )
311311 # If we are cross-compiling, init the compiler now (if we are not
312312 # cross-compiling, init would not hurt, but people may rely on
313313 # late initialization of compiler even if they shouldn't...)
314314 if os .name == 'nt' and self .plat_name != get_platform ():
315- self .compiler .initialize (self .plat_name )
315+ self ._compiler .initialize (self .plat_name )
316316
317317 # And make sure that any compile/link-related options (which might
318318 # come from the command-line or from the setup script) are set in
319319 # that CCompiler object -- that way, they automatically apply to
320320 # all compiling and linking done here.
321321 if self .include_dirs is not None :
322- self .compiler .set_include_dirs (self .include_dirs )
322+ self ._compiler .set_include_dirs (self .include_dirs )
323323 if self .define is not None :
324324 # 'define' option is a list of (name,value) tuples
325325 for (name , value ) in self .define :
326- self .compiler .define_macro (name , value )
326+ self ._compiler .define_macro (name , value )
327327 if self .undef is not None :
328328 for macro in self .undef :
329- self .compiler .undefine_macro (macro )
329+ self ._compiler .undefine_macro (macro )
330330 if self .libraries is not None :
331- self .compiler .set_libraries (self .libraries )
331+ self ._compiler .set_libraries (self .libraries )
332332 if self .library_dirs is not None :
333- self .compiler .set_library_dirs (self .library_dirs )
333+ self ._compiler .set_library_dirs (self .library_dirs )
334334 if self .rpath is not None :
335- self .compiler .set_runtime_library_dirs (self .rpath )
335+ self ._compiler .set_runtime_library_dirs (self .rpath )
336336 if self .link_objects is not None :
337- self .compiler .set_link_objects (self .link_objects )
337+ self ._compiler .set_link_objects (self .link_objects )
338338
339339 # Now actually compile and link everything.
340340 self .build_extensions ()
@@ -438,9 +438,7 @@ def get_outputs(self):
438438 # "build" tree.
439439 outputs = []
440440 for ext in self .extensions :
441- fullname = self .get_ext_fullname (ext .name )
442- outputs .append (os .path .join (self .build_lib ,
443- self .get_ext_filename (fullname )))
441+ outputs .append (self .get_ext_fullpath (ext .name ))
444442 return outputs
445443
446444 def build_extensions (self ):
@@ -459,24 +457,9 @@ def build_extension(self, ext):
459457 "a list of source filenames" ) % ext .name
460458 sources = list (sources )
461459
462- fullname = self .get_ext_fullname (ext .name )
463- if self .inplace :
464- # ignore build-lib -- put the compiled extension into
465- # the source tree along with pure Python modules
466-
467- modpath = string .split (fullname , '.' )
468- package = string .join (modpath [0 :- 1 ], '.' )
469- base = modpath [- 1 ]
470-
471- build_py = self .get_finalized_command ('build_py' )
472- package_dir = build_py .get_package_dir (package )
473- ext_filename = os .path .join (package_dir ,
474- self .get_ext_filename (base ))
475- else :
476- ext_filename = os .path .join (self .build_lib ,
477- self .get_ext_filename (fullname ))
460+ ext_path = self .get_ext_fullpath (ext .name )
478461 depends = sources + ext .depends
479- if not (self .force or newer_group (depends , ext_filename , 'newer' )):
462+ if not (self .force or newer_group (depends , ext_path , 'newer' )):
480463 log .debug ("skipping '%s' extension (up-to-date)" , ext .name )
481464 return
482465 else :
@@ -507,13 +490,13 @@ def build_extension(self, ext):
507490 for undef in ext .undef_macros :
508491 macros .append ((undef ,))
509492
510- objects = self .compiler .compile (sources ,
511- output_dir = self .build_temp ,
512- macros = macros ,
513- include_dirs = ext .include_dirs ,
514- debug = self .debug ,
515- extra_postargs = extra_args ,
516- depends = ext .depends )
493+ objects = self ._compiler .compile (sources ,
494+ output_dir = self .build_temp ,
495+ macros = macros ,
496+ include_dirs = ext .include_dirs ,
497+ debug = self .debug ,
498+ extra_postargs = extra_args ,
499+ depends = ext .depends )
517500
518501 # XXX -- this is a Vile HACK!
519502 #
@@ -534,10 +517,10 @@ def build_extension(self, ext):
534517 extra_args = ext .extra_link_args or []
535518
536519 # Detect target language, if not provided
537- language = ext .language or self .compiler .detect_language (sources )
520+ language = ext .language or self ._compiler .detect_language (sources )
538521
539- self .compiler .link_shared_object (
540- objects , ext_filename ,
522+ self ._compiler .link_shared_object (
523+ objects , ext_path ,
541524 libraries = self .get_libraries (ext ),
542525 library_dirs = ext .library_dirs ,
543526 runtime_library_dirs = ext .runtime_library_dirs ,
@@ -639,8 +622,28 @@ def find_swig (self):
639622
640623 # -- Name generators -----------------------------------------------
641624 # (extension names, filenames, whatever)
625+ def get_ext_fullpath (self , ext_name ):
626+ """Returns the path of the filename for a given extension.
627+
628+ The file is located in `build_lib` or directly in the package
629+ (inplace option).
630+ """
631+ if self .inplace :
632+ fullname = self .get_ext_fullname (ext_name )
633+ modpath = fullname .split ('.' )
634+ package = '.' .join (modpath [0 :- 1 ])
635+ base = modpath [- 1 ]
636+ build_py = self .get_finalized_command ('build_py' )
637+ package_dir = os .path .abspath (build_py .get_package_dir (package ))
638+ return os .path .join (package_dir , base )
639+ else :
640+ filename = self .get_ext_filename (ext_name )
641+ return os .path .join (self .build_lib , filename )
642+
643+ def get_ext_fullname (self , ext_name ):
644+ """Returns the fullname of a given extension name.
642645
643- def get_ext_fullname ( self , ext_name ):
646+ Adds the `package.` prefix"""
644647 if self .package is None :
645648 return ext_name
646649 else :
@@ -687,7 +690,7 @@ def get_libraries (self, ext):
687690 # Append '_d' to the python import library on debug builds.
688691 if sys .platform == "win32" :
689692 from distutils .msvccompiler import MSVCCompiler
690- if not isinstance (self .compiler , MSVCCompiler ):
693+ if not isinstance (self ._compiler , MSVCCompiler ):
691694 template = "python%d%d"
692695 if self .debug :
693696 template = template + '_d'
0 commit comments