Skip to content

Commit

Permalink
distutils direct replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Oct 1, 2023
1 parent 03a8bb1 commit 4c10d3a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
1 change: 1 addition & 0 deletions com/win32com/test/pippo_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def Method3(self, in1):


def BuildTypelib():
# https://github.com/pypa/setuptools/pull/4069
from distutils.dep_util import newer

this_dir = os.path.dirname(__file__)
Expand Down
2 changes: 2 additions & 0 deletions pywin32_postinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def flush(self):
# a list of actions for the uninstaller, the format is inspired by what
# the Wise installer also creates.
file_created
# 3.10 stopped supporting bdist_wininst, but we can still build them with 3.9.
# This can be kept until Python 3.9 or exe installers support is dropped.
is_bdist_wininst = True
except NameError:
is_bdist_wininst = False # we know what it is not - but not what it is :)
Expand Down
68 changes: 34 additions & 34 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,28 @@
import subprocess
import sys
import winreg
import logging

# setuptools must be imported before distutils for markh in some python versions.
# CI doesn't hit this, so not sure what's going on.
# setuptools must be imported before distutils because it monkey-patches it.
# distutils is also removed in Python 3.12 and deprecated with setuptools
from setuptools import Extension
from setuptools import setup
from setuptools.command.build_ext import build_ext
from setuptools.command.build import build
from setuptools.command.install import install
from setuptools.command.install_lib import install_lib

from distutils import log
from distutils.command.build import build
from distutils.command.install import install
from distutils.command.install_data import install_data
from distutils.command.install_lib import install_lib
from distutils.core import Extension

# https://github.com/pypa/setuptools/pull/4069
from distutils.dep_util import newer_group
from distutils.filelist import FileList
from tempfile import gettempdir

# some modules need a static CRT to avoid problems caused by them having a
# manifest.
static_crt_modules = ["winxpgui"]


import distutils.util
from distutils.dep_util import newer_group
from distutils.filelist import FileList

build_id_patch = build_id
if not "." in build_id_patch:
build_id_patch = build_id_patch + ".0"
Expand Down Expand Up @@ -317,10 +316,8 @@ def __init__(self, name, **kw):
kw.setdefault("library_dirs", []).insert(0, d)

# The stand-alone exchange SDK has these libs
if distutils.util.get_platform() in ["win-amd64", "win-arm64"]:
# Additional utility functions are only available for 32-bit builds.
pass
else:
# Additional utility functions are only available for 32-bit builds.
if not platform.machine() in ("AMD64", "ARM64"):
libs += " version user32 advapi32 Ex2KSdk sadapi netapi32"
kw["libraries"] = libs
WinExt_win32com.__init__(self, name, **kw)
Expand Down Expand Up @@ -430,7 +427,7 @@ def _why_cant_build_extension(self, ext):
if os.path.isfile(os.path.join(d, h)):
break
else:
log.debug("Header '%s' not found in %s", h, look_dirs)
logging.debug("Header '%s' not found in %s", h, look_dirs)
return "The header '%s' can not be located." % (h,)

common_dirs = self.compiler.library_dirs[:]
Expand All @@ -443,7 +440,7 @@ def _why_cant_build_extension(self, ext):
look_dirs = common_dirs + ext.library_dirs
found = self.compiler.find_library_file(look_dirs, lib, self.debug)
if not found:
log.debug("Lib '%s' not found in %s", lib, look_dirs)
logging.debug("Lib '%s' not found in %s", lib, look_dirs)
return "No library '%s'" % lib
self.found_libraries[lib.lower()] = found
patched_libs.append(os.path.splitext(os.path.basename(found))[0])
Expand Down Expand Up @@ -665,18 +662,18 @@ def build_extensions(self):
def build_exefile(self, ext):
_d = self.debug and "_d" or ""

log.info("building exe '%s'", ext.name)
logging.info("building exe '%s'", ext.name)
leaf_name = f"{ext.get_pywin32_dir()}\\{ext.name}{_d}.exe"
full_name = os.path.join(self.build_lib, leaf_name)

sources = list(ext.sources)
depends = sources + ext.depends
# unclear why we need to check this!?
if not (self.force or newer_group(depends, full_name, "newer")):
log.debug("skipping '%s' executable (up-to-date)", ext.name)
logging.debug("skipping '%s' executable (up-to-date)", ext.name)
return
else:
log.info("building '%s' executable", ext.name)
logging.info("building '%s' executable", ext.name)

objects = self.compiler.compile(
sources,
Expand Down Expand Up @@ -853,12 +850,15 @@ def swig_sources(self, sources, ext=None):

swig = self.find_swig()
for source in swig_sources:
swig_cmd = [swig, "-python", "-c++"]
swig_cmd.append(
swig_cmd = [
swig,
"-python",
"-c++",
# we never use the .doc files.
"-dnone",
) # we never use the .doc files.
]
swig_cmd.extend(self.current_extension.extra_swig_commands)
if distutils.util.get_platform() in ["win-amd64", "win-arm64"]:
if platform.machine() in ("AMD64", "ARM64"):
swig_cmd.append("-DSWIG_PY64BIT")
else:
swig_cmd.append("-DSWIG_PY32BIT")
Expand Down Expand Up @@ -893,10 +893,10 @@ def swig_sources(self, sources, ext=None):
if source == "com/win32comext/mapi/src/exchange.i":
rebuild = True

log.debug("should swig %s->%s=%s", source, target, rebuild)
logging.debug("should swig %s->%s=%s", source, target, rebuild)
if rebuild:
swig_cmd.extend(["-o", fqtarget, fqsource])
log.info("swigging %s to %s", source, target)
logging.info("swigging %s to %s", source, target)
out_dir = os.path.dirname(source)
cwd = os.getcwd()
os.chdir(out_dir)
Expand All @@ -905,7 +905,7 @@ def swig_sources(self, sources, ext=None):
finally:
os.chdir(cwd)
else:
log.info("skipping swig of %s", source)
logging.info("skipping swig of %s", source)

return new_sources

Expand Down Expand Up @@ -2170,7 +2170,7 @@ def convert_optional_data_files(files):
except RuntimeError as details:
if not str(details.args[0]).startswith("No file"):
raise
log.info("NOTE: Optional file %s not found - skipping" % file)
logging.info("NOTE: Optional file %s not found - skipping" % file)
else:
ret.append(temp[0])
return ret
Expand Down Expand Up @@ -2248,24 +2248,24 @@ def convert_optional_data_files(files):
"Programming Language :: Python :: Implementation :: CPython",
]

# 3.10 stopped supporting bdist_wininst, but we can still build them with 3.9.
# This can be kept until Python 3.9 or exe installers support is dropped.
if "bdist_wininst" in sys.argv:
# fixup https://github.com/pypa/setuptools/issues/3284
def maybe_fixup_exes():
import distutils.command.bdist_wininst
from distutils.command import bdist_wininst
import site

# setuptools can't find .exe stubs in `site-packages/setuptools/_distutils`
# but they might exist in the original `lib/distutils`.
expected_dir = os.path.dirname(distutils.command.bdist_wininst.__file__)
expected_dir = os.path.dirname(bdist_wininst.__file__)
if not len(glob.glob(f"{expected_dir}/*.exe")):
# might die, see if we can not!
for maybe in site.getsitepackages():
maybe_dir = os.path.abspath(f"{maybe}/../distutils/command")
if len(glob.glob(f"{maybe_dir}/*.exe")):
print(f"pointing setuptools at '{maybe_dir}'")
distutils.command.bdist_wininst.__file__ = os.path.join(
maybe_dir, "bdist_wininst.py"
)
bdist_wininst.__file__ = os.path.join(maybe_dir, "bdist_wininst.py")
break
else:
print("can't fixup distutils/setuptools exe stub location, good luck!")
Expand Down
2 changes: 1 addition & 1 deletion win32/Demos/c_extension/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Use 'python setup.py build' to build this extension.
import os
from distutils.core import Extension, setup
from setuptools import Extension, setup
from sysconfig import get_paths

sources = ["win32_extension.cpp"]
Expand Down

0 comments on commit 4c10d3a

Please sign in to comment.