Skip to content

Commit 1a59fdb

Browse files
committed
Re-order import to fix re-assignment hack
1 parent fab3199 commit 1a59fdb

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

pyproject.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
[build-system]
2-
# setuptools==77.0.3 made PEP-639 license deprecations introduced by 77.0.0 into warnings rather than errors
3-
# setuptools==75.4 dropped support for Python 3.8
4-
# setuptools==76.1 breaks building of .mc files
5-
# win32/src/PythonService.cpp(49): fatal error C1083: Cannot open include file: 'PythonServiceMessages.h': No such file or directory
6-
requires = [
7-
"setuptools >=77.0.3; python_version >='3.9'",
8-
"setuptools <76.1; python_version <'3.9'",
9-
]
2+
# As of setuptools==74, we no longer need to be concerned about distutils calling win32api
3+
requires = ["setuptools>=74"]
104
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
import winreg
3636
from collections.abc import MutableSequence
3737
from pathlib import Path
38+
from tempfile import gettempdir
39+
from typing import TYPE_CHECKING, Iterable
40+
3841
from setuptools import Extension, setup
3942
from setuptools.command.build import build
40-
from setuptools.command.build_ext import build_ext
4143
from setuptools.modified import newer_group
42-
from tempfile import gettempdir
43-
from typing import TYPE_CHECKING, Iterable
44+
from setuptools._distutils import ccompiler
4445

4546
# We must import from distutils directly at runtime
4647
# But this prevents typing issues across Python 3.11-3.12
@@ -53,8 +54,24 @@
5354
from distutils._msvccompiler import MSVCCompiler
5455
from distutils.command.install_data import install_data
5556

57+
58+
def my_new_compiler(**kw):
59+
raise Exception("Is this ever called?")
60+
if "compiler" in kw and kw["compiler"] in (None, "msvc"):
61+
return my_compiler()
62+
return orig_new_compiler(**kw)
63+
64+
65+
# No way to cleanly wedge our compiler sub-class in.
66+
orig_new_compiler = ccompiler.new_compiler
67+
ccompiler.new_compiler = my_new_compiler # type: ignore[assignment] # Assuming the caller will always use only kwargs
68+
69+
70+
from setuptools.command.build_ext import build_ext # noqa: E402 # This has to be imported AFTER the compiler hack
71+
72+
5673
build_id_patch = build_id
57-
if not "." in build_id_patch:
74+
if "." not in build_id_patch:
5875
build_id_patch += ".0"
5976
pywin32_version = "%d.%d.%s" % (
6077
sys.version_info.major,
@@ -310,7 +327,7 @@ def __init__(self, name, **kw):
310327

311328
# The stand-alone exchange SDK has these libs
312329
# Additional utility functions are only available for 32-bit builds.
313-
if not platform.machine() in ("AMD64", "ARM64"):
330+
if platform.machine() not in ("AMD64", "ARM64"):
314331
libs += " version user32 advapi32 Ex2KSdk sadapi netapi32"
315332
kw["libraries"] = libs
316333
WinExt_win32com.__init__(self, name, **kw)
@@ -856,17 +873,6 @@ def swig_sources(self, sources, ext=None):
856873
return new_sources
857874

858875

859-
def my_new_compiler(**kw):
860-
if "compiler" in kw and kw["compiler"] in (None, "msvc"):
861-
return my_compiler()
862-
return orig_new_compiler(**kw)
863-
864-
865-
# No way to cleanly wedge our compiler sub-class in.
866-
orig_new_compiler = ccompiler.new_compiler
867-
ccompiler.new_compiler = my_new_compiler # type: ignore[assignment] # Assuming the caller will always use only kwargs
868-
869-
870876
class my_compiler(MSVCCompiler):
871877
def link(
872878
self,
@@ -922,6 +928,7 @@ def key_reverse_mc(a):
922928
return (e, b)
923929

924930
sources = sorted(sources, key=key_reverse_mc)
931+
raise Exception("breakpoint")
925932
return MSVCCompiler.compile(self, sources, **kwargs)
926933

927934
def spawn(self, cmd: MutableSequence[str]) -> None: # type: ignore[override] # More restrictive than supertype

0 commit comments

Comments
 (0)