Browse Source

CMake: Move pandac compatibility-shim generation to a more sensible place.

Sam Edwards 10 years ago
parent
commit
7f9e25fb84
4 changed files with 30 additions and 48 deletions
  1. 30 0
      CMakeLists.txt
  2. 0 3
      direct/CMakeLists.txt
  3. 0 15
      direct/src/pandac/CMakeLists.txt
  4. 0 30
      direct/src/pandac/__init__.py

+ 30 - 0
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()

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

+ 0 - 15
direct/src/pandac/CMakeLists.txt

@@ -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()

+ 0 - 30
direct/src/pandac/__init__.py

@@ -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