From 521cad206d980026509c671bc6ad42058b92c06b Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Wed, 11 Oct 2023 19:39:01 -0700 Subject: [PATCH] makepanda: Stop using deprecated distutils (#1549) Just duplicating locations.py from direct. It's a bit ugly, but makepanda is getting phased out anyways. Co-authored-by: rdb --- makepanda/installpanda.py | 2 +- makepanda/locations.py | 32 ++++++++++++++++++++++++++++++++ makepanda/makepackage.py | 2 +- makepanda/makepanda.py | 3 ++- makepanda/makepandacore.py | 27 +++++++++++++-------------- makepanda/makewheel.py | 4 ++-- 6 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 makepanda/locations.py diff --git a/makepanda/installpanda.py b/makepanda/installpanda.py index d0111e0049..89e32c765e 100644 --- a/makepanda/installpanda.py +++ b/makepanda/installpanda.py @@ -9,9 +9,9 @@ ######################################################################## import os, sys, platform -from distutils.sysconfig import get_python_lib from optparse import OptionParser from makepandacore import * +from locations import get_python_lib MIME_INFO = ( diff --git a/makepanda/locations.py b/makepanda/locations.py new file mode 100644 index 0000000000..d410b77aff --- /dev/null +++ b/makepanda/locations.py @@ -0,0 +1,32 @@ +__all__ = [ + 'get_python_inc', + 'get_config_var', + 'get_python_version', + 'PREFIX', + 'get_python_lib', + 'get_config_vars', +] + +import sys + +if sys.version_info < (3, 12): + from distutils.sysconfig import * +else: + from sysconfig import * + + PREFIX = get_config_var('prefix') + + def get_python_inc(plat_specific=False): + path_name = 'platinclude' if plat_specific else 'include' + return get_path(path_name) + + def get_python_lib(plat_specific=False, standard_lib=False): + if standard_lib: + path_name = 'stdlib' + if plat_specific: + path_name = 'plat' + path_name + elif plat_specific: + path_name = 'platlib' + else: + path_name = 'purelib' + return get_path(path_name) diff --git a/makepanda/makepackage.py b/makepanda/makepackage.py index f57fc873e3..68c74523dc 100755 --- a/makepanda/makepackage.py +++ b/makepanda/makepackage.py @@ -1032,7 +1032,7 @@ def MakeInstallerAndroid(version, **kwargs): shutil.copy(os.path.join(source_dir, base), target) # Copy the Python standard library to the .apk as well. - from distutils.sysconfig import get_python_lib + from locations import get_python_lib stdlib_source = get_python_lib(False, True) stdlib_target = os.path.join("apkroot", "lib", "python{0}.{1}".format(*sys.version_info)) copy_python_tree(stdlib_source, stdlib_target) diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 407c95bb33..d88a1cb153 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -23,11 +23,12 @@ except: exit(1) from makepandacore import * -from distutils.util import get_platform import time import os import sys +from sysconfig import get_platform + ######################################################################## ## ## PARSING THE COMMAND LINE OPTIONS diff --git a/makepanda/makepandacore.py b/makepanda/makepandacore.py index ad75ae6f1d..111a3a6717 100644 --- a/makepanda/makepandacore.py +++ b/makepanda/makepandacore.py @@ -7,7 +7,7 @@ import sys,os,time,stat,string,re,getopt,fnmatch,threading,signal,shutil,platform,glob,getpass,signal import subprocess -from distutils import sysconfig +import locations if sys.version_info >= (3, 0): import pickle @@ -2250,7 +2250,7 @@ def SdkLocatePython(prefer_thirdparty_python=False): # On macOS, search for the Python framework directory matching the # version number of our current Python version. sysroot = SDK.get("MACOSX", "") - version = sysconfig.get_python_version() + version = locations.get_python_version() py_fwx = "{0}/System/Library/Frameworks/Python.framework/Versions/{1}".format(sysroot, version) @@ -2275,19 +2275,19 @@ def SdkLocatePython(prefer_thirdparty_python=False): LibDirectory("PYTHON", py_fwx + "/lib") #elif GetTarget() == 'windows': - # SDK["PYTHON"] = os.path.dirname(sysconfig.get_python_inc()) - # SDK["PYTHONVERSION"] = "python" + sysconfig.get_python_version() + # SDK["PYTHON"] = os.path.dirname(locations.get_python_inc()) + # SDK["PYTHONVERSION"] = "python" + locations.get_python_version() # SDK["PYTHONEXEC"] = sys.executable else: - SDK["PYTHON"] = sysconfig.get_python_inc() - SDK["PYTHONVERSION"] = "python" + sysconfig.get_python_version() + abiflags + SDK["PYTHON"] = locations.get_python_inc() + SDK["PYTHONVERSION"] = "python" + locations.get_python_version() + abiflags SDK["PYTHONEXEC"] = os.path.realpath(sys.executable) if CrossCompiling(): # We need a version of Python we can run. SDK["PYTHONEXEC"] = sys.executable - host_version = "python" + sysconfig.get_python_version() + abiflags + host_version = "python" + locations.get_python_version() + abiflags if SDK["PYTHONVERSION"] != host_version: exit("Host Python version (%s) must be the same as target Python version (%s)!" % (host_version, SDK["PYTHONVERSION"])) @@ -3514,7 +3514,7 @@ def GetExtensionSuffix(): return '.so' def GetPythonABI(): - soabi = sysconfig.get_config_var('SOABI') + soabi = locations.get_config_var('SOABI') if soabi: return soabi @@ -3523,16 +3523,16 @@ def GetPythonABI(): if sys.version_info >= (3, 8): return soabi - debug_flag = sysconfig.get_config_var('Py_DEBUG') + debug_flag = locations.get_config_var('Py_DEBUG') if (debug_flag is None and hasattr(sys, 'gettotalrefcount')) or debug_flag: soabi += 'd' - malloc_flag = sysconfig.get_config_var('WITH_PYMALLOC') + malloc_flag = locations.get_config_var('WITH_PYMALLOC') if malloc_flag is None or malloc_flag: soabi += 'm' if sys.version_info < (3, 3): - usize = sysconfig.get_config_var('Py_UNICODE_SIZE') + usize = locations.get_config_var('Py_UNICODE_SIZE') if (usize is None and sys.maxunicode == 0x10ffff) or usize == 4: soabi += 'u' @@ -3648,14 +3648,13 @@ def GetCurrentPythonVersionInfo(): if PkgSkip("PYTHON"): return - from distutils.sysconfig import get_python_lib return { "version": SDK["PYTHONVERSION"][6:].rstrip('dmu'), "soabi": GetPythonABI(), "ext_suffix": GetExtensionSuffix(), "executable": sys.executable, - "purelib": get_python_lib(False), - "platlib": get_python_lib(True), + "purelib": locations.get_python_lib(False), + "platlib": locations.get_python_lib(True), } diff --git a/makepanda/makewheel.py b/makepanda/makewheel.py index 2f18789e78..55a48f62cf 100644 --- a/makepanda/makewheel.py +++ b/makepanda/makewheel.py @@ -2,7 +2,6 @@ Generates a wheel (.whl) file from the output of makepanda. """ from __future__ import print_function, unicode_literals -from distutils.util import get_platform import json import sys @@ -13,10 +12,11 @@ import zipfile import hashlib import tempfile import subprocess -from distutils.sysconfig import get_config_var from optparse import OptionParser from makepandacore import ColorText, LocateBinary, GetExtensionSuffix, SetVerbose, GetVerbose, GetMetadataValue from base64 import urlsafe_b64encode +from locations import get_config_var +from sysconfig import get_platform def get_abi_tag():