From 3b74a83be505b4260c18bcec703ca3b5db20c87f Mon Sep 17 00:00:00 2001 From: Joshua Adkins Date: Thu, 2 May 2024 12:16:41 -0600 Subject: [PATCH] Revert "Exclusively build for pwdata and filter out classes (#3)" This reverts commit b21c0ea009e9569e9fcb956db545c409d6ab18e3. --- pycg/__main__.py | 8 +------- pycg/processing/postprocessor.py | 10 ---------- pycg/processing/preprocessor.py | 29 ----------------------------- pycg/pycg.py | 10 +--------- 4 files changed, 2 insertions(+), 55 deletions(-) diff --git a/pycg/__main__.py b/pycg/__main__.py index a5beffe..fb254c3 100644 --- a/pycg/__main__.py +++ b/pycg/__main__.py @@ -12,10 +12,6 @@ def main(): parser.add_argument( "--package", help="Package containing the code to be analyzed", default=None ) - parser.add_argument( - "--exclusives", help="Exclusive package to analyze", default=[]) - parser.add_argument( - "--skip-classes", help="Classes to skip during traversal", default=[]) parser.add_argument( "--fasten", help="Produce call graph using the FASTEN format", @@ -61,9 +57,7 @@ def main(): args = parser.parse_args() cg = CallGraphGenerator( - args.entry_point, args.package, - args.exclusives, args.skip_classes, - args.max_iter, args.operation + args.entry_point, args.package, args.max_iter, args.operation ) cg.analyze() diff --git a/pycg/processing/postprocessor.py b/pycg/processing/postprocessor.py index 757bee7..f114e43 100644 --- a/pycg/processing/postprocessor.py +++ b/pycg/processing/postprocessor.py @@ -30,8 +30,6 @@ def __init__( self, input_file, modname, - exclusives, - skip_classes, import_manager, scope_manager, def_manager, @@ -40,8 +38,6 @@ def __init__( modules_analyzed=None, ): super().__init__(input_file, modname, modules_analyzed) - self.exclusives = exclusives - self.skip_classes = skip_classes self.import_manager = import_manager self.scope_manager = scope_manager self.def_manager = def_manager @@ -178,10 +174,6 @@ def visit_FunctionDef(self, node): super().visit_FunctionDef(node) def visit_ClassDef(self, node): - # 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) @@ -337,8 +329,6 @@ def update_parent_classes(self, defi): def analyze_submodules(self): super().analyze_submodules( PostProcessor, - self.exclusives, - 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 7edfb8f..5d5c7db 100644 --- a/pycg/processing/preprocessor.py +++ b/pycg/processing/preprocessor.py @@ -19,7 +19,6 @@ # under the License. # import ast -import re from pycg import utils from pycg.machinery.definitions import Definition @@ -31,8 +30,6 @@ def __init__( self, filename, modname, - exclusives, - skip_classes, import_manager, scope_manager, def_manager, @@ -43,8 +40,6 @@ def __init__( super().__init__(filename, modname, modules_analyzed) self.modname = modname - self.exclusives = exclusives - self.skip_classes = skip_classes self.mod_dir = "/".join(self.filename.split("/")[:-1]) self.import_manager = import_manager @@ -53,8 +48,6 @@ def __init__( self.class_manager = class_manager self.module_manager = module_manager - self.skip_classes_pattern = re.compile('|'.join(map(re.escape, self.skip_classes))) - def _get_fun_defaults(self, node): defaults = {} start = len(node.args.args) - len(node.args.defaults) @@ -78,8 +71,6 @@ def analyze_submodule(self, modname): super().analyze_submodule( PreProcessor, modname, - self.exclusives, - self.skip_classes, self.import_manager, self.scope_manager, self.def_manager, @@ -90,11 +81,6 @@ def analyze_submodule(self, modname): def visit_Module(self, node): def iterate_mod_items(items, const): - items = [ - item for item in items - if not self.skip_classes_pattern.search(item) - ] - for item in items: defi = self.def_manager.get(item) if not defi: @@ -217,15 +203,6 @@ def add_external_def(name, target): for import_item in node.names: src_name = handle_src_name(import_item.name) tgt_name = import_item.asname if import_item.asname else import_item.name - - # Limit to exclusive module if exclusives exist - if self.exclusives and src_name.split(".")[0] not in self.exclusives: - continue - - # Skip specified classes - if tgt_name in self.skip_classes: - continue - imported_name = self.import_manager.handle_import(src_name, level) if not imported_name: @@ -246,9 +223,6 @@ def add_external_def(name, target): # handle all modules that were not analyzed for modname in self.import_manager.get_imports(self.modname): - if self.exclusives and modname.split(".")[0] not in self.exclusives: - continue - fname = self.import_manager.get_filepath(modname) if not fname: @@ -428,9 +402,6 @@ def visit_Lambda(self, node): def visit_ClassDef(self, node): # create a definition for the class (node.name) - if node.name in self.skip_classes: - return - cls_def = self.def_manager.handle_class_def(self.current_ns, node.name) mod = self.module_manager.get(self.modname) diff --git a/pycg/pycg.py b/pycg/pycg.py index 7a354f9..2f77017 100644 --- a/pycg/pycg.py +++ b/pycg/pycg.py @@ -35,13 +35,9 @@ class CallGraphGenerator(object): - def __init__( - self, entry_points, package, exclusives, skip_classes, max_iter, operation - ): + def __init__(self, entry_points, package, max_iter, operation): self.entry_points = entry_points self.package = package - self.exclusives = exclusives - self.skip_classes = skip_classes self.state = None self.max_iter = max_iter self.operation = operation @@ -166,8 +162,6 @@ def analyze(self): self.do_pass( PreProcessor, True, - self.exclusives, - self.skip_classes, self.import_manager, self.scope_manager, self.def_manager, @@ -185,8 +179,6 @@ def analyze(self): self.do_pass( PostProcessor, False, - self.exclusives, - self.skip_classes, self.import_manager, self.scope_manager, self.def_manager,