Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-implement newer and newer_group to avoid deprecated distutils.util #2141

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 14 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,20 @@
import win32com
import winerror
from pythoncom import _GetGatewayCount, _GetInterfaceCount
from pywin32_testutil import LeakTestCase, TestLoader, TestResult, TestRunner
from pywin32_testutil import (
LeakTestCase,
TestLoader as TestLoader,
TestRunner as TestRunner,
)


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