Skip to content

Commit

Permalink
refactor: finish uncluttering main()
Browse files Browse the repository at this point in the history
  • Loading branch information
Technologicat committed Nov 16, 2017
1 parent 9bb608f commit cde6b3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
16 changes: 14 additions & 2 deletions pyan/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,21 @@ def __init__(self, filenames, logger=None):
self.context_stack = [] # for detecting which FunctionDefs are methods
self.last_value = None

def process(self, filename):
# Analyze.
self.process()

def process(self):
"""Analyze the set of files, twice so that any forward-references are picked up."""
for pas in range(2):
for filename in self.filenames:
self.logger.info("========== pass %d, file '%s' ==========" % (pas+1, filename))
self.process_one(filename)
if pas == 0:
self.resolve_base_classes() # must be done only after all files seen
self.postprocess()

def process_one(self, filename):
"""Analyze the specified Python source file."""

if filename not in self.filenames:
raise ValueError("Filename '%s' has not been preprocessed (was not given to __init__, which got %s)" % (filename, self.filenames))
with open(filename, "rt", encoding="utf-8") as f:
Expand Down
9 changes: 0 additions & 9 deletions pyan/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,7 @@ def main():
handler = logging.FileHandler(options.logname)
logger.addHandler(handler)

# Process the set of files, twice so that any forward-references are picked up.
v = CallGraphVisitor(filenames, logger)
for pas in range(2):
for filename in filenames:
logger.info("========== pass %d, file '%s' ==========" % (pas+1, filename))
v.process(filename)
if pas == 0:
v.resolve_base_classes() # must be done only after all files seen
v.postprocess()

graph = VisualGraph.from_visitor(v, options=graph_options, logger=logger)

if options.dot:
Expand Down

0 comments on commit cde6b3e

Please sign in to comment.