Sfoglia il codice sorgente

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 <[email protected]>
Mitchell Stokes 2 anni fa
parent
commit
521cad206d

+ 1 - 1
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 = (

+ 32 - 0
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)

+ 1 - 1
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)

+ 2 - 1
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

+ 13 - 14
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),
     }
 
 

+ 2 - 2
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():