diff --git a/CMakeLists.txt b/CMakeLists.txt index d1755b6919..b7d551edb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,3 +49,33 @@ endif() if(BUILD_PANDATOOL) add_subdirectory(pandatool) endif() + +# This bit is to generate the 'pandac' compatibility shim. It's deprecated now, +# but in older versions of Panda3D, one would use +# from pandac.PandaModules import * +# instead of +# from panda3d.FOO import * +if(HAVE_PYTHON) + # Generate PandaModules: + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/pandac/PandaModules.py" + "\"This module is deprecated. Import from panda3d.core and other panda3d.* modules instead.\" + +print(\"Warning: pandac.PandaModules is deprecated, import from panda3d.core instead\")\n") + + foreach(module ${ALL_INTERROGATE_MODULES}) + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/PandaModules.py" " +try: + from panda3d.${module} import * +except ImportError as err: + if \"No module named %s\" not in str(err): + raise +") + endforeach() + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/pandac/__init__.py" "") + + # Now install ourselves: + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/pandac/__init__.py" "${CMAKE_CURRENT_BINARY_DIR}/pandac/PandaModules.py" + DESTINATION "${PYTHON_LIB_INSTALL_DIR}/pandac") +endif() diff --git a/direct/CMakeLists.txt b/direct/CMakeLists.txt index f3debd7d08..7d89af1a93 100644 --- a/direct/CMakeLists.txt +++ b/direct/CMakeLists.txt @@ -40,6 +40,3 @@ if(HAVE_PYTHON) FILES "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" DESTINATION "${PYTHON_LIB_INSTALL_DIR}/direct") endif() - -# pandac has its own installation steps necessary: -add_subdirectory(src/pandac) diff --git a/direct/src/pandac/CMakeLists.txt b/direct/src/pandac/CMakeLists.txt deleted file mode 100644 index 62969e7acf..0000000000 --- a/direct/src/pandac/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -if(HAVE_PYTHON) - # Generate PandaModules: - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/PandaModules.py" - "# Generated by CMake; edits not preserved\n") - foreach(module ${ALL_INTERROGATE_MODULES}) - file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/PandaModules.py" - "from panda3d.${module} import *\n") - endforeach() - - # Now install ourselves: - file(GLOB python_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.py") - install( - FILES ${python_sources} "${CMAKE_CURRENT_BINARY_DIR}/PandaModules.py" - DESTINATION "${PYTHON_LIB_INSTALL_DIR}/pandac") -endif() diff --git a/direct/src/pandac/__init__.py b/direct/src/pandac/__init__.py deleted file mode 100644 index cfbd9209a4..0000000000 --- a/direct/src/pandac/__init__.py +++ /dev/null @@ -1,30 +0,0 @@ -# N.B. PandaModules is generated at build time by CMake -from PandaModules import * -import __builtin__ - -# Now import all extensions: -from direct.extensions_native.extension_native_helpers import * -extensions = [ - 'CInterval', 'HTTPChannel', 'Mat3', 'NodePath', 'VBase3', 'VBase4' -] - -# Prior to importing, we need to make the Dtool_funcToMethod function and -# the extended class available globally. This is hacky, but tacking it on -# __builtin__ works just fine: -import __builtin__ -__builtin__.Dtool_funcToMethod = Dtool_funcToMethod -__builtin__.Dtool_ObjectToDict = Dtool_ObjectToDict - -for extension in extensions: - if extension not in locals(): - # Not a class we have compiled in, skip it! - continue - - module = 'direct.extensions_native.%s_extensions' % extension - - setattr(__builtin__, extension, locals()[extension]) - __import__(module) - del __builtin__.__dict__[extension] - -del __builtin__.Dtool_funcToMethod -del __builtin__.Dtool_ObjectToDict