memoir


Namememoir JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/lycantropos/memoir/
SummaryMemoization support.
upload_time2020-03-18 09:01:39
maintainer
docs_urlNone
authorAzat Ibrakov
requires_python>=3.5.3
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            memoir
======

[![](https://travis-ci.com/lycantropos/memoir.svg?branch=master)](https://travis-ci.com/lycantropos/memoir "Travis CI")
[![](https://dev.azure.com/lycantropos/memoir/_apis/build/status/lycantropos.memoir?branchName=master)](https://dev.azure.com/lycantropos/memoir/_build/latest?branchName=master "Azure Pipelines")
[![](https://codecov.io/gh/lycantropos/memoir/branch/master/graph/badge.svg)](https://codecov.io/gh/lycantropos/memoir "Codecov")
[![](https://img.shields.io/github/license/lycantropos/memoir.svg)](https://github.com/lycantropos/memoir/blob/master/LICENSE "License")
[![](https://badge.fury.io/py/memoir.svg)](https://badge.fury.io/py/memoir "PyPI")

In what follows
- `python` is an alias for `python3.5` or any later
version (`python3.6` and so on),
- `pypy` is an alias for `pypy3.5` or any later
version (`pypy3.6` and so on).

Installation
------------

Install the latest `pip` & `setuptools` packages versions:
- with `CPython`
  ```bash
  python -m pip install --upgrade pip setuptools
  ```
- with `PyPy`
  ```bash
  pypy -m pip install --upgrade pip setuptools
  ```

### User

Download and install the latest stable version from `PyPI` repository:
- with `CPython`
  ```bash
  python -m pip install --upgrade memoir
  ```
- with `PyPy`
  ```bash
  pypy -m pip install --upgrade memoir
  ```

### Developer

Download the latest version from `GitHub` repository
```bash
git clone https://github.com/lycantropos/memoir.git
cd memoir
```

Install:
- with `CPython`
  ```bash
  python setup.py install
  ```
- with `PyPy`
  ```bash
  pypy setup.py install
  ```

Usage
-----

Let's suppose we are defining a class 
with expensive read-only [`property`](https://docs.python.org/library/functions.html#property) 
which can be calculated once and reused afterwards.

Common way of solving this is by introducing private'ish attribute like
```python
>>> class Example:
...     @property
...     def expensive_property(self):
...         try:
...             result = self._expensive_property
...         except AttributeError:
...             result = do_expensive_calculations(...)
...             self._expensive_property = result
...         return result

```
this works fine, but each such property

- introduces an extra attribute,
- requires a lot of boilerplate code.

If we have

- [weakly-referencable](https://docs.python.org/library/weakref.html) 
(which is by default if not suppressed explicitly, 
e.g. by using [`__slots__` class variable](https://docs.python.org/reference/datamodel.html#slots)),
- [hashable](https://docs.python.org/glossary.html#term-hashable)

class we can implement it like
```python
>>> from memoir import cached
>>> class Example:
...     @cached.property_
...     def expensive_property(self):
...         return do_expensive_calculations(...)

```

Development
-----------

### Bumping version

#### Preparation

Install
[bump2version](https://github.com/c4urself/bump2version#installation).

#### Pre-release

Choose which version number category to bump following [semver
specification](http://semver.org/).

Test bumping version
```bash
bump2version --dry-run --verbose $CATEGORY
```

where `$CATEGORY` is the target version number category name, possible
values are `patch`/`minor`/`major`.

Bump version
```bash
bump2version --verbose $CATEGORY
```

This will set version to `major.minor.patch-alpha`. 

#### Release

Test bumping version
```bash
bump2version --dry-run --verbose --tag release
```

Bump version
```bash
bump2version --verbose --tag release
```

This will set version to `major.minor.patch` and add `Git` tag.

#### Notes

To avoid inconsistency between branches and pull requests,
bumping version should be merged into `master` branch as separate pull
request.

### Running tests

Plain:
- with `CPython`
  ```bash
  python setup.py test
  ```
- with `PyPy`
  ```bash
  pypy setup.py test
  ```

Inside `Docker` container:
- with `CPython`
  ```bash
  docker-compose --file docker-compose.cpython.yml up
  ```
- with `PyPy`
  ```bash
  docker-compose --file docker-compose.pypy.yml up
  ```

`Bash` script (e.g. can be used in `Git` hooks):
- with `CPython`
  ```bash
  ./run-tests.sh
  ```
  or
  ```bash
  ./run-tests.sh cpython
  ```

- with `PyPy`
  ```bash
  ./run-tests.sh pypy
  ```

`PowerShell` script (e.g. can be used in `Git` hooks):
- with `CPython`
  ```powershell
  .\run-tests.ps1
  ```
  or
  ```powershell
  .\run-tests.ps1 cpython
  ```
- with `PyPy`
  ```powershell
  .\run-tests.ps1 pypy
  ```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lycantropos/memoir/",
    "name": "memoir",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5.3",
    "maintainer_email": "",
    "keywords": "",
    "author": "Azat Ibrakov",
    "author_email": "azatibrakov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/36/e2/5ae0ce6ebb39ca46c6a078820fad82eb8922e11ae19aefecf1c5a09a8f97/memoir-0.0.3.tar.gz",
    "platform": "",
    "description": "memoir\n======\n\n[![](https://travis-ci.com/lycantropos/memoir.svg?branch=master)](https://travis-ci.com/lycantropos/memoir \"Travis CI\")\n[![](https://dev.azure.com/lycantropos/memoir/_apis/build/status/lycantropos.memoir?branchName=master)](https://dev.azure.com/lycantropos/memoir/_build/latest?branchName=master \"Azure Pipelines\")\n[![](https://codecov.io/gh/lycantropos/memoir/branch/master/graph/badge.svg)](https://codecov.io/gh/lycantropos/memoir \"Codecov\")\n[![](https://img.shields.io/github/license/lycantropos/memoir.svg)](https://github.com/lycantropos/memoir/blob/master/LICENSE \"License\")\n[![](https://badge.fury.io/py/memoir.svg)](https://badge.fury.io/py/memoir \"PyPI\")\n\nIn what follows\n- `python` is an alias for `python3.5` or any later\nversion (`python3.6` and so on),\n- `pypy` is an alias for `pypy3.5` or any later\nversion (`pypy3.6` and so on).\n\nInstallation\n------------\n\nInstall the latest `pip` & `setuptools` packages versions:\n- with `CPython`\n  ```bash\n  python -m pip install --upgrade pip setuptools\n  ```\n- with `PyPy`\n  ```bash\n  pypy -m pip install --upgrade pip setuptools\n  ```\n\n### User\n\nDownload and install the latest stable version from `PyPI` repository:\n- with `CPython`\n  ```bash\n  python -m pip install --upgrade memoir\n  ```\n- with `PyPy`\n  ```bash\n  pypy -m pip install --upgrade memoir\n  ```\n\n### Developer\n\nDownload the latest version from `GitHub` repository\n```bash\ngit clone https://github.com/lycantropos/memoir.git\ncd memoir\n```\n\nInstall:\n- with `CPython`\n  ```bash\n  python setup.py install\n  ```\n- with `PyPy`\n  ```bash\n  pypy setup.py install\n  ```\n\nUsage\n-----\n\nLet's suppose we are defining a class \nwith expensive read-only [`property`](https://docs.python.org/library/functions.html#property) \nwhich can be calculated once and reused afterwards.\n\nCommon way of solving this is by introducing private'ish attribute like\n```python\n>>> class Example:\n...     @property\n...     def expensive_property(self):\n...         try:\n...             result = self._expensive_property\n...         except AttributeError:\n...             result = do_expensive_calculations(...)\n...             self._expensive_property = result\n...         return result\n\n```\nthis works fine, but each such property\n\n- introduces an extra attribute,\n- requires a lot of boilerplate code.\n\nIf we have\n\n- [weakly-referencable](https://docs.python.org/library/weakref.html) \n(which is by default if not suppressed explicitly, \ne.g. by using [`__slots__` class variable](https://docs.python.org/reference/datamodel.html#slots)),\n- [hashable](https://docs.python.org/glossary.html#term-hashable)\n\nclass we can implement it like\n```python\n>>> from memoir import cached\n>>> class Example:\n...     @cached.property_\n...     def expensive_property(self):\n...         return do_expensive_calculations(...)\n\n```\n\nDevelopment\n-----------\n\n### Bumping version\n\n#### Preparation\n\nInstall\n[bump2version](https://github.com/c4urself/bump2version#installation).\n\n#### Pre-release\n\nChoose which version number category to bump following [semver\nspecification](http://semver.org/).\n\nTest bumping version\n```bash\nbump2version --dry-run --verbose $CATEGORY\n```\n\nwhere `$CATEGORY` is the target version number category name, possible\nvalues are `patch`/`minor`/`major`.\n\nBump version\n```bash\nbump2version --verbose $CATEGORY\n```\n\nThis will set version to `major.minor.patch-alpha`. \n\n#### Release\n\nTest bumping version\n```bash\nbump2version --dry-run --verbose --tag release\n```\n\nBump version\n```bash\nbump2version --verbose --tag release\n```\n\nThis will set version to `major.minor.patch` and add `Git` tag.\n\n#### Notes\n\nTo avoid inconsistency between branches and pull requests,\nbumping version should be merged into `master` branch as separate pull\nrequest.\n\n### Running tests\n\nPlain:\n- with `CPython`\n  ```bash\n  python setup.py test\n  ```\n- with `PyPy`\n  ```bash\n  pypy setup.py test\n  ```\n\nInside `Docker` container:\n- with `CPython`\n  ```bash\n  docker-compose --file docker-compose.cpython.yml up\n  ```\n- with `PyPy`\n  ```bash\n  docker-compose --file docker-compose.pypy.yml up\n  ```\n\n`Bash` script (e.g. can be used in `Git` hooks):\n- with `CPython`\n  ```bash\n  ./run-tests.sh\n  ```\n  or\n  ```bash\n  ./run-tests.sh cpython\n  ```\n\n- with `PyPy`\n  ```bash\n  ./run-tests.sh pypy\n  ```\n\n`PowerShell` script (e.g. can be used in `Git` hooks):\n- with `CPython`\n  ```powershell\n  .\\run-tests.ps1\n  ```\n  or\n  ```powershell\n  .\\run-tests.ps1 cpython\n  ```\n- with `PyPy`\n  ```powershell\n  .\\run-tests.ps1 pypy\n  ```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Memoization support.",
    "version": "0.0.3",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9b2a2a97c4c97c28058ef7cb8cc0894dd40ef3a69b1d2c5a0c2fc94e6db83ec7",
                "md5": "64a64852a9b42beae0fc3feb5ae96a37",
                "sha256": "24b9038d29cab4a17ef3ec495932f321e76b6cf425eca1d7518dc8af7cd82d37"
            },
            "downloads": -1,
            "filename": "memoir-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "64a64852a9b42beae0fc3feb5ae96a37",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5.3",
            "size": 4905,
            "upload_time": "2020-03-18T09:01:39",
            "upload_time_iso_8601": "2020-03-18T09:01:39.037832Z",
            "url": "https://files.pythonhosted.org/packages/9b/2a/2a97c4c97c28058ef7cb8cc0894dd40ef3a69b1d2c5a0c2fc94e6db83ec7/memoir-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "36e25ae0ce6ebb39ca46c6a078820fad82eb8922e11ae19aefecf1c5a09a8f97",
                "md5": "301a78ddad53b3bf22b0e6fbee15ba1c",
                "sha256": "1f7fc401da6575f8f03ef7f7147bdecf969499aa41a3532c28cace8fe7237c3d"
            },
            "downloads": -1,
            "filename": "memoir-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "301a78ddad53b3bf22b0e6fbee15ba1c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5.3",
            "size": 4044,
            "upload_time": "2020-03-18T09:01:39",
            "upload_time_iso_8601": "2020-03-18T09:01:39.918888Z",
            "url": "https://files.pythonhosted.org/packages/36/e2/5ae0ce6ebb39ca46c6a078820fad82eb8922e11ae19aefecf1c5a09a8f97/memoir-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-03-18 09:01:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "lycantropos",
    "github_project": "memoir",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "memoir"
}
        
Elapsed time: 0.05404s