Skip to content

Commit

Permalink
Avoid distutils.util
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Nov 1, 2023
1 parent 4025d76 commit 9d45c0e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
5 changes: 2 additions & 3 deletions com/win32com/test/pippo_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import sys

import pythoncom
import win32com
import winerror
from win32com.server.util import wrap

from .util import newer


class CPippo:
#
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 10 additions & 2 deletions com/win32com/test/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gc
import logging
import os
import sys
Expand All @@ -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():
Expand Down
36 changes: 30 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9d45c0e

Please sign in to comment.