gorilla2


Namegorilla2 JSON
Version 3.4.0 PyPI version JSON
download
home_pagehttps://github.com/christophercrouzet/gorilla
SummaryConvenient approach to monkey patching
upload_time2023-01-12 02:21:54
maintainer
docs_urlNone
authorChristopher Crouzet
requires_python
licenseMIT
keywords gorilla monkey patch patching
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            Gorilla
=======

.. image:: https://img.shields.io/travis/christophercrouzet/gorilla/master.svg
   :target: https://travis-ci.org/christophercrouzet/gorilla
   :alt: Build status

.. image:: https://img.shields.io/coveralls/christophercrouzet/gorilla/master.svg
   :target: https://coveralls.io/r/christophercrouzet/gorilla
   :alt: Coverage Status

.. image:: https://img.shields.io/pypi/v/gorilla.svg
   :target: https://pypi.python.org/pypi/gorilla
   :alt: PyPI latest version

.. image:: https://readthedocs.org/projects/gorilla/badge/?version=latest
   :target: https://gorilla.readthedocs.io
   :alt: Documentation status

.. image:: https://img.shields.io/pypi/l/gorilla.svg
   :target: https://pypi.python.org/pypi/gorilla
   :alt: License


Gorilla is a Python library that provides a convenient approach to monkey
patching.

Monkey patching is the process of **modifying module and class attributes at
runtime** with the purpose of replacing or extending third-party code.

Although *not* a recommended practice, it is sometimes useful to fix or modify
the behaviour of a piece of code from a third-party library, or to extend its
public interface while making the additions feel like they are built-in into
the library.

The Python language makes monkey patching extremely easy but the advantages of
Gorilla are multiple, not only in assuring a **consistent behaviour** on both
Python 2 and Python 3 versions, but also in preventing common source of errors,
and making the process both **intuitive and convenient** even when faced with
*large* numbers of patches to create.


Features
--------

* intuitive and convenient decorator approach to create patches.
* can create patches for all class or module members at once.
* compatible with both Python 2 and Python 3.
* customizable behaviour.


Usage
-----

Thanks to the dynamic nature of Python that makes monkey patching possible, the
process happens at runtime without ever having to directly modify the source
code of the third-party library:

.. code-block:: python

   >>> import gorilla
   >>> import destination
   >>> @gorilla.patches(destination.Class)
   ... class MyClass(object):
   ...     def method(self):
   ...         print("Hello")
   ...     @classmethod
   ...     def class_method(cls):
   ...         print("world!")


The code above creates two patches, one for each member of the class
``MyClass``, but does not apply them yet. In other words, they define the
information required to carry on the operation but are not yet inserted into
the specified destination class ``destination.Class``.

Such patches created with the decorators can then be automatically retrieved by
recursively scanning a package or a module, then applied:

.. code-block:: python

   >>> import gorilla
   >>> import mypackage
   >>> patches = gorilla.find_patches([mypackage])
   >>> for patch in patches:
   ...     gorilla.apply(patch)


See the `Tutorial`_ section from the documentation for more detailed examples
and explanations on how to use Gorilla.


Documentation
-------------

Read the documentation online at `gorilla.readthedocs.io`_ or check its source
in the ``doc`` directory.


Out There
---------

Projects using Gorilla include:

* `bana <https://github.com/christophercrouzet/bana>`_
* `mlflow <https://github.com/mlflow/mlflow>`_


Author
------

Christopher Crouzet
<`christophercrouzet.com <https://christophercrouzet.com>`_>


.. _gorilla.readthedocs.io: https://gorilla.readthedocs.io
.. _Tutorial: https://gorilla.readthedocs.io/en/latest/tutorial.html

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/christophercrouzet/gorilla",
    "name": "gorilla2",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "gorilla monkey patch patching",
    "author": "Christopher Crouzet",
    "author_email": "christopher@crouzet.pm",
    "download_url": "https://files.pythonhosted.org/packages/79/6e/55c15cc3b87e0240d6b5a763371e672016cbfd24bd9cca6e1f39cd0f8e4a/gorilla2-3.4.0.tar.gz",
    "platform": null,
    "description": "Gorilla\r\n=======\r\n\r\n.. image:: https://img.shields.io/travis/christophercrouzet/gorilla/master.svg\r\n   :target: https://travis-ci.org/christophercrouzet/gorilla\r\n   :alt: Build status\r\n\r\n.. image:: https://img.shields.io/coveralls/christophercrouzet/gorilla/master.svg\r\n   :target: https://coveralls.io/r/christophercrouzet/gorilla\r\n   :alt: Coverage Status\r\n\r\n.. image:: https://img.shields.io/pypi/v/gorilla.svg\r\n   :target: https://pypi.python.org/pypi/gorilla\r\n   :alt: PyPI latest version\r\n\r\n.. image:: https://readthedocs.org/projects/gorilla/badge/?version=latest\r\n   :target: https://gorilla.readthedocs.io\r\n   :alt: Documentation status\r\n\r\n.. image:: https://img.shields.io/pypi/l/gorilla.svg\r\n   :target: https://pypi.python.org/pypi/gorilla\r\n   :alt: License\r\n\r\n\r\nGorilla is a Python library that provides a convenient approach to monkey\r\npatching.\r\n\r\nMonkey patching is the process of **modifying module and class attributes at\r\nruntime** with the purpose of replacing or extending third-party code.\r\n\r\nAlthough *not* a recommended practice, it is sometimes useful to fix or modify\r\nthe behaviour of a piece of code from a third-party library, or to extend its\r\npublic interface while making the additions feel like they are built-in into\r\nthe library.\r\n\r\nThe Python language makes monkey patching extremely easy but the advantages of\r\nGorilla are multiple, not only in assuring a **consistent behaviour** on both\r\nPython 2 and Python 3 versions, but also in preventing common source of errors,\r\nand making the process both **intuitive and convenient** even when faced with\r\n*large* numbers of patches to create.\r\n\r\n\r\nFeatures\r\n--------\r\n\r\n* intuitive and convenient decorator approach to create patches.\r\n* can create patches for all class or module members at once.\r\n* compatible with both Python 2 and Python 3.\r\n* customizable behaviour.\r\n\r\n\r\nUsage\r\n-----\r\n\r\nThanks to the dynamic nature of Python that makes monkey patching possible, the\r\nprocess happens at runtime without ever having to directly modify the source\r\ncode of the third-party library:\r\n\r\n.. code-block:: python\r\n\r\n   >>> import gorilla\r\n   >>> import destination\r\n   >>> @gorilla.patches(destination.Class)\r\n   ... class MyClass(object):\r\n   ...     def method(self):\r\n   ...         print(\"Hello\")\r\n   ...     @classmethod\r\n   ...     def class_method(cls):\r\n   ...         print(\"world!\")\r\n\r\n\r\nThe code above creates two patches, one for each member of the class\r\n``MyClass``, but does not apply them yet. In other words, they define the\r\ninformation required to carry on the operation but are not yet inserted into\r\nthe specified destination class ``destination.Class``.\r\n\r\nSuch patches created with the decorators can then be automatically retrieved by\r\nrecursively scanning a package or a module, then applied:\r\n\r\n.. code-block:: python\r\n\r\n   >>> import gorilla\r\n   >>> import mypackage\r\n   >>> patches = gorilla.find_patches([mypackage])\r\n   >>> for patch in patches:\r\n   ...     gorilla.apply(patch)\r\n\r\n\r\nSee the `Tutorial`_ section from the documentation for more detailed examples\r\nand explanations on how to use Gorilla.\r\n\r\n\r\nDocumentation\r\n-------------\r\n\r\nRead the documentation online at `gorilla.readthedocs.io`_ or check its source\r\nin the ``doc`` directory.\r\n\r\n\r\nOut There\r\n---------\r\n\r\nProjects using Gorilla include:\r\n\r\n* `bana <https://github.com/christophercrouzet/bana>`_\r\n* `mlflow <https://github.com/mlflow/mlflow>`_\r\n\r\n\r\nAuthor\r\n------\r\n\r\nChristopher Crouzet\r\n<`christophercrouzet.com <https://christophercrouzet.com>`_>\r\n\r\n\r\n.. _gorilla.readthedocs.io: https://gorilla.readthedocs.io\r\n.. _Tutorial: https://gorilla.readthedocs.io/en/latest/tutorial.html\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Convenient approach to monkey patching",
    "version": "3.4.0",
    "split_keywords": [
        "gorilla",
        "monkey",
        "patch",
        "patching"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "796e55c15cc3b87e0240d6b5a763371e672016cbfd24bd9cca6e1f39cd0f8e4a",
                "md5": "c303b1f9d2780bc924d4a130176cf5fc",
                "sha256": "10c3fee8cb6230d5502b47da03a2446119b72f7f80f59cc716eee57601027cba"
            },
            "downloads": -1,
            "filename": "gorilla2-3.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c303b1f9d2780bc924d4a130176cf5fc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 30708,
            "upload_time": "2023-01-12T02:21:54",
            "upload_time_iso_8601": "2023-01-12T02:21:54.017833Z",
            "url": "https://files.pythonhosted.org/packages/79/6e/55c15cc3b87e0240d6b5a763371e672016cbfd24bd9cca6e1f39cd0f8e4a/gorilla2-3.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-12 02:21:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "christophercrouzet",
    "github_project": "gorilla",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "gorilla2"
}
        
Elapsed time: 0.03926s