From 7a681dc99388f2a80ffcd196a922f80c8caa77f2 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 29 May 2016 02:01:57 +0200 Subject: [PATCH] Python 3 fixes for rtdist builds --- direct/src/p3d/panda3d.pdef | 6 ++++-- direct/src/plugin/p3dPythonRun.cxx | 18 ++++++++++++++++++ direct/src/showbase/VFSImporter.py | 6 ++---- direct/src/showutil/FreezeTool.py | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/direct/src/p3d/panda3d.pdef b/direct/src/p3d/panda3d.pdef index 690ee16227..5a993a1ada 100644 --- a/direct/src/p3d/panda3d.pdef +++ b/direct/src/p3d/panda3d.pdef @@ -63,8 +63,10 @@ class panda3d(package): # Include various standard Python encodings. The rest is in morepy. module('encodings', 'encodings.aliases', 'encodings.undefined', - 'encodings.utf_8', 'encodings.ascii', 'encodings.string_escape', - 'encodings.mbcs', 'encodings.latin_1', 'io') + 'encodings.utf_8', 'encodings.ascii', 'encodings.mbcs', + 'encodings.latin_1', 'io') + if sys.version_info < (3, 0): + module('encodings.string_escape') # Pick up the shader files that appear in direct/src/filter. import direct diff --git a/direct/src/plugin/p3dPythonRun.cxx b/direct/src/plugin/p3dPythonRun.cxx index cb7f58fb22..542c47acb8 100644 --- a/direct/src/plugin/p3dPythonRun.cxx +++ b/direct/src/plugin/p3dPythonRun.cxx @@ -217,6 +217,24 @@ run_python() { PyModule_AddStringConstant(showbase_module, "__package__", "direct.showbase"); } + PyObject *stdpy_module = PyImport_AddModule("direct.stdpy"); + if (stdpy_module != NULL) { + Filename stdpy_dir(direct_dir, "stdpy"); + dir_str = stdpy_dir.to_os_specific(); + PyModule_AddObject(stdpy_module, "__path__", Py_BuildValue("[s#]", dir_str.data(), dir_str.length())); + PyModule_AddStringConstant(stdpy_module, "__package__", "direct.stdpy"); + } + + // And the encodings package as well, since we've presumably picked up a + // bunch of encodings modules as part of the frozen bundle. + Filename encodings_dir(dir, "encodings"); + PyObject *encodings_module = PyImport_AddModule("encodings"); + if (encodings_module != NULL) { + dir_str = encodings_dir.to_os_specific(); + PyModule_AddObject(encodings_module, "__path__", Py_BuildValue("[s#]", dir_str.data(), dir_str.length())); + PyModule_AddStringConstant(encodings_module, "__package__", "encodings"); + } + // And register the VFSImporter. PyObject *result = PyObject_CallMethod(vfsimporter_module, (char *)"register", (char *)""); if (result == NULL) { diff --git a/direct/src/showbase/VFSImporter.py b/direct/src/showbase/VFSImporter.py index 807b931ab0..e6849fd503 100644 --- a/direct/src/showbase/VFSImporter.py +++ b/direct/src/showbase/VFSImporter.py @@ -2,6 +2,7 @@ __all__ = ['register', 'sharedPackages', 'reloadSharedPackage', 'reloadSharedPackages'] from panda3d.core import Filename, VirtualFileSystem, VirtualFileMountSystem, OFileStream, copyStream +from direct.stdpy.file import open import sys import marshal import imp @@ -173,10 +174,7 @@ class VFSLoader: filename = Filename(self.filename) filename.setExtension('py') filename.setText() - vfile = vfs.getFile(filename) - if not vfile: - raise IOError("Could not find '%s'" % (filename)) - return vfile.readFile(True) + return open(self.filename, self.desc[1]).read() def _import_extension_module(self, fullname): """ Loads the binary shared object as a Python module, and diff --git a/direct/src/showutil/FreezeTool.py b/direct/src/showutil/FreezeTool.py index 623f7f0e4a..d75a79b56b 100644 --- a/direct/src/showutil/FreezeTool.py +++ b/direct/src/showutil/FreezeTool.py @@ -1190,7 +1190,7 @@ class Freezer: if self.storePythonSource: filename += '.py' - stream = StringStream('') + stream = StringStream(b'') if multifile.findSubfile(filename) < 0: multifile.addSubfile(filename, stream, 0) multifile.flush()