aspectify


Nameaspectify JSON
Version 0.0.4 PyPI version JSON
download
home_pagehttps://github.com/ruescog/aspectify
SummaryApply Aspect Oriented Programming to your Python code
upload_time2023-06-02 10:53:25
maintainer
docs_urlNone
authorruescog
requires_python>=3.7
licenseApache Software License 2.0
keywords nbdev jupyter notebook python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            aspectify
================

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

Aspect Oriented Programming is a programming paradigm that allows the
user to separate some cross-cutting content from the main code, such as
the logging or a database connection.

As it may be known, other programming languages has some functionallity
(implemented or plugged in) to use this paradigm as an additional
abstract layer to the core application.
[AspectJ](https://www.eclipse.org/aspectj/) (used in Java), can sound
familiar to the reader.

In order to bring this amazing and powerful functionality to Python
(which, in addition, will allow us to add it dynamically instead of
using a weaver –as it is done in Java–), we have defined `Aspectify`, a
Python library to manage AOP.

## Background concepts

Before introducing the library, it is important to define some concepts
used in AOP. Those are: -
[`Aspect`](https://ruescog.github.io/aspectify/aop.html#aspect)
(*what*): a cross-cutting concept. In fact, an
[`Aspect`](https://ruescog.github.io/aspectify/aop.html#aspect) will
group some functionalies. These, which will modify the natural behaviour
of a method, are called `Advice`s. - `PointCut` (*when*): a fragment of
code where the
[`Aspect`](https://ruescog.github.io/aspectify/aop.html#aspect) is
defined. Can be multiple `PointCut`s for each
[`Aspect`](https://ruescog.github.io/aspectify/aop.html#aspect) (indeed,
it will). - `Advice` (*when and what to do*): The code fragment to
execute when the `PointCut` occurs and the moment when the new behaviuor
must occur. Originally, only three moments were defined (`before`,
`around` –instead of– and `after`), but nowadays new moments are
defined, such as “after throwing an exception” (`after_throwing`) or
“after NOT throwing an exception” (`after_returning`).

## Installation

In order to install the library, it is only needed to execute the pypi
comand that follows:

``` sh
pip install aspectify
```

> **ADVICE**: You should use a virtual environment to install the
> packages associated with your proyect.

## Why do we need Aspectify

Once the background is defined and the library is installed, we can
start to create the AOP layer to our projects.

### The core project

In order to use the library, we need a project. For example, we will use
the `random` library for Python.

``` python
from random import Random
```

Now, we can use it to generate some integers.

``` python
r = Random()
r.randint(5, 10)
```

    9

As you can see in its documentation, `randint` (called with parameters
`a` and `b`) can generate the `b` value itself (it is a closed range
\[5, 10\]).

If we want to change this behaviour to the normal random functions
behaviour (the range is closed-opened \[5, 10)), you will need to
redefine it. Furthermore, if other functions or library use this method,
they will not use yours.

How can we solve it? Using AOP.

During this introduction, we have seen the background concepts and how
to install the `Aspectify` library. In the next section we will explain
how to use it with a simple example.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ruescog/aspectify",
    "name": "aspectify",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "nbdev jupyter notebook python",
    "author": "ruescog",
    "author_email": "ruescog@unirioja.es",
    "download_url": "https://files.pythonhosted.org/packages/c7/2c/997fa1d5af76d15b53d674eb5fdeedc4d3eccfdd912412df30e60d9f8f96/aspectify-0.0.4.tar.gz",
    "platform": null,
    "description": "aspectify\n================\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nAspect Oriented Programming is a programming paradigm that allows the\nuser to separate some cross-cutting content from the main code, such as\nthe logging or a database connection.\n\nAs it may be known, other programming languages has some functionallity\n(implemented or plugged in) to use this paradigm as an additional\nabstract layer to the core application.\n[AspectJ](https://www.eclipse.org/aspectj/) (used in Java), can sound\nfamiliar to the reader.\n\nIn order to bring this amazing and powerful functionality to Python\n(which, in addition, will allow us to add it dynamically instead of\nusing a weaver \u2013as it is done in Java\u2013), we have defined `Aspectify`, a\nPython library to manage AOP.\n\n## Background concepts\n\nBefore introducing the library, it is important to define some concepts\nused in AOP. Those are: -\n[`Aspect`](https://ruescog.github.io/aspectify/aop.html#aspect)\n(*what*): a cross-cutting concept. In fact, an\n[`Aspect`](https://ruescog.github.io/aspectify/aop.html#aspect) will\ngroup some functionalies. These, which will modify the natural behaviour\nof a method, are called `Advice`s. - `PointCut` (*when*): a fragment of\ncode where the\n[`Aspect`](https://ruescog.github.io/aspectify/aop.html#aspect) is\ndefined. Can be multiple `PointCut`s for each\n[`Aspect`](https://ruescog.github.io/aspectify/aop.html#aspect) (indeed,\nit will). - `Advice` (*when and what to do*): The code fragment to\nexecute when the `PointCut` occurs and the moment when the new behaviuor\nmust occur. Originally, only three moments were defined (`before`,\n`around` \u2013instead of\u2013 and `after`), but nowadays new moments are\ndefined, such as \u201cafter throwing an exception\u201d (`after_throwing`) or\n\u201cafter NOT throwing an exception\u201d (`after_returning`).\n\n## Installation\n\nIn order to install the library, it is only needed to execute the pypi\ncomand that follows:\n\n``` sh\npip install aspectify\n```\n\n> **ADVICE**: You should use a virtual environment to install the\n> packages associated with your proyect.\n\n## Why do we need Aspectify\n\nOnce the background is defined and the library is installed, we can\nstart to create the AOP layer to our projects.\n\n### The core project\n\nIn order to use the library, we need a project. For example, we will use\nthe `random` library for Python.\n\n``` python\nfrom random import Random\n```\n\nNow, we can use it to generate some integers.\n\n``` python\nr = Random()\nr.randint(5, 10)\n```\n\n    9\n\nAs you can see in its documentation, `randint` (called with parameters\n`a` and `b`) can generate the `b` value itself (it is a closed range\n\\[5, 10\\]).\n\nIf we want to change this behaviour to the normal random functions\nbehaviour (the range is closed-opened \\[5, 10)), you will need to\nredefine it. Furthermore, if other functions or library use this method,\nthey will not use yours.\n\nHow can we solve it? Using AOP.\n\nDuring this introduction, we have seen the background concepts and how\nto install the `Aspectify` library. In the next section we will explain\nhow to use it with a simple example.\n\n\n",
    "bugtrack_url": null,
    "license": "Apache Software License 2.0",
    "summary": "Apply Aspect Oriented Programming to your Python code",
    "version": "0.0.4",
    "project_urls": {
        "Homepage": "https://github.com/ruescog/aspectify"
    },
    "split_keywords": [
        "nbdev",
        "jupyter",
        "notebook",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7fc259f32cbcdfcd7602009ecbcc84a0f7feceb7a48889a871fef54c882d2033",
                "md5": "e48524f1d3a06555d61947dd9c55c415",
                "sha256": "8d255637e5f507993be69c6bf7adec89bae1f7e0c86cc56fcb0ba30012bec58a"
            },
            "downloads": -1,
            "filename": "aspectify-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e48524f1d3a06555d61947dd9c55c415",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8716,
            "upload_time": "2023-06-02T10:53:22",
            "upload_time_iso_8601": "2023-06-02T10:53:22.440727Z",
            "url": "https://files.pythonhosted.org/packages/7f/c2/59f32cbcdfcd7602009ecbcc84a0f7feceb7a48889a871fef54c882d2033/aspectify-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c72c997fa1d5af76d15b53d674eb5fdeedc4d3eccfdd912412df30e60d9f8f96",
                "md5": "0aef6988a367523347f6241c98b77e9c",
                "sha256": "61ae6f853c5f7cf73f1b7e303ce8f32cdd228a81f1f05d3a55be3791dd7648f4"
            },
            "downloads": -1,
            "filename": "aspectify-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "0aef6988a367523347f6241c98b77e9c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9252,
            "upload_time": "2023-06-02T10:53:25",
            "upload_time_iso_8601": "2023-06-02T10:53:25.314048Z",
            "url": "https://files.pythonhosted.org/packages/c7/2c/997fa1d5af76d15b53d674eb5fdeedc4d3eccfdd912412df30e60d9f8f96/aspectify-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-02 10:53:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ruescog",
    "github_project": "aspectify",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aspectify"
}
        
Elapsed time: 1.25999s