From be4ece28ccdff3ce707267dd18dd84cc58d38cbe Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 4 Oct 2024 20:13:05 -0400 Subject: [PATCH] Dropping support for Python 3.7 and cleanup code paths --- .github/workflows/download-arm64-libs.py | 12 ++++++------ .github/workflows/main.yml | 5 ++--- CHANGES.txt | 2 ++ Pythonwin/pywin/test/test_pywin.py | 5 ++--- build_all.bat | 4 ---- build_env.md | 1 - com/win32com/test/pippo_server.py | 5 +---- make_all.bat | 5 ----- mypy.ini | 1 - pyrightconfig.json | 2 +- ruff.toml | 2 +- setup.py | 11 +++-------- win32/Lib/pywin32_bootstrap.py | 10 +--------- win32/src/_win32sysloader.cpp | 6 ------ 14 files changed, 19 insertions(+), 52 deletions(-) diff --git a/.github/workflows/download-arm64-libs.py b/.github/workflows/download-arm64-libs.py index 51c5bcd02..841673f98 100644 --- a/.github/workflows/download-arm64-libs.py +++ b/.github/workflows/download-arm64-libs.py @@ -28,16 +28,16 @@ VERSION += f"-rc{sys.version_info.serial}" URL = f"https://www.nuget.org/api/v2/package/pythonarm64/{VERSION}" -PATH = dest / f"pythonarm64.{VERSION}.zip" +DEST_PATH = dest / f"pythonarm64.{VERSION}.zip" -if PATH.is_file(): - print("Skipping download because", PATH, "exists") +if DEST_PATH.is_file(): + print("Skipping download because", DEST_PATH, "exists") else: print("Downloading", URL) - urlretrieve(URL, PATH) - print("Downloaded", PATH) + urlretrieve(URL, DEST_PATH) + print("Downloaded", DEST_PATH) -with ZipFile(PATH, "r") as zf: +with ZipFile(DEST_PATH, "r") as zf: for name in zf.namelist(): zip_path = pathlib.PurePath(name) if zip_path.parts[:2] == ("tools", "libs"): diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bde655f3b..d282f1f9b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13-dev"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13-dev"] architecture: ["x64", "x86"] steps: @@ -129,7 +129,6 @@ jobs: strategy: fail-fast: false matrix: - # mypy 1.5 dropped support for Python 3.7 # mypy won't understand "3.13-dev", keeping the CI simple by just omitting it python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: @@ -148,7 +147,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13-dev"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13-dev"] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/CHANGES.txt b/CHANGES.txt index fd800ca29..36e0ad5ce 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,8 @@ https://mhammond.github.io/pywin32_installers.html. Coming in build 308, as yet unreleased -------------------------------------- +* Dropped support for Python 3.7 (#2207, @Avasam) + Build 307, released 2024-10-04 ------------------------------ ### Release process changes diff --git a/Pythonwin/pywin/test/test_pywin.py b/Pythonwin/pywin/test/test_pywin.py index b38d87ec0..df59ef570 100644 --- a/Pythonwin/pywin/test/test_pywin.py +++ b/Pythonwin/pywin/test/test_pywin.py @@ -47,8 +47,7 @@ def setUpClass(cls): def _restore_oe(): sys.stdout, sys.stderr = cls.std_oe_orig - if sys.version_info >= (3, 8): - cls.addClassCleanup(_restore_oe) + cls.addClassCleanup(_restore_oe) sys.argv[1:] = ["/new", src_dir + "\\_dbgscript.py"] if not _indebugger: thisApp.InitInstance() @@ -65,7 +64,7 @@ def tearDownClass(cls): win32api.PostQuitMessage() win32gui.PumpWaitingMessages() cls.app.ExitInstance() - sys.stdout, sys.stderr = cls.std_oe_orig # py3.7 + sys.stdout, sys.stderr = cls.std_oe_orig def test_1_pydocs_and_finddlg(self): mf = win32ui.GetMainFrame() diff --git a/build_all.bat b/build_all.bat index 536aee00d..ec8cbbaa2 100644 --- a/build_all.bat +++ b/build_all.bat @@ -1,7 +1,3 @@ -py -3.7-32 setup.py -q build -@if errorlevel 1 goto failed -py -3.7 setup.py -q build -@if errorlevel 1 goto failed py -3.8-32 setup.py -q build @if errorlevel 1 goto failed py -3.8 setup.py -q build diff --git a/build_env.md b/build_env.md index d9c55ac10..4f616bf99 100644 --- a/build_env.md +++ b/build_env.md @@ -149,7 +149,6 @@ from the pywin32 directory. - Update `setuptools` and set the following environment variables to ensure it is used: ```shell - set SETUPTOOLS_USE_DISTUTILS=1 set DISTUTILS_USE_SDK=1 ``` diff --git a/com/win32com/test/pippo_server.py b/com/win32com/test/pippo_server.py index c5ae2df40..d8e964623 100644 --- a/com/win32com/test/pippo_server.py +++ b/com/win32com/test/pippo_server.py @@ -41,10 +41,7 @@ def Method3(self, in1): def BuildTypelib(): - if sys.version_info >= (3, 8): - from setuptools.modified import newer - else: - from distutils.dep_util import newer + from setuptools.modified import newer this_dir = os.path.dirname(__file__) idl = os.path.abspath(os.path.join(this_dir, "pippo.idl")) diff --git a/make_all.bat b/make_all.bat index c6d6a2b33..05855ddfb 100644 --- a/make_all.bat +++ b/make_all.bat @@ -13,11 +13,6 @@ rem Now the binaries. rem Check /build_env.md#build-environment to make sure you have all the required components installed rem (bdist_wininst needs --target-version to name the installers correctly!) -py -3.7-32 setup.py -q bdist_wininst --skip-build --target-version=3.7 -py -3.7-32 setup.py -q bdist_wheel --skip-build -py -3.7 setup.py -q bdist_wininst --skip-build --target-version=3.7 -py -3.7 setup.py -q bdist_wheel --skip-build - py -3.8-32 setup.py -q bdist_wininst --skip-build --target-version=3.8 py -3.8-32 setup.py -q bdist_wheel --skip-build py -3.8 setup.py -q bdist_wininst --skip-build --target-version=3.8 diff --git a/mypy.ini b/mypy.ini index a93198a2f..8eb8485ca 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,7 +1,6 @@ [mypy] show_column_numbers = true ; Target the oldest supported version in editors and default CLI -; mypy 1.5 dropped support for Python 3.7 python_version = 3.8 strict = true diff --git a/pyrightconfig.json b/pyrightconfig.json index bc3c26fbc..a9aabfbee 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -1,7 +1,7 @@ { "typeCheckingMode": "basic", // Target the oldest supported version in editors and default CLI - "pythonVersion": "3.7", + "pythonVersion": "3.8", // Keep it simple for now by allowing both mypy and pyright to use `type: ignore` "enableTypeIgnoreComments": true, // Exclude from scanning when running pyright diff --git a/ruff.toml b/ruff.toml index cd23d7822..0765b6f59 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,4 +1,4 @@ -target-version = "py37" # Target the oldest supported version +target-version = "py38" # Target the oldest supported version in editors and default CLI [lint] select = [ diff --git a/setup.py b/setup.py index 37d536a68..85488b5a5 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ from setuptools.command.build_ext import build_ext from setuptools.command.install import install from setuptools.command.install_lib import install_lib +from setuptools.modified import newer_group from tempfile import gettempdir from typing import Iterable @@ -47,11 +48,6 @@ from distutils._msvccompiler import MSVCCompiler from distutils.command.install_data import install_data -if sys.version_info >= (3, 8): - from setuptools.modified import newer_group -else: - from distutils.dep_util import newer_group - build_id_patch = build_id if not "." in build_id_patch: build_id_patch += ".0" @@ -922,8 +918,8 @@ def install(self): # This is crazy - in setuptools 61.1.0 (and probably some earlier versions), the # install_lib and build comments don't agree on where the .py files to install can # be found, so we end up with a warning logged: - # `warning: my_install_lib: 'build\lib.win-amd64-3.7' does not exist -- no Python modules to install` - # (because they are actually in `build\lib.win-amd64-cpython-37`!) + # `warning: my_install_lib: 'build\lib.win-amd64-3.8' does not exist -- no Python modules to install` + # (because they are actually in `build\lib.win-amd64-cpython-38`!) # It's not an error though, so we end up with .exe installers lacking our lib files! builder = self.get_finalized_command("build") if os.path.isdir(builder.build_platlib) and not os.path.isdir(self.build_dir): @@ -2201,7 +2197,6 @@ def convert_optional_data_files(files): "Intended Audience :: Developers", "License :: OSI Approved :: Python Software Foundation License", "Operating System :: Microsoft :: Windows", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", diff --git a/win32/Lib/pywin32_bootstrap.py b/win32/Lib/pywin32_bootstrap.py index fbc4f7be4..c9f59a56d 100644 --- a/win32/Lib/pywin32_bootstrap.py +++ b/win32/Lib/pywin32_bootstrap.py @@ -4,8 +4,6 @@ # In short, there's a directory installed by pywin32 named 'pywin32_system32' # with some important DLLs which need to be found by Python when some pywin32 # modules are imported. -# If Python has `os.add_dll_directory()`, we need to call it with this path. -# Otherwise, we add this path to PATH. try: @@ -19,11 +17,5 @@ # https://docs.python.org/3/reference/import.html#__path__ for path in pywin32_system32.__path__: if os.path.isdir(path): - if hasattr(os, "add_dll_directory"): - os.add_dll_directory(path) - # This is to ensure the pywin32 path is in the beginning to find the - # pywin32 DLLs first and prevent other PATH entries to shadow them - elif not os.environ["PATH"].startswith(path): - os.environ["PATH"] = os.environ["PATH"].replace(os.pathsep + path, "") - os.environ["PATH"] = path + os.pathsep + os.environ["PATH"] + os.add_dll_directory(path) break diff --git a/win32/src/_win32sysloader.cpp b/win32/src/_win32sysloader.cpp index 0a9e4dcac..9a9ef7c27 100644 --- a/win32/src/_win32sysloader.cpp +++ b/win32/src/_win32sysloader.cpp @@ -52,13 +52,7 @@ static PyObject *PyLoadModule(PyObject *self, PyObject *args) if (!modName) return NULL; - // Python 3.7 vs 3.8 use different flags for LoadLibraryEx and we match them. - // See github issue 1787. -#if (PY_VERSION_HEX < 0x03080000) - HINSTANCE hinst = LoadLibraryEx(modName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); -#else HINSTANCE hinst = LoadLibraryEx(modName, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); -#endif PyMem_Free(modName); if (hinst == NULL) { Py_INCREF(Py_None);