From 9d45c0e19200c7973af55d37a8847dae6504427a Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 1 Nov 2023 17:01:26 -0400 Subject: [PATCH 1/2] Avoid distutils.util --- com/win32com/test/pippo_server.py | 5 ++--- com/win32com/test/util.py | 12 +++++++++-- setup.py | 36 +++++++++++++++++++++++++------ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/com/win32com/test/pippo_server.py b/com/win32com/test/pippo_server.py index 1c2219d8c9..23e203ae2c 100644 --- a/com/win32com/test/pippo_server.py +++ b/com/win32com/test/pippo_server.py @@ -6,10 +6,11 @@ import sys import pythoncom -import win32com import winerror from win32com.server.util import wrap +from .util import newer + class CPippo: # @@ -41,8 +42,6 @@ def Method3(self, in1): def BuildTypelib(): - from distutils.dep_util import newer - this_dir = os.path.dirname(__file__) idl = os.path.abspath(os.path.join(this_dir, "pippo.idl")) tlb = os.path.splitext(idl)[0] + ".tlb" diff --git a/com/win32com/test/util.py b/com/win32com/test/util.py index a809875989..e3af4a0af7 100644 --- a/com/win32com/test/util.py +++ b/com/win32com/test/util.py @@ -1,4 +1,3 @@ -import gc import logging import os import sys @@ -13,7 +12,16 @@ import win32com import winerror from pythoncom import _GetGatewayCount, _GetInterfaceCount -from pywin32_testutil import LeakTestCase, TestLoader, TestResult, TestRunner +from pywin32_testutil import LeakTestCase + + +def newer(source, target): + """Re-implemented from deprecated `distutils.dep_util.newer`""" + if not os.path.exists(target): + return True + mtime1 = os.path.getmtime(source) + mtime2 = os.path.getmtime(target) + return mtime1 > mtime2 def CheckClean(): diff --git a/setup.py b/setup.py index 596fecc14f..7ead47b3a4 100644 --- a/setup.py +++ b/setup.py @@ -31,30 +31,54 @@ import subprocess import sys import winreg +from pathlib import Path +from tempfile import gettempdir +from typing import Iterable, List, Tuple, Union # setuptools must be imported before distutils for markh in some python versions. # CI doesn't hit this, so not sure what's going on. from setuptools import setup from setuptools.command.build_ext import build_ext +import distutils.util 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 -from pathlib import Path -from tempfile import gettempdir -from typing import Iterable, List, Tuple, Union - # 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 +def newer_group(sources, target, missing="error"): + """Re-implemented from deprecated `distutils.dep_util.newer_group`""" + # If the target doesn't even exist, then it's definitely out-of-date. + if not os.path.exists(target): + return True + + # Otherwise we have to find out the hard way: if *any* source file + # is more recent than 'target', then 'target' is out-of-date and + # we can immediately return true. If we fall through to the end + # of the loop, then 'target' is up-to-date and we return false. + target_mtime = os.path.getmtime(target) + for source in sources: + if not os.path.exists(source): + if missing == "error": # blow up when we stat() the file + pass + elif missing == "ignore": # missing source dropped from + continue # target's dependency list + elif missing == "newer": # missing source means target is + return True # out-of-date + + source_mtime = os.path.getmtime(source) + if source_mtime > target_mtime: + return True + else: + return False + build_id_patch = build_id if not "." in build_id_patch: From 43bc6c6ccbe48b07f9e3585311b8bc6f215cdfb2 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 1 Nov 2023 21:12:08 -0400 Subject: [PATCH 2/2] Re-export TestLoader and TestRunner --- com/win32com/test/util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/com/win32com/test/util.py b/com/win32com/test/util.py index e3af4a0af7..d802ec586f 100644 --- a/com/win32com/test/util.py +++ b/com/win32com/test/util.py @@ -12,7 +12,11 @@ import win32com import winerror from pythoncom import _GetGatewayCount, _GetInterfaceCount -from pywin32_testutil import LeakTestCase +from pywin32_testutil import ( + LeakTestCase, + TestLoader as TestLoader, + TestRunner as TestRunner, +) def newer(source, target):