code: def packageGraph(self, packagelevel=None):
          
          packages = {}
          for module in self.listModules():
              package_name = self.packageOf(module.modname, packagelevel)
              if package_name not in packages:
                  dirname = os.path.dirname(module.filename)
                  packages[package_name] = Module(package_name, dirname)
              package = packages[package_name]
              for name in module.imports:
                  package_name = self.packageOf(name, packagelevel)
                  if package_name != package.modname: # no loops
                      package.imports.add(package_name)
          graph = ModuleGraph()
          graph.modules = packages
          return graph
docs: Convert a module graph to a package graph.