Description
What's the problem this feature will solve?
This is re-opening python/cpython#86175 for setuptools.
If I'm not mistaken, python/cpython#12341 is responsible for sorting sources in distutils to enable reproducible builds.
But since then, pywin32 has had to manually re-sort the sources by doing this:
from distutils import ccompiler
from distutils._msvccompiler import MSVCCompiler
def my_new_compiler(**kw):
if "compiler" in kw and kw["compiler"] in (None, "msvc"):
return my_compiler()
return orig_new_compiler(**kw)
# No way to cleanly wedge our compiler sub-class in.
orig_new_compiler = ccompiler.new_compiler
ccompiler.new_compiler = my_new_compiler
# This import has to be delayed to AFTER the compiler hack
from setuptools.command.build_ext import build_ext # noqa: E402
class my_compiler(MSVCCompiler):
# Work around bpo-36302/bpo-42009 - it sorts sources but this breaks
# support for building .mc files etc :(
def compile(self, sources, **kwargs) -> list[str]:
# re-sort the list of source files but ensure all .mc files come first.
def key_reverse_mc(a):
b, e = os.path.splitext(a)
e = "" if e == ".mc" else e
return (e, b)
sources = sorted(sources, key=key_reverse_mc)
return MSVCCompiler.compile(self, sources, **kwargs)
# [...]
If pywin32 didn't have to do this "compiler patching", I'm pretty sure I could remove this hack and 2 deprecated distutils imports
Describe the solution you'd like
I'd like setuptools (distutils) to sort sources in such a way that Message Compiler (.mc
) files come first.
If there's an already existing better way to handle .mc
files. Please let me know!
Alternative Solutions
(see the current workaround posted above)
Additional context
- https://github.com/mhammond/pywin32/blob/main/setup.py
- [BUG] v76.1.0 broke pywin32 builds #4968
- The docs make a brief mention of
.mc
files: https://setuptools.pypa.io/en/latest/deprecated/distutils/setupscript.html#extension-source-files - https://learn.microsoft.com/en-us/windows/win32/wes/message-compiler--mc-exe-
Code of Conduct
- I agree to follow the PSF Code of Conduct