From 530b5f00931109d265320ca644dbac24899c5373 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Sat, 9 Dec 2023 18:29:14 -0500 Subject: [PATCH] ENH: Remove python 2.7 support from ctk_compile_file helper function --- CMake/ctk_compile_python_scripts.cmake.in | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/CMake/ctk_compile_python_scripts.cmake.in b/CMake/ctk_compile_python_scripts.cmake.in index 7833a4d802..8717df2fbe 100644 --- a/CMake/ctk_compile_python_scripts.cmake.in +++ b/CMake/ctk_compile_python_scripts.cmake.in @@ -15,17 +15,12 @@ from __future__ import print_function # https://github.com/jonashaag/cpython/blob/ce5e5df0c9d8098da05dee26e12ffe2aa331889e/Lib/compileall.py#L61-111 # +import importlib import os import sys import py_compile import struct -magic = None -if sys.version_info.major>= 3: - import importlib - magic = importlib.util.MAGIC_NUMBER -else: - import imp - magic = imp.get_magic() + def ctk_compile_file(fullname, ddir=None, force=0, rx=None, quiet=0): \"\"\"Byte-compile one file. @@ -54,7 +49,7 @@ def ctk_compile_file(fullname, ddir=None, force=0, rx=None, quiet=0): if not force: try: mtime = int(os.stat(fullname).st_mtime) - expect = struct.pack('<4sl', magic, mtime) + expect = struct.pack('<4sl', importlib.util.MAGIC_NUMBER, mtime) cfile = fullname + (__debug__ and 'c' or 'o') with open(cfile, 'rb') as chandle: actual = chandle.read(8)