CMS 3D CMS Logo

Classes | Functions | Variables
TreeCrawler Namespace Reference

Classes

class  Color
 
class  mymf
 
class  Package
 
class  SearchHit
 

Functions

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

Variables

 _stack
 

Function Documentation

◆ getDependenciesFromPythonFile()

def TreeCrawler.getDependenciesFromPythonFile (   filename)

Definition at line 287 of file TreeCrawler.py.

Referenced by getImportTree().

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

◆ getImportTree()

def TreeCrawler.getImportTree (   filename)

Definition at line 295 of file TreeCrawler.py.

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

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

◆ packageNameFromFilename()

def TreeCrawler.packageNameFromFilename (   name)

Definition at line 31 of file TreeCrawler.py.

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

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

31 def packageNameFromFilename(name:str) -> str:
32  return ".".join(name.replace("python/","").replace(".py","").split("/")[-3:])
33 
34 
def replace(string, replacements)
def packageNameFromFilename
Definition: TreeCrawler.py:31
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ removeRecursiveLoops()

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

Definition at line 249 of file TreeCrawler.py.

References print(), and FastTimerService_cff.range.

Referenced by transformIntoGraph().

249 def removeRecursiveLoops( node, verbose=False, currentStack=None ) :
250  if currentStack is None : currentStack=[]
251  try :
252  duplicateIndex=currentStack.index( node ) # If there isn't a recursive loop this will raise a ValueError
253  if verbose :
254  print("Removing recursive loop in:")
255  for index in range(duplicateIndex,len(currentStack)) :
256  print(" ",currentStack[index].name,"-->")
257  print(" ",node.name)
258  currentStack[-1].dependencies.remove(node)
259  except ValueError:
260  # No recursive loop found, so continue traversing the tree
261  currentStack.append( node )
262  for subnode in node.dependencies :
263  removeRecursiveLoops( subnode, verbose, currentStack[:] )
264 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def removeRecursiveLoops(node, verbose=False, currentStack=None)
Definition: TreeCrawler.py:249

◆ transformIntoGraph()

def TreeCrawler.transformIntoGraph (   depgraph,
  toplevel 
)

Definition at line 265 of file TreeCrawler.py.

References removeRecursiveLoops().

Referenced by getImportTree().

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

Variable Documentation

◆ _stack

TreeCrawler._stack
private

Definition at line 47 of file TreeCrawler.py.