@@ -378,8 +378,8 @@ def run(self):
378378
379379
380380class my_build_ext (build_ext ):
381- def finalize_options (self ):
382- build_ext .finalize_options (self )
381+ def finalize_options (self ) -> None :
382+ super () .finalize_options ()
383383
384384 self .plat_dir = {
385385 "win-amd64" : "x64" ,
@@ -393,8 +393,9 @@ def finalize_options(self):
393393 if self .mingw32 :
394394 self .libraries .append ("stdc++" )
395395
396- self .excluded_extensions = [] # list of (ext, why)
397- self .swig_cpp = True # hrm - deprecated - should use swig_opts=-c++??
396+ self .excluded_extensions : list [tuple [WinExt , str ]] = []
397+ """List of excluded extensions and their reason"""
398+ self .swig_opts .append ("-c++" )
398399
399400 def _why_cant_build_extension (self , ext ):
400401 """Return None, or a reason it can't be built."""
@@ -539,6 +540,25 @@ def _check_vc(self):
539540 print ("-- ATLMFC paths likely missing (Required for win32ui)" )
540541 return vcbase , vcverdir
541542
543+ def _verstamp (self , filename ):
544+ """
545+ Stamp the version of the built target.
546+ Do this externally to avoid suddenly dragging in the
547+ modules needed by this process.
548+ """
549+ self .spawn (
550+ [
551+ sys .executable ,
552+ Path (__file__ ).parent / "win32" / "Lib" / "win32verstamp.py" ,
553+ f"--version={ pywin32_version } " ,
554+ "--comments=https://github.com/mhammond/pywin32" ,
555+ f"--original-filename={ os .path .basename (filename )} " ,
556+ "--product=PyWin32" ,
557+ "--quiet" if "-v" not in sys .argv else "" ,
558+ filename ,
559+ ]
560+ )
561+
542562 def build_extensions (self ):
543563 # First, sanity-check the 'extensions' list
544564 self .check_extensions_list (self .extensions )
@@ -598,24 +618,6 @@ def build_extensions(self):
598618 print ("-- compiler.library_dirs:" , self .compiler .library_dirs )
599619 raise RuntimeError ("Too many extensions skipped, check build environment" )
600620
601- for ext in [* self .extensions , * W32_exe_files ]:
602- # Stamp the version of the built target.
603- # Do this externally to avoid suddenly dragging in the
604- # modules needed by this process, and which we will soon try and update.
605- ext_path = self .get_ext_fullpath (ext .name )
606- self .spawn (
607- [
608- sys .executable ,
609- Path (__file__ ).parent / "win32" / "Lib" / "win32verstamp.py" ,
610- f"--version={ pywin32_version } " ,
611- "--comments=https://github.com/mhammond/pywin32" ,
612- f"--original-filename={ os .path .basename (ext_path )} " ,
613- "--product=PyWin32" ,
614- "--quiet" if "-v" not in sys .argv else "" ,
615- ext_path ,
616- ]
617- )
618-
619621 # Not sure how to make this completely generic, and there is no
620622 # need at this stage.
621623 self ._build_scintilla ()
@@ -701,6 +703,8 @@ def build_exefile(self, ext):
701703 build_temp = self .build_temp ,
702704 )
703705
706+ self ._verstamp (full_name )
707+
704708 def build_extension (self , ext ):
705709 # Some of these extensions are difficult to build, requiring various
706710 # hard-to-track libraries et (eg, exchange sdk, etc). So we
@@ -741,6 +745,7 @@ def build_extension(self, ext):
741745
742746 try :
743747 build_ext .build_extension (self , ext )
748+ self ._verstamp (self .get_ext_fullpath (ext .name ))
744749 # Convincing distutils to create .lib files with the name we
745750 # need is difficult, so we just hack around it by copying from
746751 # the created name to the name we need.
@@ -890,8 +895,9 @@ def swig_sources(self, sources, ext=None):
890895
891896
892897class my_compiler (MSVCCompiler ):
893- # Work around bpo-36302/bpo-42009 - it sorts sources but this breaks
894- # support for building .mc files etc :(
898+ # Work around python/cpython#80483 / python/cpython#86175
899+ # it sorts sources but this breaks support for building .mc files etc :(
900+ # See pypa/setuptools#4986 / pypa/distutils#370 for potential upstream fix.
895901 def compile (self , sources , ** kwargs ):
896902 # re-sort the list of source files but ensure all .mc files come first.
897903 def key_reverse_mc (a ):
0 commit comments