diff --git a/pycg/__main__.py b/pycg/__main__.py index 8de8f58..0228971 100644 --- a/pycg/__main__.py +++ b/pycg/__main__.py @@ -62,7 +62,7 @@ def main(): cg = CallGraphGenerator( args.entry_point, args.package, - args.exclusives, args.ignored_mods, + args.exclusives, args.skip_classes, args.max_iter, args.operation ) cg.analyze() diff --git a/pycg/processing/postprocessor.py b/pycg/processing/postprocessor.py index 5e6eb01..757bee7 100644 --- a/pycg/processing/postprocessor.py +++ b/pycg/processing/postprocessor.py @@ -31,7 +31,7 @@ def __init__( input_file, modname, exclusives, - ignored_mods, + skip_classes, import_manager, scope_manager, def_manager, @@ -41,7 +41,7 @@ def __init__( ): super().__init__(input_file, modname, modules_analyzed) self.exclusives = exclusives - self.ignored_mods = ignored_mods + self.skip_classes = skip_classes self.import_manager = import_manager self.scope_manager = scope_manager self.def_manager = def_manager @@ -178,8 +178,10 @@ def visit_FunctionDef(self, node): super().visit_FunctionDef(node) def visit_ClassDef(self, node): - if node.name in self.ignored_mods: + # Return if visiting class should be skipped + if node.name in self.skip_classes: return + # create a definition for the class (node.name) cls_def = self.def_manager.handle_class_def(self.current_ns, node.name) @@ -187,6 +189,7 @@ def visit_ClassDef(self, node): cls = self.class_manager.get(cls_def.get_ns()) if not cls: cls = self.class_manager.create(cls_def.get_ns(), self.modname) + cls.clear_mro() for base in node.bases: # all bases are of the type ast.Name @@ -335,7 +338,7 @@ def analyze_submodules(self): super().analyze_submodules( PostProcessor, self.exclusives, - self.ignored_mods, + self.skip_classes, self.import_manager, self.scope_manager, self.def_manager, diff --git a/pycg/processing/preprocessor.py b/pycg/processing/preprocessor.py index 55a18c2..7edfb8f 100644 --- a/pycg/processing/preprocessor.py +++ b/pycg/processing/preprocessor.py @@ -32,7 +32,7 @@ def __init__( filename, modname, exclusives, - ignored_mods, + skip_classes, import_manager, scope_manager, def_manager, @@ -44,7 +44,7 @@ def __init__( self.modname = modname self.exclusives = exclusives - self.ignored_mods = ignored_mods + self.skip_classes = skip_classes self.mod_dir = "/".join(self.filename.split("/")[:-1]) self.import_manager = import_manager @@ -53,7 +53,7 @@ def __init__( self.class_manager = class_manager self.module_manager = module_manager - self.ignored_mod_pattern = re.compile('|'.join(map(re.escape, self.ignored_mods))) + self.skip_classes_pattern = re.compile('|'.join(map(re.escape, self.skip_classes))) def _get_fun_defaults(self, node): defaults = {} @@ -79,7 +79,7 @@ def analyze_submodule(self, modname): PreProcessor, modname, self.exclusives, - self.ignored_mods, + self.skip_classes, self.import_manager, self.scope_manager, self.def_manager, @@ -92,7 +92,7 @@ def visit_Module(self, node): def iterate_mod_items(items, const): items = [ item for item in items - if not self.ignored_mod_pattern.search(item) + if not self.skip_classes_pattern.search(item) ] for item in items: @@ -222,8 +222,8 @@ def add_external_def(name, target): if self.exclusives and src_name.split(".")[0] not in self.exclusives: continue - # Skip ignored modules - if tgt_name in self.ignored_mods: + # Skip specified classes + if tgt_name in self.skip_classes: continue imported_name = self.import_manager.handle_import(src_name, level) @@ -428,7 +428,7 @@ def visit_Lambda(self, node): def visit_ClassDef(self, node): # create a definition for the class (node.name) - if node.name in self.ignored_mods: + if node.name in self.skip_classes: return cls_def = self.def_manager.handle_class_def(self.current_ns, node.name) diff --git a/pycg/pycg.py b/pycg/pycg.py index bc673b9..7a354f9 100644 --- a/pycg/pycg.py +++ b/pycg/pycg.py @@ -36,12 +36,12 @@ class CallGraphGenerator(object): def __init__( - self, entry_points, package, exclusives, ignored_mods, max_iter, operation + self, entry_points, package, exclusives, skip_classes, max_iter, operation ): self.entry_points = entry_points self.package = package self.exclusives = exclusives - self.ignored_mods = ignored_mods + self.skip_classes = skip_classes self.state = None self.max_iter = max_iter self.operation = operation @@ -167,7 +167,7 @@ def analyze(self): PreProcessor, True, self.exclusives, - self.ignored_mods, + self.skip_classes, self.import_manager, self.scope_manager, self.def_manager, @@ -186,7 +186,7 @@ def analyze(self): PostProcessor, False, self.exclusives, - self.ignored_mods, + self.skip_classes, self.import_manager, self.scope_manager, self.def_manager,