gorilla


Namegorilla JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/christophercrouzet/gorilla
SummaryConvenient approach to monkey patching
upload_time2021-04-17 00:05:04
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": "gorilla",
    "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/0f/00/0a7f837b9ea8ad3e0a98aa1d6ac52c13db9bc01ce9ccdca4d3072b8ea272/gorilla-0.4.0.tar.gz",
    "platform": "",
    "description": "Gorilla\n=======\n\n.. image:: https://img.shields.io/travis/christophercrouzet/gorilla/master.svg\n   :target: https://travis-ci.org/christophercrouzet/gorilla\n   :alt: Build status\n\n.. image:: https://img.shields.io/coveralls/christophercrouzet/gorilla/master.svg\n   :target: https://coveralls.io/r/christophercrouzet/gorilla\n   :alt: Coverage Status\n\n.. image:: https://img.shields.io/pypi/v/gorilla.svg\n   :target: https://pypi.python.org/pypi/gorilla\n   :alt: PyPI latest version\n\n.. image:: https://readthedocs.org/projects/gorilla/badge/?version=latest\n   :target: https://gorilla.readthedocs.io\n   :alt: Documentation status\n\n.. image:: https://img.shields.io/pypi/l/gorilla.svg\n   :target: https://pypi.python.org/pypi/gorilla\n   :alt: License\n\n\nGorilla is a Python library that provides a convenient approach to monkey\npatching.\n\nMonkey patching is the process of **modifying module and class attributes at\nruntime** with the purpose of replacing or extending third-party code.\n\nAlthough *not* a recommended practice, it is sometimes useful to fix or modify\nthe behaviour of a piece of code from a third-party library, or to extend its\npublic interface while making the additions feel like they are built-in into\nthe library.\n\nThe Python language makes monkey patching extremely easy but the advantages of\nGorilla are multiple, not only in assuring a **consistent behaviour** on both\nPython 2 and Python 3 versions, but also in preventing common source of errors,\nand making the process both **intuitive and convenient** even when faced with\n*large* numbers of patches to create.\n\n\nFeatures\n--------\n\n* intuitive and convenient decorator approach to create patches.\n* can create patches for all class or module members at once.\n* compatible with both Python 2 and Python 3.\n* customizable behaviour.\n\n\nUsage\n-----\n\nThanks to the dynamic nature of Python that makes monkey patching possible, the\nprocess happens at runtime without ever having to directly modify the source\ncode of the third-party library:\n\n.. code-block:: python\n\n   >>> import gorilla\n   >>> import destination\n   >>> @gorilla.patches(destination.Class)\n   ... class MyClass(object):\n   ...     def method(self):\n   ...         print(\"Hello\")\n   ...     @classmethod\n   ...     def class_method(cls):\n   ...         print(\"world!\")\n\n\nThe code above creates two patches, one for each member of the class\n``MyClass``, but does not apply them yet. In other words, they define the\ninformation required to carry on the operation but are not yet inserted into\nthe specified destination class ``destination.Class``.\n\nSuch patches created with the decorators can then be automatically retrieved by\nrecursively scanning a package or a module, then applied:\n\n.. code-block:: python\n\n   >>> import gorilla\n   >>> import mypackage\n   >>> patches = gorilla.find_patches([mypackage])\n   >>> for patch in patches:\n   ...     gorilla.apply(patch)\n\n\nSee the `Tutorial`_ section from the documentation for more detailed examples\nand explanations on how to use Gorilla.\n\n\nDocumentation\n-------------\n\nRead the documentation online at `gorilla.readthedocs.io`_ or check its source\nin the ``doc`` directory.\n\n\nOut There\n---------\n\nProjects using Gorilla include:\n\n* `bana <https://github.com/christophercrouzet/bana>`_\n* `mlflow <https://github.com/mlflow/mlflow>`_\n\n\nAuthor\n------\n\nChristopher Crouzet\n<`christophercrouzet.com <https://christophercrouzet.com>`_>\n\n\n.. _gorilla.readthedocs.io: https://gorilla.readthedocs.io\n.. _Tutorial: https://gorilla.readthedocs.io/en/latest/tutorial.html\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Convenient approach to monkey patching",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/christophercrouzet/gorilla"
    },
    "split_keywords": [
        "gorilla",
        "monkey",
        "patch",
        "patching"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b32ad0eab79744c9bc32b916226e8cb71e275eb1c4e73ed6d682d99f907e5d10",
                "md5": "689850318ce5b1b996acebd87dbb74a4",
                "sha256": "25a407c783823db06a90f25303a49b2ab553b8527f4c826878ce5d6d2e25cb5c"
            },
            "downloads": -1,
            "filename": "gorilla-0.4.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "689850318ce5b1b996acebd87dbb74a4",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 9591,
            "upload_time": "2021-04-17T00:05:02",
            "upload_time_iso_8601": "2021-04-17T00:05:02.471973Z",
            "url": "https://files.pythonhosted.org/packages/b3/2a/d0eab79744c9bc32b916226e8cb71e275eb1c4e73ed6d682d99f907e5d10/gorilla-0.4.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0f000a7f837b9ea8ad3e0a98aa1d6ac52c13db9bc01ce9ccdca4d3072b8ea272",
                "md5": "6466544f48de14ae93c620a70d94e85b",
                "sha256": "005ab8853b037162a7c77bb824604c6e081878ee03c09ad01ef41744856019d3"
            },
            "downloads": -1,
            "filename": "gorilla-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6466544f48de14ae93c620a70d94e85b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 29757,
            "upload_time": "2021-04-17T00:05:04",
            "upload_time_iso_8601": "2021-04-17T00:05:04.042783Z",
            "url": "https://files.pythonhosted.org/packages/0f/00/0a7f837b9ea8ad3e0a98aa1d6ac52c13db9bc01ce9ccdca4d3072b8ea272/gorilla-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-04-17 00:05:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "christophercrouzet",
    "github_project": "gorilla",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "gorilla"
}
        
Elapsed time: 4.22020s