Skip to main content

Various cli tools related to MRO. Useful for debugging complex class strictures.

Project description

https://badge.fury.io/py/mro-tools.png

Various cli tools related to MRO. Useful for debugging complex class strictures.

Installing

You can install mro-tools using pip:

$ pip install mro-tools

Why?

Inheritance is wonderful. Except when its not. How many times did you have to debug a complex class with MRO of >30 classes? You will then know its not pleasant. Editors don’t help much since as soon you jump to a base class, all editor inheritance calculations are relative to the jumped class, not the original subclass. That makes it non-trivial to see what actually happens within code execution without dropping into pdb. This package aims to aid with such issues. It has a collection of cli tools which help troubleshooting complex classes with big MRO trees.

Using

MRO tools exposes all tools via a single group command. All available commands can be seen by executing mro-tools command:

❯❯❯ mro-tools
Usage: mro-tools [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  method  Get all method definitions within all classes...
  version  Print version of mro-tools

Each sub-command has more documentation:

❯❯❯ mro-tools version --help
Usage: mro-tools version [OPTIONS]

  Print version of mro-tools

Options:
  --help  Show this message and exit.

mro-tools can also be accessed as a Python module:

❯❯❯ python -m mro_tools

Examples

❯❯❯ python -m mro_tools method django.views.generic:FormView.get_context_data
========
Full MRO
========
django.views.generic.edit.FormView
django.views.generic.base.TemplateResponseMixin
django.views.generic.edit.BaseFormView
django.views.generic.edit.FormMixin
django.views.generic.base.ContextMixin
django.views.generic.edit.ProcessFormView
django.views.generic.base.View
builtins.object

----------------------------------------------------
django.views.generic.edit.FormMixin.get_context_data
----------------------------------------------------
def get_context_data(self, **kwargs):
    """Insert the form into the context dict."""
    if 'form' not in kwargs:
        kwargs['form'] = self.get_form()
    return super().get_context_data(**kwargs)

-------------------------------------------------------
django.views.generic.base.ContextMixin.get_context_data
-------------------------------------------------------
def get_context_data(self, **kwargs):
    if 'view' not in kwargs:
        kwargs['view'] = self
    if self.extra_context is not None:
        kwargs.update(self.extra_context)
    return kwargs

History

0.3.0 (2019-02-08)

  • Added --no-color option. This allows open in other editors for syntax highlight: mro-tools klass ... | vim -R - +'set syntax=python'

  • Added file to class header in klass command

0.2.0 (2018-09-22)

  • Added klass command

0.1.3 (2018-09-13)

  • Added pygments code highlight to method

0.1.2 (2018-02-13)

  • Added --django-configurations option

0.1.1 (2018-01-05)

  • Fixes RST markup in README

0.1.0 (2018-01-05)

  • First release on PyPI.

Credits

Development Lead

Contributors

None yet. Why not be the first?

License

The MIT License (MIT)

Copyright (c) 2018, Miroslav Shubernetskiy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mro-tools-0.3.0.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

mro_tools-0.3.0-py2.py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page