소스 검색

fix packp3d ordering issue http://www.panda3d.org/forums/viewtopic.php?p=65842

David Rose 15 년 전
부모
커밋
2e6d2c5255
1개의 변경된 파일25개의 추가작업 그리고 0개의 파일을 삭제
  1. 25 0
      direct/src/showutil/FreezeTool.py

+ 25 - 0
direct/src/showutil/FreezeTool.py

@@ -844,6 +844,15 @@ class Freezer:
         self.mf = PandaModuleFinder(excludes = excludeDict.keys())
 
         # Attempt to import the explicit modules into the modulefinder.
+
+        # First, ensure the includes are sorted in order so that
+        # packages appear before the modules they contain.  This
+        # resolves potential ordering issues, especially with modules
+        # that are discovered by filename rather than through import
+        # statements.
+        includes.sort(key = self.__sortModuleKey)
+
+        # Now walk through the list and import them all.
         for mdef in includes:
             try:
                 self.__loadModule(mdef)
@@ -894,6 +903,22 @@ class Freezer:
             missing.sort()
             print "There are some missing modules: %r" % missing
 
+    def __sortModuleKey(self, mdef):
+        """ A sort key function to sort a list of mdef's into order,
+        primarily to ensure that packages proceed their modules. """
+
+        if mdef.moduleName:
+            # If we have a moduleName, the key consists of the split
+            # tuple of packages names.  That way, parents always sort
+            # before children.
+            return ('a', mdef.moduleName.split('.'))
+        else:
+            # If we don't have a moduleName, the key doesn't really
+            # matter--we use filename--but we start with 'b' to ensure
+            # that all of non-named modules appear following all of
+            # the named modules.
+            return ('b', mdef.filename)
+
     def __loadModule(self, mdef):
         """ Adds the indicated module to the modulefinder. """