Skip to content

Commit

Permalink
Merge branch 'release/1.10.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
rdb committed Oct 13, 2023
2 parents c45e14a + bf456ba commit e01cb59
Show file tree
Hide file tree
Showing 21 changed files with 291 additions and 106 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -355,6 +355,23 @@ jobs:
rmdir panda3d-1.10.14
(cd thirdparty/darwin-libs-a && rm -rf rocket)
- name: Set up Python 3.12
if: matrix.os != 'windows-2019'
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Build Python 3.12
if: matrix.os != 'windows-2019'
shell: bash
run: |
python makepanda/makepanda.py --git-commit=${{github.sha}} --outputdir=built --everything --no-eigen --python-incdir="$pythonLocation/include" --python-libdir="$pythonLocation/lib" --verbose --threads=4 --windows-sdk=10
- name: Test Python 3.12
if: matrix.os != 'windows-2019'
shell: bash
run: |
python -m pip install -r requirements-test.txt
PYTHONPATH=built LD_LIBRARY_PATH=built/lib DYLD_LIBRARY_PATH=built/lib python -m pytest
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions contrib/src/panda3dtoolsgui/Panda3DToolsGUI.py
Expand Up @@ -2650,11 +2650,11 @@ def CheckModDates(self, item):
for inputFile in inputs:
if (inputFile != ''):
inputFilename = inputFile.split('\\')[-1]
print "Compare: ", inFile, filename, inputFile, inputFilename
print("Compare: ", inFile, filename, inputFile, inputFilename)
if inputFilename == filename:
inputTime = os.path.getmtime(inputFile)
outputTime = os.path.getmtime(inFile)
print "Matched: ", (inputTime > outputTime)
print("Matched: ", (inputTime > outputTime))
inputChanged = (inputTime > outputTime)
break
'''
Expand Down Expand Up @@ -2848,7 +2848,7 @@ def OnBatchItemSelection(self, event):

except ValueError:
return
#print self.batchList
#print(self.batchList)

def OnBatchItemEdit(self, event):
selectedItemId = self.batchTree.GetSelections()
Expand Down
2 changes: 1 addition & 1 deletion contrib/src/panda3dtoolsgui/setup.py
@@ -1,4 +1,4 @@
from distutils.core import setup
from setuptools import setup
import py2exe

setup(console=['Panda3DToolsGUI.py'])
84 changes: 55 additions & 29 deletions direct/src/dist/FreezeTool.py
Expand Up @@ -5,14 +5,14 @@
import sys
import os
import marshal
import imp
import platform
import struct
import io
import sysconfig
import zipfile
import importlib
import warnings
from importlib import machinery

from . import pefile

Expand All @@ -24,6 +24,16 @@

from panda3d.core import Filename, Multifile, PandaSystem, StringStream

# Old imp constants.
_PY_SOURCE = 1
_PY_COMPILED = 2
_C_EXTENSION = 3
_PKG_DIRECTORY = 5
_C_BUILTIN = 6
_PY_FROZEN = 7

_PKG_NAMESPACE_DIRECTORY = object()

# Check to see if we are running python_d, which implies we have a
# debug build, and we have to build the module with debug options.
# This is only relevant on Windows.
Expand All @@ -37,7 +47,7 @@
# NB. if encodings are removed, be sure to remove them from the shortcut in
# deploy-stub.c.
startupModules = [
'imp', 'encodings', 'encodings.*', 'io', 'marshal', 'importlib.machinery',
'encodings', 'encodings.*', 'io', 'marshal', 'importlib.machinery',
'importlib.util',
]

Expand Down Expand Up @@ -262,10 +272,15 @@ def determineStandardSetup(self):
self.arch = '-arch x86_64'
elif proc in ('arm64', 'aarch64'):
self.arch = '-arch arm64'
self.compileObjExe = "gcc -c %(arch)s -o %(basename)s.o -O2 -I%(pythonIPath)s %(filename)s"
self.compileObjDll = "gcc -fPIC -c %(arch)s -o %(basename)s.o -O2 -I%(pythonIPath)s %(filename)s"
self.linkExe = "gcc %(arch)s -o %(basename)s %(basename)s.o -framework Python"
self.linkDll = "gcc %(arch)s -undefined dynamic_lookup -bundle -o %(basename)s.so %(basename)s.o"
self.compileObjExe = "clang -c %(arch)s -o %(basename)s.o -O2 -I%(pythonIPath)s %(filename)s"
self.compileObjDll = "clang -fPIC -c %(arch)s -o %(basename)s.o -O2 -I%(pythonIPath)s %(filename)s"
self.linkExe = "clang %(arch)s -o %(basename)s %(basename)s.o"
if '/Python.framework/' in self.PythonIPath:
framework_dir = self.PythonIPath.split("/Python.framework/", 1)[0]
if framework_dir != "/System/Library/Frameworks":
self.linkExe += " -F " + framework_dir
self.linkExe += " -framework Python"
self.linkDll = "clang %(arch)s -undefined dynamic_lookup -bundle -o %(basename)s.so %(basename)s.o"

else:
# Unix
Expand Down Expand Up @@ -897,12 +912,11 @@ def __init__(self, previous = None, debugLevel = 0,

# Suffix/extension for Python C extension modules
if self.platform == PandaSystem.getPlatform():
suffixes = imp.get_suffixes()

# Set extension for Python files to binary mode
for i, suffix in enumerate(suffixes):
if suffix[2] == imp.PY_SOURCE:
suffixes[i] = (suffix[0], 'rb', imp.PY_SOURCE)
suffixes = (
[(s, 'rb', _C_EXTENSION) for s in machinery.EXTENSION_SUFFIXES] +
[(s, 'rb', _PY_SOURCE) for s in machinery.SOURCE_SUFFIXES] +
[(s, 'rb', _PY_COMPILED) for s in machinery.BYTECODE_SUFFIXES]
)
else:
suffixes = [('.py', 'rb', 1), ('.pyc', 'rb', 2)]

Expand Down Expand Up @@ -1316,10 +1330,10 @@ def __loadModule(self, mdef):
ext = mdef.filename.getExtension()
if ext == 'pyc' or ext == 'pyo':
fp = open(pathname, 'rb')
stuff = ("", "rb", imp.PY_COMPILED)
stuff = ("", "rb", _PY_COMPILED)
self.mf.load_module(mdef.moduleName, fp, pathname, stuff)
else:
stuff = ("", "rb", imp.PY_SOURCE)
stuff = ("", "rb", _PY_SOURCE)
if mdef.text:
fp = io.StringIO(mdef.text)
else:
Expand Down Expand Up @@ -1415,7 +1429,7 @@ def __replacePaths(self):

def __addPyc(self, multifile, filename, code, compressionLevel):
if code:
data = imp.get_magic() + b'\0\0\0\0\0\0\0\0'
data = importlib.util.MAGIC_NUMBER + b'\0\0\0\0\0\0\0\0'
data += marshal.dumps(code)

stream = StringStream(data)
Expand Down Expand Up @@ -1605,7 +1619,7 @@ def writeCode(self, filename, initCode = ""):
# trouble importing it as a builtin module. Synthesize a frozen
# module that loads it as builtin.
if '.' in moduleName and self.linkExtensionModules:
code = compile('import sys;del sys.modules["%s"];import imp;imp.init_builtin("%s")' % (moduleName, moduleName), moduleName, 'exec', optimize=self.optimize)
code = compile('import sys;del sys.modules["%s"];from importlib._bootstrap import _builtin_from_name;_builtin_from_name("%s")' % (moduleName, moduleName), moduleName, 'exec', optimize=self.optimize)
code = marshal.dumps(code)
mangledName = self.mangleName(moduleName)
moduleDefs.append(self.makeModuleDef(mangledName, code))
Expand Down Expand Up @@ -1887,9 +1901,19 @@ def generateRuntimeFromStub(self, target, stub_file, use_console, fields={},
if '.' in moduleName and not self.platform.startswith('android'):
if self.platform.startswith("macosx") and not use_console:
# We write the Frameworks directory to sys.path[0].
code = 'import sys;del sys.modules["%s"];import sys,os,imp;imp.load_dynamic("%s",os.path.join(sys.path[0], "%s%s"))' % (moduleName, moduleName, moduleName, modext)
direxpr = 'sys.path[0]'
else:
code = 'import sys;del sys.modules["%s"];import sys,os,imp;imp.load_dynamic("%s",os.path.join(os.path.dirname(sys.executable), "%s%s"))' % (moduleName, moduleName, moduleName, modext)
direxpr = 'os.path.dirname(sys.executable)'

code = \
f'import sys;' \
f'del sys.modules["{moduleName}"];' \
f'import sys,os;' \
f'from importlib.machinery import ExtensionFileLoader,ModuleSpec;' \
f'from importlib._bootstrap import _load;' \
f'path=os.path.join({direxpr}, "{moduleName}{modext}");' \
f'_load(ModuleSpec(name="{moduleName}", loader=ExtensionFileLoader("{moduleName}", path), origin=path))'

code = compile(code, moduleName, 'exec', optimize=self.optimize)
code = marshal.dumps(code)
moduleList.append((moduleName, len(pool), len(code)))
Expand Down Expand Up @@ -2400,9 +2424,6 @@ def __writingModule(self, moduleName):
return True


_PKG_NAMESPACE_DIRECTORY = object()


class PandaModuleFinder(modulefinder.ModuleFinder):

def __init__(self, *args, **kw):
Expand All @@ -2415,7 +2436,12 @@ def __init__(self, *args, **kw):

self.builtin_module_names = kw.pop('builtin_module_names', sys.builtin_module_names)

self.suffixes = kw.pop('suffixes', imp.get_suffixes())
self.suffixes = kw.pop('suffixes', (
[(s, 'rb', _C_EXTENSION) for s in machinery.EXTENSION_SUFFIXES] +
[(s, 'r', _PY_SOURCE) for s in machinery.SOURCE_SUFFIXES] +
[(s, 'rb', _PY_COMPILED) for s in machinery.BYTECODE_SUFFIXES]
))

self.optimize = kw.pop('optimize', -1)

modulefinder.ModuleFinder.__init__(self, *args, **kw)
Expand Down Expand Up @@ -2563,7 +2589,7 @@ def load_module(self, fqname, fp, pathname, file_info):

suffix, mode, type = file_info
self.msgin(2, "load_module", fqname, fp and "fp", pathname)
if type == imp.PKG_DIRECTORY:
if type == _PKG_DIRECTORY:
m = self.load_package(fqname, pathname)
self.msgout(2, "load_module ->", m)
return m
Expand All @@ -2574,7 +2600,7 @@ def load_module(self, fqname, fp, pathname, file_info):
m.__path__ = pathname
return m

if type == imp.PY_SOURCE:
if type == _PY_SOURCE:
if fqname in overrideModules:
# This module has a custom override.
code = overrideModules[fqname]
Expand All @@ -2598,7 +2624,7 @@ def load_module(self, fqname, fp, pathname, file_info):

code += b'\n' if isinstance(code, bytes) else '\n'
co = compile(code, pathname, 'exec', optimize=self.optimize)
elif type == imp.PY_COMPILED:
elif type == _PY_COMPILED:
if sys.version_info >= (3, 7):
try:
data = fp.read()
Expand Down Expand Up @@ -2752,11 +2778,11 @@ def find_module(self, name, path=None, parent=None):

# If we have a custom override for this module, we know we have it.
if fullname in overrideModules:
return (None, '', ('.py', 'r', imp.PY_SOURCE))
return (None, '', ('.py', 'r', _PY_SOURCE))

# It's built into the interpreter.
if fullname in self.builtin_module_names:
return (None, None, ('', '', imp.C_BUILTIN))
return (None, None, ('', '', _C_BUILTIN))

# If no search path is given, look for a built-in module.
if path is None:
Expand Down Expand Up @@ -2806,7 +2832,7 @@ def find_module(self, name, path=None, parent=None):
for suffix, mode, _ in self.suffixes:
init = os.path.join(basename, '__init__' + suffix)
if self._open_file(init, mode):
return (None, basename, ('', '', imp.PKG_DIRECTORY))
return (None, basename, ('', '', _PKG_DIRECTORY))

# This may be a namespace package.
if self._dir_exists(basename):
Expand All @@ -2818,7 +2844,7 @@ def find_module(self, name, path=None, parent=None):
# Only if we're not looking on a particular path, though.
if p3extend_frozen and p3extend_frozen.is_frozen_module(name):
# It's a frozen module.
return (None, name, ('', '', imp.PY_FROZEN))
return (None, name, ('', '', _PY_FROZEN))

# If we found folders on the path with this module name without an
# __init__.py file, we should consider this a namespace package.
Expand Down
3 changes: 1 addition & 2 deletions direct/src/dist/commands.py
Expand Up @@ -13,7 +13,6 @@
import shutil
import stat
import struct
import imp
import string
import tempfile

Expand Down Expand Up @@ -1068,7 +1067,7 @@ def create_runtime(platform, appname, mainscript, use_console):
freezer_extras.update(freezer.extras)
freezer_modules.update(freezer.getAllModuleNames())
for suffix in freezer.mf.suffixes:
if suffix[2] == imp.C_EXTENSION:
if suffix[2] == 3: # imp.C_EXTENSION:
ext_suffixes.add(suffix[0])

for appname, scriptname in self.gui_apps.items():
Expand Down
12 changes: 12 additions & 0 deletions dtool/src/interrogatedb/py_compat.h
Expand Up @@ -241,6 +241,18 @@ INLINE PyObject *PyObject_CallMethodOneArg(PyObject *obj, PyObject *name, PyObje
}
#endif

/* Python 3.12 */

#if PY_VERSION_HEX < 0x030C0000
# define PyLong_IsNonNegative(value) (Py_SIZE((value)) >= 0)
#else
INLINE bool PyLong_IsNonNegative(PyObject *value) {
int overflow = 0;
long longval = PyLong_AsLongAndOverflow(value, &overflow);
return overflow == 1 || longval >= 0;
}
#endif

/* Other Python implementations */

#endif // HAVE_PYTHON
Expand Down
4 changes: 1 addition & 3 deletions makepanda/installpanda.py
Expand Up @@ -12,9 +12,7 @@
import sys
from optparse import OptionParser
from makepandacore import *

# DO NOT CHANGE TO sysconfig - see GitHub issue #1230
from distutils.sysconfig import get_python_lib
from locations import get_python_lib


MIME_INFO = (
Expand Down
32 changes: 32 additions & 0 deletions 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)
3 changes: 1 addition & 2 deletions makepanda/makepackage.py
Expand Up @@ -942,8 +942,7 @@ def copy_python_tree(source_root, target_root):
shutil.copy(os.path.join(source_dir, base), target)

# Copy the Python standard library to the .apk as well.
# DO NOT CHANGE TO sysconfig - see #1230
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)
Expand Down
6 changes: 2 additions & 4 deletions makepanda/makepanda.py
Expand Up @@ -30,12 +30,10 @@
print("Please install the development package of Python and try again.")
exit(1)

if sys.version_info >= (3, 10):
from sysconfig import get_platform
else:
from distutils.util import get_platform
from makepandacore import *

from sysconfig import get_platform

try:
import zlib
except:
Expand Down

0 comments on commit e01cb59

Please sign in to comment.