ATLAS Offline Software
Classes | Functions
apydep Namespace Reference

Classes

class  DependencyFinder
 

Functions

def get_dependencies (filename, print_error=False)
 
def walk_tree (path='./', print_error=False, filterFnc=None)
 
def make_graph (deps, filterFnc=None)
 
def main ()
 

Function Documentation

◆ get_dependencies()

def apydep.get_dependencies (   filename,
  print_error = False 
)
Get all the imports/includes in a file.

Definition at line 41 of file apydep.py.

41 def get_dependencies(filename, print_error=False):
42  """Get all the imports/includes in a file."""
43 
44  try:
45  tree = ast.parse(open(filename,'rb').read(), filename=filename)
46  except Exception as e:
47  if print_error:
48  print(e, file=sys.stderr)
49  return DependencyFinder()
50 
51  finder = DependencyFinder()
52  try:
53  finder.visit(tree)
54  except Exception as e:
55  if print_error:
56  print(e, f'({os.path.basename(filename)})', file=sys.stderr)
57 
58  return finder
59 
60 

◆ main()

def apydep.main ( )

Definition at line 93 of file apydep.py.

93 def main():
94  parser = argparse.ArgumentParser(description=__doc__)
95 
96  parser.add_argument('path', metavar='DIRECTORY', nargs='?', default='./',
97  help='root of source tree [%(default)s]')
98 
99  parser.add_argument('-o', '--output', metavar='FILE', type=str,
100  help='output file for DOT graph')
101 
102  parser.add_argument('-p', '--packages', metavar='FILE', type=str,
103  help='path to packages.txt file [from release]')
104 
105  parser.add_argument('-a', '--all', action='store_true',
106  help='include non-athena dependencies')
107 
108  parser.add_argument('-v', '--verbose', action='store_true',
109  help='print parse errors')
110 
111  args = parser.parse_args()
112 
113  packages = None
114  if not args.all:
115  package_file = args.packages or os.path.join(os.environ['AtlasArea'],'InstallArea',
116  os.environ['BINARY_TAG'],'packages.txt')
117 
118  try:
119  with open(package_file) as f:
120  packages = set(line.rstrip().split('/')[-1] for line in f if not line.startswith('#'))
121  except FileNotFoundError:
122  parser.error(f"Cannot read '{package_file}'. Specify via '-p/--packages' or run with '-a/--all'")
123 
124  # By default only show athena packages:
125  filterFnc = None if args.all else lambda p : p in packages
126 
127  # Walk source tree and create DOT graph:
128  g = make_graph(walk_tree(args.path, args.verbose, filterFnc), filterFnc)
129 
130  if args.output:
131  g.write(args.output)
132  else:
133  print(g)
134 

◆ make_graph()

def apydep.make_graph (   deps,
  filterFnc = None 
)
Save the dependencies as dot graph, nodes filtered by filterFnc

Definition at line 81 of file apydep.py.

81 def make_graph(deps, filterFnc=None):
82  """Save the dependencies as dot graph, nodes filtered by filterFnc"""
83 
84  graph = pygraphviz.AGraph(name='AthPyGraph', directed=True)
85  for a in deps:
86  for t in ['import','include']:
87  graph.add_edges_from(((a,b) for b in deps[a][t]
88  if a!=b and (filterFnc is None or (filterFnc(a) and filterFnc(b)))),
89  label = t)
90  return graph
91 
92 

◆ walk_tree()

def apydep.walk_tree (   path = './',
  print_error = False,
  filterFnc = None 
)
Walk the source tree and extract python dependencies, filtered by FilterFnc

Definition at line 61 of file apydep.py.

61 def walk_tree(path='./', print_error=False, filterFnc=None):
62  """Walk the source tree and extract python dependencies, filtered by FilterFnc"""
63 
64  pkg = 'UNKNOWN'
65  deps = defaultdict(lambda : defaultdict(set))
66  for root, dirs, files in os.walk(path):
67  if 'CMakeLists.txt' in files:
68  pkg = os.path.basename(root)
69 
70  if (filterFnc and not filterFnc(pkg)):
71  continue
72 
73  for f in filter(lambda p : os.path.splitext(p)[1]=='.py', files):
74  d = get_dependencies(os.path.join(root,f), print_error)
75  deps[pkg]['import'].update(d.imports)
76  deps[pkg]['include'].update(d.includes)
77 
78  return deps
79 
80 
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
apydep.main
def main()
Definition: apydep.py:93
apydep.walk_tree
def walk_tree(path='./', print_error=False, filterFnc=None)
Definition: apydep.py:61
covarianceTool.filter
filter
Definition: covarianceTool.py:514
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
apydep.make_graph
def make_graph(deps, filterFnc=None)
Definition: apydep.py:81
apydep.get_dependencies
def get_dependencies(filename, print_error=False)
Definition: apydep.py:41
Trk::open
@ open
Definition: BinningType.h:40
WriteBchToCool.update
update
Definition: WriteBchToCool.py:67
Trk::split
@ split
Definition: LayerMaterialProperties.h:38