CMS 3D CMS Logo

Classes | Functions | Variables
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)
 

Variables

 _stack
 

Function Documentation

◆ getDependenciesFromPythonFile()

def TreeCrawler.getDependenciesFromPythonFile (   filename,
  toplevelname,
  path 
)

Definition at line 288 of file TreeCrawler.py.

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 

Referenced by getImportTree().

◆ getImportTree()

def TreeCrawler.getImportTree (   filename,
  path 
)

Definition at line 296 of file TreeCrawler.py.

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

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

◆ packageNameFromFilename()

def TreeCrawler.packageNameFromFilename (   name)

Definition at line 32 of file TreeCrawler.py.

32 def packageNameFromFilename(name):
33  return ".".join(name.replace("python/","").replace(".py","").split("/")[-3:])
34 
35 

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

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

◆ removeRecursiveLoops()

def TreeCrawler.removeRecursiveLoops (   node,
  verbose = False,
  currentStack = None 
)

Definition at line 250 of file TreeCrawler.py.

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 

References print(), and FastTimerService_cff.range.

Referenced by transformIntoGraph().

◆ transformIntoGraph()

def TreeCrawler.transformIntoGraph (   depgraph,
  toplevel 
)

Definition at line 266 of file TreeCrawler.py.

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 

References removeRecursiveLoops().

Referenced by getImportTree().

Variable Documentation

◆ _stack

TreeCrawler._stack
private

Definition at line 48 of file TreeCrawler.py.

FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
TreeCrawler.getImportTree
def getImportTree(filename, path)
Definition: TreeCrawler.py:296
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
TreeCrawler.transformIntoGraph
def transformIntoGraph(depgraph, toplevel)
Definition: TreeCrawler.py:266
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
TreeCrawler.packageNameFromFilename
def packageNameFromFilename(name)
Definition: TreeCrawler.py:32
TreeCrawler.removeRecursiveLoops
def removeRecursiveLoops(node, verbose=False, currentStack=None)
Definition: TreeCrawler.py:250
TreeCrawler.getDependenciesFromPythonFile
def getDependenciesFromPythonFile(filename, toplevelname, path)
Definition: TreeCrawler.py:288
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444