Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksongoode committed May 1, 2024
1 parent 7daf94e commit 697c4ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pycg/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 7 additions & 4 deletions pycg/processing/postprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(
input_file,
modname,
exclusives,
ignored_mods,
skip_classes,
import_manager,
scope_manager,
def_manager,
Expand All @@ -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
Expand Down Expand Up @@ -178,15 +178,18 @@ 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)

# iterate bases to compute MRO for the class
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
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions pycg/processing/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
filename,
modname,
exclusives,
ignored_mods,
skip_classes,
import_manager,
scope_manager,
def_manager,
Expand All @@ -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
Expand All @@ -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)))

Check failure on line 56 in pycg/processing/preprocessor.py

View workflow job for this annotation

GitHub Actions / flake8

line too long (91 > 89 characters)

def _get_fun_defaults(self, node):
defaults = {}
Expand All @@ -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,
Expand All @@ -92,7 +92,7 @@ def visit_Module(self, node):
def iterate_mod_items(items, const):
items = [
item for item in items

Check warning on line 94 in pycg/processing/preprocessor.py

View workflow job for this annotation

GitHub Actions / flake8

trailing whitespace
if not self.ignored_mod_pattern.search(item)
if not self.skip_classes_pattern.search(item)
]

Check warning on line 97 in pycg/processing/preprocessor.py

View workflow job for this annotation

GitHub Actions / flake8

blank line contains whitespace
for item in items:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pycg/pycg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 697c4ad

Please sign in to comment.