crepr


Namecrepr JSON
Version 0.2.0 PyPI version JSON
download
home_page
SummaryCreate a __repr__ for your python classes from the definition found in __init__
upload_time2023-12-11 19:34:30
maintainer
docs_urlNone
author
requires_python>=3.12
licenseMIT
keywords __repr__ cli code generator introspection
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # crepr

Create a ``__repr__`` for your python classes.

A Python script that takes a file path as a command-line argument,
imports the specified file, and creates a `__repr__` method
for each class defined in the module.
It uses the definition found in the  `__init__` method of the class.
It is pronounced /kɹeɪpr/, like 🇳🇿 crêpe.

Have a look at the blog-post [Love Your Representation
](https://dev.to/ldrscke/love-your-representation-27mm) for the rationale of this package.

[![Tests](https://github.com/cleder/crepr/actions/workflows/run-all-tests.yml/badge.svg?branch=main)](https://github.com/cleder/crepr/actions/workflows/run-all-tests.yml)
[![codecov](https://codecov.io/gh/cleder/crepr/graph/badge.svg?token=EGCcrWkpay)](https://codecov.io/gh/cleder/crepr)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)
](https://github.com/pre-commit/pre-commit)
[![MyPy](https://img.shields.io/badge/type_checker-mypy-blue)
](http://mypy-lang.org/)
[![Black](https://img.shields.io/badge/code_style-black-000000)
](https://github.com/psf/black)
[![MIT License](https://img.shields.io/pypi/l/crepr)](https://opensource.org/license/mit/)
[![Python Version](https://img.shields.io/pypi/pyversions/crepr)](https://www.python.org/)
[![PyPI - Version](https://img.shields.io/pypi/v/crepr)](https://pypi.org/project/crepr/)
[![Status](https://img.shields.io/pypi/status/crepr)](https://pypi.org/project/crepr/)

## Install

```bash
pip install crepr
```

## Usage

```bash
❯ crepr --help
Usage: crepr [OPTIONS] FILE_PATH

  Create a __repr__ method for each class of a python file.

Arguments:
  FILE_PATH  [required]

Options:
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified shell.
  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified shell, to
                                  copy it or customize
```

## Example

Given the file `tests/classes/kw_only_test.py` with the contents:

```python
class KwOnly:
    def __init__(self, name: str, *, age: int) -> None:
        self.name = name
        self.age = age
```

The command:

```bash
❯ crepr tests/kw_only_test.py
```

produces

```python
class KwOnly:
    def __init__(self, name: str, *, age: int) -> None:
        self.name = name
        self.age = age

    def __repr__(self) -> str:
        """Create a string (c)representation for KwOnly."""
        return (f'{self.__class__.__module__}.{self.__class__.__name__}('
            f'name={self.name!r}, '
            f'age={self.age!r}, '
        ')')
```

The `repr()` of an instance of this class will be:

```python
>>> from tests.classes.kw_only_test import KwOnly
>>> kwo = KwOnly('Christian', age=25)
>>> kwo
tests.classes.kw_only_test.KwOnly(name='Christian', age=25, )
```

Give your representations some love.

❤️`.__repr__(self) -> str:`

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "crepr",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": "",
    "keywords": "__repr__,cli,code generator,introspection",
    "author": "",
    "author_email": "Christian Ledermann <christian.ledermann@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/38/7b/15addee496b3936c2bc1175b0055609cbd11db8fb350e3d65f5ef739c8a7/crepr-0.2.0.tar.gz",
    "platform": null,
    "description": "# crepr\n\nCreate a ``__repr__`` for your python classes.\n\nA Python script that takes a file path as a command-line argument,\nimports the specified file, and creates a `__repr__` method\nfor each class defined in the module.\nIt uses the definition found in the  `__init__` method of the class.\nIt is pronounced /k\u0279e\u026apr/, like \ud83c\uddf3\ud83c\uddff cr\u00eape.\n\nHave a look at the blog-post [Love Your Representation\n](https://dev.to/ldrscke/love-your-representation-27mm) for the rationale of this package.\n\n[![Tests](https://github.com/cleder/crepr/actions/workflows/run-all-tests.yml/badge.svg?branch=main)](https://github.com/cleder/crepr/actions/workflows/run-all-tests.yml)\n[![codecov](https://codecov.io/gh/cleder/crepr/graph/badge.svg?token=EGCcrWkpay)](https://codecov.io/gh/cleder/crepr)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)\n](https://github.com/pre-commit/pre-commit)\n[![MyPy](https://img.shields.io/badge/type_checker-mypy-blue)\n](http://mypy-lang.org/)\n[![Black](https://img.shields.io/badge/code_style-black-000000)\n](https://github.com/psf/black)\n[![MIT License](https://img.shields.io/pypi/l/crepr)](https://opensource.org/license/mit/)\n[![Python Version](https://img.shields.io/pypi/pyversions/crepr)](https://www.python.org/)\n[![PyPI - Version](https://img.shields.io/pypi/v/crepr)](https://pypi.org/project/crepr/)\n[![Status](https://img.shields.io/pypi/status/crepr)](https://pypi.org/project/crepr/)\n\n## Install\n\n```bash\npip install crepr\n```\n\n## Usage\n\n```bash\n\u276f crepr --help\nUsage: crepr [OPTIONS] FILE_PATH\n\n  Create a __repr__ method for each class of a python file.\n\nArguments:\n  FILE_PATH  [required]\n\nOptions:\n  --install-completion [bash|zsh|fish|powershell|pwsh]\n                                  Install completion for the specified shell.\n  --show-completion [bash|zsh|fish|powershell|pwsh]\n                                  Show completion for the specified shell, to\n                                  copy it or customize\n```\n\n## Example\n\nGiven the file `tests/classes/kw_only_test.py` with the contents:\n\n```python\nclass KwOnly:\n    def __init__(self, name: str, *, age: int) -> None:\n        self.name = name\n        self.age = age\n```\n\nThe command:\n\n```bash\n\u276f crepr tests/kw_only_test.py\n```\n\nproduces\n\n```python\nclass KwOnly:\n    def __init__(self, name: str, *, age: int) -> None:\n        self.name = name\n        self.age = age\n\n    def __repr__(self) -> str:\n        \"\"\"Create a string (c)representation for KwOnly.\"\"\"\n        return (f'{self.__class__.__module__}.{self.__class__.__name__}('\n            f'name={self.name!r}, '\n            f'age={self.age!r}, '\n        ')')\n```\n\nThe `repr()` of an instance of this class will be:\n\n```python\n>>> from tests.classes.kw_only_test import KwOnly\n>>> kwo = KwOnly('Christian', age=25)\n>>> kwo\ntests.classes.kw_only_test.KwOnly(name='Christian', age=25, )\n```\n\nGive your representations some love.\n\n\u2764\ufe0f`.__repr__(self) -> str:`\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Create a __repr__ for your python classes from the definition found in __init__",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/cleder/crepr/"
    },
    "split_keywords": [
        "__repr__",
        "cli",
        "code generator",
        "introspection"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "81602de377a7f9b3924bc4921d13f16a1fce2f9a32157437e99c1b441672478c",
                "md5": "3700dee13aa4a0c9a44c4e50911a6126",
                "sha256": "8a808f482ff969d0507d1475e2ef26da22809abd5b7b4540a708d730130dff5c"
            },
            "downloads": -1,
            "filename": "crepr-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3700dee13aa4a0c9a44c4e50911a6126",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 6510,
            "upload_time": "2023-12-11T19:34:29",
            "upload_time_iso_8601": "2023-12-11T19:34:29.183524Z",
            "url": "https://files.pythonhosted.org/packages/81/60/2de377a7f9b3924bc4921d13f16a1fce2f9a32157437e99c1b441672478c/crepr-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "387b15addee496b3936c2bc1175b0055609cbd11db8fb350e3d65f5ef739c8a7",
                "md5": "4b1734a7cbe5baa6ed00547b9983a646",
                "sha256": "e95e55a659d6c72a9d064154e667eb445e77e398ae7533f04041e6e737cab4fb"
            },
            "downloads": -1,
            "filename": "crepr-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4b1734a7cbe5baa6ed00547b9983a646",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 6581,
            "upload_time": "2023-12-11T19:34:30",
            "upload_time_iso_8601": "2023-12-11T19:34:30.857128Z",
            "url": "https://files.pythonhosted.org/packages/38/7b/15addee496b3936c2bc1175b0055609cbd11db8fb350e3d65f5ef739c8a7/crepr-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-11 19:34:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cleder",
    "github_project": "crepr",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "crepr"
}
        
Elapsed time: 0.16382s