inheritance_explorer package

Submodules

inheritance_explorer.cli module

Console script for inheritance_explorer. Run $ inheritance_explorer –help for instructions and options.

inheritance_explorer.inheritance_explorer module

class inheritance_explorer.inheritance_explorer.ClassGraphTree(baseclass: Any, funcname: str | None = None, default_color: str = '#000000', func_override_color: str = '#ff0000', similarity_cutoff: float = 0.75, max_recursion_level: int = 500, classes_to_exclude: list[str] | None = None)[source]

Bases: object

A hierarchical class graph container.

Parameters

baseclass

the starting base class to begin mapping from

funcname: str

(optional) the name of a function to watch for overrides

default_color: str

(optional) the default outline color of nodes, in any graphviz string

func_override_color: str

(optional) the outline color of nodes that override funcname, in any graphviz string

max_recursion_level: int

(optional) the max number of recrusion levels to map to. A value of 0 will show only the immediate children of the provided class. Default is set to 500.

classes_to_excludeList[str]

(optional) a list of class names to exclude from the mapping.

build_interactive_graph(include_similarity: bool = True, node_style: dict[str, Any] | None = None, edge_style: dict[str, Any] | None = None, similarity_edge_style: dict[str, Any] | None = None, override_node_color: str | tuple[float, ...] | None = None, **kwargs) Network[source]

build an interactive Network graph from the current node list

Parameters

include_similarity: bool

include edges for similar code (default True)

node_style: dict

a dictionary of parameters to pass to pyvis.network.Network.add_node note that these settings will be applied to all nodes.

edge_style: dict

a dictionary of parameters to pass to pyvis.network.Network.add_edge note that these settings will be applied to all edges.

similarity_edge_style: dict

a dictionary of parameters to pass to pyvis.network.Network.add_edge for the similarity links. Only used if include_similarity is True.

override_node_color: str or tuple

the color for nodes that over-ride the function being tracked. Only used if the base ClassGraphTree was initialized with a funcname to track.

kwargs:

any additional keyword arguments are passed to pyvis.Network

Returns

Network

the pyvis.Network representation of the class hierarchy.

check_source_similarity(similarity_container_class: str = 'PycodeSimilarity', method: str = 'reference', reference: int | None = None)[source]
check_subclasses(parent, parent_id: int, node_i: int, current_recursion_level: int) int[source]
display_code_comparison(include_overrides_only: bool = True)[source]

show the code comparison widget

Parameters

include_overrides_only: bool

if True (default), only displays the classes that override the function being compared.

get_multiple_source_code(node_1: int | str, *args) dict[int | str, str][source]

Retrieve the source code for multiple nodes

Parameters

node_1: Union[str, int] the first node to fetch *args: Union[str, int] any additional nodes to fetch

Returns

dict dictionary where the node is the key and the source code the value.

get_source_code(node: int | str) str[source]

retrieve the source code of the comparison function for a specified node

Parameters

node: int the node to fetch the source code for

Returns

str a string containing the source code for the node.

graph(*args, include_similarity: bool = True, **kwargs) Dot[source]

a GraphViz dot graph of the class hierarchy using pydot

plot_similarity(above_cutoff: bool | None = False, ax: Axes | None = None, colorbar: bool | None = True, **kwargs) tuple[dict[int, str], Axes][source]

add the similarity plot to a matplotlib axis (or create a new one)

Parameters

above_cutoff: bool

if True (default False), plots where similarity > cutoff

ax: Axes

matplotlib axis to add the plot to. A new axis handle will be created and returned if this is not set.

colorbar: bool

adds a colorbar to ax if True (default)

kwargs

any keyword argument accepted by plt.imshow()

Returns

(sim_labels, ax)

sim_labels: dictionary mapping the matrix indices to label ax: the modified (or new) axis handle

set_graphviz_args_kwargs(*args, **kwargs)[source]
show_graph(*args, env: str = 'notebook', format: str = 'png', **kwargs)[source]

display a static GraphViz graph

inheritance_explorer.similarity module

class inheritance_explorer.similarity.PycodeSimilarity(method: str = 'reference')[source]

Bases: SimilarityContainer

class inheritance_explorer.similarity.ResultsContainer(count: int, total: int, similarity_fraction: float, base_class: int, this_class: int)[source]

Bases: object

class inheritance_explorer.similarity.SimilarityContainer(method: str = 'reference')[source]

Bases: ABC

run(source_dict: OrderedDict[int, str], reference: Any | None = None) OrderedDict[int, ResultsContainer] | tuple[dict[int, OrderedDict[int, ResultsContainer]], ndarray[tuple[int, ...], dtype[Any]], tuple[int, ...]][source]
source_dictdict

dictionary mapping a node identifier to a source code string

Module contents

Top-level package for inheritance_explorer.