Coder Social home page Coder Social logo

ri0t / python-mro-graph Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 23 KB

A small tool to generate and illustrate (via dot) the method resolution order graph of Python objects

Python 100.00%
developer-tools mro python2 python3 method resolution order dot visualizer tool

python-mro-graph's Introduction

python-mro-graph generator

A small tool to generate and illustrate (via dot) the method resolution order graph of Python objects

Based off of Michele Simionato's original work from 2003, which you can find here: http://www.phyast.pitt.edu/~micheles/python/drawMRO.html

I 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:

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:

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:

mro-graph --help

As importable component

You can also do it this way:

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 <http://www.gnu.org/licenses/>.

python-mro-graph's People

Contributors

ri0t avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.