reprit


Namereprit JSON
Version 0.9.0 PyPI version JSON
download
home_pagehttps://github.com/lycantropos/reprit/
Summary
upload_time2023-05-11 23:14:23
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT License Copyright (c) 2019 Azat Ibrakov 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.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            reprit
======

[![](https://github.com/lycantropos/reprit/workflows/CI/badge.svg)](https://github.com/lycantropos/reprit/actions/workflows/ci.yml "Github Actions")
[![](https://readthedocs.org/projects/reprit/badge/?version=latest)](https://reprit.readthedocs.io/en/latest "Documentation")
[![](https://codecov.io/gh/lycantropos/reprit/branch/master/graph/badge.svg)](https://codecov.io/gh/lycantropos/reprit "Codecov")
[![](https://img.shields.io/github/license/lycantropos/reprit.svg)](https://github.com/lycantropos/reprit/blob/master/LICENSE "License")
[![](https://badge.fury.io/py/reprit.svg)](https://badge.fury.io/py/reprit "PyPI")

In what follows `python` is an alias for `python3.7` or `pypy3.7`
or any later version (`python3.8`, `pypy3.8` and so on).

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

Install the latest `pip` & `setuptools` packages versions
```bash
python -m pip install --upgrade pip setuptools
```

### User

Download and install the latest stable version from `PyPI` repository
```bash
python -m pip install --upgrade reprit
```

### Developer

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

Install
```bash
python setup.py install
```

Usage
-----

Let's suppose we are defining a class and we want to have `__repr__`, that:

1. Includes parameters involved in instance creation. 
For simple cases it should be possible 
to copy string & paste in some place (e.g. REPL session) 
and have similar object definition with as less work as possible. 
This helps a lot during debugging, logging, 
in failed test cases with randomly generated data, etc.
2. In case of signature change 
method should handle this automatically for simple cases 
like renaming/removing/changing order of parameters.

This can be done like
```python
>>> from reprit.base import generate_repr
>>> class DummyContainer:
...     def __init__(self, positional, *variadic_positional, keyword_only, **variadic_keyword):
...         self.positional = positional
...         self.variadic_positional = variadic_positional
...         self.keyword_only = keyword_only
...         self.variadic_keyword = variadic_keyword
...
...     __repr__ = generate_repr(__init__)

```
after that
```python
>>> DummyContainer(range(10), 2, 3, keyword_only='some', a={'sample': 42})
DummyContainer(range(0, 10), 2, 3, keyword_only='some', a={'sample': 42})

```
or for a class with avoidance of built-in names clash
& private'ish attributes
& both
```python
>>> from reprit import seekers
>>> from reprit.base import generate_repr
>>> class State:
...     def __init__(self, id_, name, zip_):
...         self.id = id_
...         self._name = name
...         self._zip = zip_
...
...     __repr__ = generate_repr(__init__,
...                              field_seeker=seekers.complex_)

```
after that
```python
>>> State(1, 'Alabama', 36016)
State(1, 'Alabama', 36016)

```

We can also tell to skip unspecified optional parameters
```python
>>> from reprit.base import generate_repr
>>> class Employee:
...     def __init__(self, name, email=None, manager=None):
...         self.name = name
...         self.email = email
...         self.manager = manager
... 
...     __repr__ = generate_repr(__init__,
...                              skip_defaults=True)

```
After that
```python
>>> Employee('John Doe')
Employee('John Doe')
>>> Employee('John Doe',
...          manager=Employee('Jane Doe'))
Employee('John Doe', manager=Employee('Jane Doe'))
>>> Employee('John Doe', 'johndoe@company.com', Employee('Jane Doe'))
Employee('John Doe', 'johndoe@company.com', Employee('Jane Doe'))

```

*Note*: this method doesn't automatically handle changes during runtime 
(e.g. if someone deletes instance field 
or replaces `__init__`/`__new__` method implementation), 
in this case user should update `__repr__` method as well.

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 release
```

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

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

### Running tests

Install dependencies
```bash
python -m pip install -r requirements-tests.txt
```

Plain
```bash
pytest
```

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:
- with `CPython`
  ```bash
  ./run-tests.sh
  ```
  or
  ```bash
  ./run-tests.sh cpython
  ```

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

`PowerShell` script:
- 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/reprit/",
    "name": "reprit",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Azat Ibrakov <azatibrakov@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d7/dd/46a26d61504fed6702c67036a2ea7809a44319f1c64552776c3f9145c73d/reprit-0.9.0.tar.gz",
    "platform": null,
    "description": "reprit\n======\n\n[![](https://github.com/lycantropos/reprit/workflows/CI/badge.svg)](https://github.com/lycantropos/reprit/actions/workflows/ci.yml \"Github Actions\")\n[![](https://readthedocs.org/projects/reprit/badge/?version=latest)](https://reprit.readthedocs.io/en/latest \"Documentation\")\n[![](https://codecov.io/gh/lycantropos/reprit/branch/master/graph/badge.svg)](https://codecov.io/gh/lycantropos/reprit \"Codecov\")\n[![](https://img.shields.io/github/license/lycantropos/reprit.svg)](https://github.com/lycantropos/reprit/blob/master/LICENSE \"License\")\n[![](https://badge.fury.io/py/reprit.svg)](https://badge.fury.io/py/reprit \"PyPI\")\n\nIn what follows `python` is an alias for `python3.7` or `pypy3.7`\nor any later version (`python3.8`, `pypy3.8` and so on).\n\nInstallation\n------------\n\nInstall the latest `pip` & `setuptools` packages versions\n```bash\npython -m pip install --upgrade pip setuptools\n```\n\n### User\n\nDownload and install the latest stable version from `PyPI` repository\n```bash\npython -m pip install --upgrade reprit\n```\n\n### Developer\n\nDownload the latest version from `GitHub` repository\n```bash\ngit clone https://github.com/lycantropos/reprit.git\ncd reprit\n```\n\nInstall\n```bash\npython setup.py install\n```\n\nUsage\n-----\n\nLet's suppose we are defining a class and we want to have `__repr__`, that:\n\n1. Includes parameters involved in instance creation. \nFor simple cases it should be possible \nto copy string & paste in some place (e.g. REPL session) \nand have similar object definition with as less work as possible. \nThis helps a lot during debugging, logging, \nin failed test cases with randomly generated data, etc.\n2. In case of signature change \nmethod should handle this automatically for simple cases \nlike renaming/removing/changing order of parameters.\n\nThis can be done like\n```python\n>>> from reprit.base import generate_repr\n>>> class DummyContainer:\n...     def __init__(self, positional, *variadic_positional, keyword_only, **variadic_keyword):\n...         self.positional = positional\n...         self.variadic_positional = variadic_positional\n...         self.keyword_only = keyword_only\n...         self.variadic_keyword = variadic_keyword\n...\n...     __repr__ = generate_repr(__init__)\n\n```\nafter that\n```python\n>>> DummyContainer(range(10), 2, 3, keyword_only='some', a={'sample': 42})\nDummyContainer(range(0, 10), 2, 3, keyword_only='some', a={'sample': 42})\n\n```\nor for a class with avoidance of built-in names clash\n& private'ish attributes\n& both\n```python\n>>> from reprit import seekers\n>>> from reprit.base import generate_repr\n>>> class State:\n...     def __init__(self, id_, name, zip_):\n...         self.id = id_\n...         self._name = name\n...         self._zip = zip_\n...\n...     __repr__ = generate_repr(__init__,\n...                              field_seeker=seekers.complex_)\n\n```\nafter that\n```python\n>>> State(1, 'Alabama', 36016)\nState(1, 'Alabama', 36016)\n\n```\n\nWe can also tell to skip unspecified optional parameters\n```python\n>>> from reprit.base import generate_repr\n>>> class Employee:\n...     def __init__(self, name, email=None, manager=None):\n...         self.name = name\n...         self.email = email\n...         self.manager = manager\n... \n...     __repr__ = generate_repr(__init__,\n...                              skip_defaults=True)\n\n```\nAfter that\n```python\n>>> Employee('John Doe')\nEmployee('John Doe')\n>>> Employee('John Doe',\n...          manager=Employee('Jane Doe'))\nEmployee('John Doe', manager=Employee('Jane Doe'))\n>>> Employee('John Doe', 'johndoe@company.com', Employee('Jane Doe'))\nEmployee('John Doe', 'johndoe@company.com', Employee('Jane Doe'))\n\n```\n\n*Note*: this method doesn't automatically handle changes during runtime \n(e.g. if someone deletes instance field \nor replaces `__init__`/`__new__` method implementation), \nin this case user should update `__repr__` method as well.\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 release\n```\n\nBump version\n```bash\nbump2version --verbose release\n```\n\nThis will set version to `major.minor.patch`.\n\n### Running tests\n\nInstall dependencies\n```bash\npython -m pip install -r requirements-tests.txt\n```\n\nPlain\n```bash\npytest\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:\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:\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",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2019 Azat Ibrakov  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. ",
    "summary": "",
    "version": "0.9.0",
    "project_urls": {
        "Download": "https://github.com/lycantropos/reprit/archive/master.zip",
        "Homepage": "https://github.com/lycantropos/reprit/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ffbbdbe079d4e9e15c726b5896b4f52081e8b7025efea9fbc31837c0eacfcc02",
                "md5": "2eb5000ec166653ae9528664e89e7e1e",
                "sha256": "7f8053dacf95b3e38c60dc0204d6010ae6548a81d92197701876f1363576dcdb"
            },
            "downloads": -1,
            "filename": "reprit-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2eb5000ec166653ae9528664e89e7e1e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10172,
            "upload_time": "2023-05-11T23:14:20",
            "upload_time_iso_8601": "2023-05-11T23:14:20.954059Z",
            "url": "https://files.pythonhosted.org/packages/ff/bb/dbe079d4e9e15c726b5896b4f52081e8b7025efea9fbc31837c0eacfcc02/reprit-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d7dd46a26d61504fed6702c67036a2ea7809a44319f1c64552776c3f9145c73d",
                "md5": "ad4ae3b8c55dca2fa6f2a502511ce97b",
                "sha256": "17e9e04679dfc1d1dcd6d945c5d0c51f72272a90343a39c62fa478622b651180"
            },
            "downloads": -1,
            "filename": "reprit-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ad4ae3b8c55dca2fa6f2a502511ce97b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 10878,
            "upload_time": "2023-05-11T23:14:23",
            "upload_time_iso_8601": "2023-05-11T23:14:23.915346Z",
            "url": "https://files.pythonhosted.org/packages/d7/dd/46a26d61504fed6702c67036a2ea7809a44319f1c64552776c3f9145c73d/reprit-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-11 23:14:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lycantropos",
    "github_project": "reprit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "reprit"
}
        
Elapsed time: 0.08970s