https://github.com/ri0t/python-mro-graph
A small tool to generate and illustrate (via dot) the method resolution order graph of Python objects
https://github.com/ri0t/python-mro-graph
developer-tools dot graph method mro order python2 python3 resolution tool visualizer
Last synced: 3 months ago
JSON representation
A small tool to generate and illustrate (via dot) the method resolution order graph of Python objects
- Host: GitHub
- URL: https://github.com/ri0t/python-mro-graph
- Owner: ri0t
- Created: 2020-11-13T17:29:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-14T17:56:46.000Z (over 4 years ago)
- Last Synced: 2025-02-01T23:18:21.019Z (4 months ago)
- Topics: developer-tools, dot, graph, method, mro, order, python2, python3, resolution, tool, visualizer
- Language: Python
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
python-mro-graph generator
##########################A small tool to generate and illustrate (via dot) the method resolution order graph of
Python objectsBased off of Michele Simionato's original work from 2003, which you can find here:
http://www.phyast.pitt.edu/~micheles/python/drawMRO.htmlI added packaging foam and a click based command line interface and some minor
updates. Nothing that changes the basic functionality much, except perhaps an additional
dot-source export.Requirements
============Generating a graph needs the dot tool installed. Usually this tool resides in the
`graphviz` package.Additionally - to display the resulting graphs - either imagemagick or ghostview or
some other postscript or png viewer is required.Usage
=====Command line tool
-----------------You will need to be able to import the object you want to investigate.
Simple usage: builtins
~~~~~~~~~~~~~~~~~~~~~~A simple example demonstrating usage for builtin objects:
.. code-block::
mro-graph "" "dict"
..which displays the MRO of a simple dictionary. Notice that IMPORT_EXEC
is left empty, that is because we do not need to import anything to inspect
builtins.Complex usage: packaged objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Say, you have a package called `test` which contains a module called `test_module`
which in turn contains the object you want to inspect, called `test_object`.To inspect it, call `mro-graph` and instruct it to generate a graph:
.. code-block::
mro-graph "from test.test_module import test_object" "test_object"
..which should result in it displaying the MRO graph to you.
See the command line help for more details:
.. code-block::
mro-graph --help
As importable component
-----------------------You can also do it this way:
.. code-block::
from mro_graph import MROGraph
MROGraph(dict)
This will generate and display the MRO graph of Python's builtin dictionary.
By using it this way, you can inspect live objects right inside your program.License
=======Copyright (C) 2003 Michele Simionato
Copyright (C) 2019-2020 Heiko 'riot' Weinen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .