Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
[report]
exclude_lines =
if __name__ == .__main__.:
raise NotImplementedError
pass
def print_lattice
def print_report
def print_table
def valid_date
def __repr__
def __str__
if __name__ == .__main__.:
pass
pragma: no cover
raise NotImplementedError

[run]
source = ./pyt
Expand All @@ -15,6 +18,6 @@ omit =
pyt/definition_chains.py
pyt/draw.py
pyt/github_search.py
pyt/intraprocedural_cfg.py
pyt/liveness.py
pyt/repo_runner.py
pyt/save.py
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: autopep8-wrapper
- id: check-docstring-first
- id: debug-statements
- id: check-ast
- id: check-symlinks
- id: name-tests-test
exclude: tests/util
- id: flake8
args: ['--ignore=E501']
11 changes: 5 additions & 6 deletions pyt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
print_table
)
from .draw import draw_cfgs, draw_lattices
from .expr_visitor import make_cfg
from .fixed_point import analyse
from .framework_adaptor import FrameworkAdaptor
from .framework_helper import (
Expand All @@ -28,7 +29,6 @@
is_function_without_leading_
)
from .github_search import scan_github, set_github_api_token
from .interprocedural_cfg import interprocedural
from .lattice import print_lattice
from .liveness import LivenessAnalysis
from .project_handler import get_directory_modules, get_modules
Expand Down Expand Up @@ -183,13 +183,13 @@ def analyse_repo(github_repo, analysis_type, ui_mode):
project_modules = get_modules(directory)
local_modules = get_directory_modules(directory)
tree = generate_ast(github_repo.path)
interprocedural_cfg = interprocedural(
cfg = make_cfg(
tree,
project_modules,
local_modules,
github_repo.path
)
cfg_list.append(interprocedural_cfg)
cfg_list.append(cfg)

initialize_constraint_table(cfg_list)
analyse(cfg_list, analysis_type=analysis_type)
Expand Down Expand Up @@ -256,14 +256,13 @@ def main(command_line_args=sys.argv[1:]):
tree = generate_ast(path, python_2=args.python_2)

cfg_list = list()

interprocedural_cfg = interprocedural(
cfg = make_cfg(
tree,
project_modules,
local_modules,
path
)
cfg_list.append(interprocedural_cfg)
cfg_list.append(cfg)
framework_route_criteria = is_flask_route_function
if args.adaptor:
if args.adaptor.lower().startswith('e'):
Expand Down
2 changes: 1 addition & 1 deletion pyt/alias_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This module contains helper functions for the interprocedural_cfg module."""
"""This module contains alias helper functions for the expr_visitor module."""

def as_alias_handler(alias_list):
"""Returns a list of all the names that will be called."""
Expand Down
14 changes: 1 addition & 13 deletions pyt/analysis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,10 @@ class AnalysisBase(metaclass=ABCMeta):

annotated_cfg_nodes = dict()

def __init__(self, cfg, visitor):
"""Annotate visitor if not None and save visitor."""
if visitor:
self.annotate_cfg(cfg, visitor)
self.visitor = visitor
def __init__(self, cfg):
self.cfg = cfg
self.build_lattice(cfg)

def annotate_cfg(self, cfg, visitor):
"""Add the visitor to the cfg nodes."""
for node in cfg.nodes:
if node.ast_node:
_visitor = visitor()
_visitor.visit(node.ast_node)
self.annotated_cfg_nodes[node] = _visitor.result

@staticmethod
@abstractmethod
def get_lattice_elements(cfg_nodes):
Expand Down
6 changes: 3 additions & 3 deletions pyt/ast_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
python_2_mode = False


def convert_to_3(path):
def convert_to_3(path): # pragma: no cover
"""Convert python 2 file to python 3."""
try:
print('##### Trying to convert file to Python 3. #####')
Expand All @@ -30,13 +30,13 @@ def generate_ast(path, python_2=False):
"""
# If set, it stays set.
global python_2_mode
if python_2:
if python_2: # pragma: no cover
python_2_mode = True
if os.path.isfile(path):
with open(path, 'r') as f:
try:
return ast.parse(f.read())
except SyntaxError:
except SyntaxError: # pragma: no cover
global recursive
if not recursive:
if not python_2_mode:
Expand Down
Loading