From cde6b3e25ca95e53b1a9af248b808441ea8a435b Mon Sep 17 00:00:00 2001 From: Juha Jeronen Date: Thu, 16 Nov 2017 17:22:14 +0200 Subject: [PATCH] refactor: finish uncluttering main() --- pyan/analyzer.py | 16 ++++++++++++++-- pyan/main.py | 9 --------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pyan/analyzer.py b/pyan/analyzer.py index 757a89e..91e15f0 100644 --- a/pyan/analyzer.py +++ b/pyan/analyzer.py @@ -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: diff --git a/pyan/main.py b/pyan/main.py index 13095f9..9c48fdd 100644 --- a/pyan/main.py +++ b/pyan/main.py @@ -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: