class documentation

class ImportGraph: (source)

Constructor: ImportGraph(entry_point)

View In Hierarchy

The Import Graph class is a data structure that allows users to manipulate different files under a Python project. It leverage import relations in each of source files.

Static Method extract_class_from_source To parse import statements from the AST tree Args: source: source code text Returns: class/function definitions, ast tree and alias pairs
Static Method find_child_by_name To locate a child node using node name
Static Method find_node_by_name To locate a node using node name
Static Method leaf2root To generate the full path to the top level module from the given node. Args: node: the tree node Returns: the full path name in the form of dotted string.
Static Method parse_import To parse import statements from the AST tree Args: tree: Python AST object Returns: an import map data structure
Method __init__ To constuct an import graph. Args: entry_point: the top level folder path such as "my-python-projects/homework1". The argument must not endswith slash!
Method build_dir_tree To build enhanced directory tree for further analysis
Method get_leaf_nodes To return all the leaf nodes in this tree. Each of leaf nodes represents a single Python script.
Method go_to_that_node To locate a particular node from the tree from the current node given a visit path from import statement. For instance, a visit path of [example, module_a, func] means, if we can locate the function definition ...
Instance Variable entry_point Undocumented
Instance Variable root Undocumented
Method _build_dir_tree Undocumented
@staticmethod
def extract_class_from_source(source): (source)

To parse import statements from the AST tree Args: source: source code text Returns: class/function definitions, ast tree and alias pairs

@staticmethod
def find_child_by_name(node, name): (source)

To locate a child node using node name

@staticmethod
def find_node_by_name(nodes, name): (source)

To locate a node using node name

@staticmethod
def leaf2root(node): (source)

To generate the full path to the top level module from the given node. Args: node: the tree node Returns: the full path name in the form of dotted string.

@staticmethod
def parse_import(tree): (source)

To parse import statements from the AST tree Args: tree: Python AST object Returns: an import map data structure

def __init__(self, entry_point): (source)

To constuct an import graph. Args: entry_point: the top level folder path such as "my-python-projects/homework1". The argument must not endswith slash!

def build_dir_tree(self): (source)

To build enhanced directory tree for further analysis

def get_leaf_nodes(self): (source)

To return all the leaf nodes in this tree. Each of leaf nodes represents a single Python script.

def go_to_that_node(self, cur_node, visit_path): (source)

To locate a particular node from the tree from the current node given a visit path from import statement. For instance, a visit path of [example, module_a, func] means, if we can locate the function definition func from module_a under example folder. The function tries to locate the given path using both relative and absolute import path. Args: visit_path: a list of names that represent different level python modules.

entry_point = (source)

Undocumented

Undocumented

def _build_dir_tree(self, node): (source)

Undocumented