CMS 3D CMS Logo

Classes | Functions
TreeCrawler Namespace Reference

Classes

class  Color
 
class  mymf
 
class  Package
 
class  SearchHit
 

Functions

def getDependenciesFromPythonFile (filename, toplevelname, path)
 
def getImportTree (filename, path)
 
def packageNameFromFilename (name)
 
def removeRecursiveLoops (node, verbose=False, currentStack=None)
 
def transformIntoGraph (depgraph, toplevel)
 

Function Documentation

def TreeCrawler.getDependenciesFromPythonFile (   filename,
  toplevelname,
  path 
)

Definition at line 288 of file TreeCrawler.py.

Referenced by getImportTree().

288 def getDependenciesFromPythonFile(filename,toplevelname,path):
289  modulefinder = mymf(path)
290  modulefinder.run_script(filename)
291  globalDependencyDict = modulefinder._depgraph
292  globalDependencyDict[toplevelname] = globalDependencyDict["__main__"]
293  return globalDependencyDict
294 
295 
def getDependenciesFromPythonFile(filename, toplevelname, path)
Definition: TreeCrawler.py:288
def TreeCrawler.getImportTree (   filename,
  path 
)

Definition at line 296 of file TreeCrawler.py.

References getDependenciesFromPythonFile(), packageNameFromFilename(), and transformIntoGraph().

296 def getImportTree(filename,path):
297  toplevelname = packageNameFromFilename(filename)
298  # get dependencies from given file
299  globalDependencyDict = getDependenciesFromPythonFile(filename,toplevelname,path)
300 
301  # transform this flat structure in a dependency tree
302  dependencyGraph = transformIntoGraph(globalDependencyDict,toplevelname)
303  return dependencyGraph
304 
def getDependenciesFromPythonFile(filename, toplevelname, path)
Definition: TreeCrawler.py:288
def getImportTree(filename, path)
Definition: TreeCrawler.py:296
def packageNameFromFilename(name)
Definition: TreeCrawler.py:32
def transformIntoGraph(depgraph, toplevel)
Definition: TreeCrawler.py:266
def TreeCrawler.packageNameFromFilename (   name)

Definition at line 32 of file TreeCrawler.py.

References join(), python.rootplot.root2matplotlib.replace(), and split.

Referenced by getImportTree(), and TreeCrawler.Package.search().

33  return ".".join(name.replace("python/","").replace(".py","").split("/")[-3:])
34 
35 
def replace(string, replacements)
def packageNameFromFilename(name)
Definition: TreeCrawler.py:32
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139
def TreeCrawler.removeRecursiveLoops (   node,
  verbose = False,
  currentStack = None 
)

Definition at line 250 of file TreeCrawler.py.

References edm.print().

Referenced by transformIntoGraph().

250 def removeRecursiveLoops( node, verbose=False, currentStack=None ) :
251  if currentStack is None : currentStack=[]
252  try :
253  duplicateIndex=currentStack.index( node ) # If there isn't a recursive loop this will raise a ValueError
254  if verbose :
255  print("Removing recursive loop in:")
256  for index in range(duplicateIndex,len(currentStack)) :
257  print(" ",currentStack[index].name,"-->")
258  print(" ",node.name)
259  currentStack[-1].dependencies.remove(node)
260  except ValueError:
261  # No recursive loop found, so continue traversing the tree
262  currentStack.append( node )
263  for subnode in node.dependencies :
264  removeRecursiveLoops( subnode, verbose, currentStack[:] )
265 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def removeRecursiveLoops(node, verbose=False, currentStack=None)
Definition: TreeCrawler.py:250
def TreeCrawler.transformIntoGraph (   depgraph,
  toplevel 
)

Definition at line 266 of file TreeCrawler.py.

References removeRecursiveLoops().

Referenced by getImportTree().

266 def transformIntoGraph(depgraph,toplevel):
267  packageDict = {}
268  # create the top level config
269  packageDict[toplevel] = Package(toplevel, top = True)
270 
271  # create package objects
272  for key, value in six.iteritems(depgraph):
273  if key.count(".") == 2 and key != toplevel:
274  packageDict[key] = Package(key)
275  for name in value.keys():
276  if name.count(".") == 2: packageDict[name] = Package(name)
277  # now create dependencies
278  for key, value in six.iteritems(depgraph):
279  if key.count(".") == 2 or key == toplevel:
280  package = packageDict[key]
281  package.dependencies = [packageDict[name] for name in value.keys() if name.count(".") == 2]
282 
283  removeRecursiveLoops( packageDict[toplevel] )
284  # find and return the top level config
285  return packageDict[toplevel]
286 
287 
def removeRecursiveLoops(node, verbose=False, currentStack=None)
Definition: TreeCrawler.py:250
def transformIntoGraph(depgraph, toplevel)
Definition: TreeCrawler.py:266