Name | crepr JSON |
Version |
0.5.0
JSON |
| download |
home_page | None |
Summary | Create a __repr__ for your python classes from the definition found in __init__ |
upload_time | 2024-10-06 19:26:18 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.12 |
license | MIT |
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.
`crepr` is a Python script that takes a file name as a command-line argument, imports the specified module, and then adds or removes a `__repr__` method for each class defined in the module. It uses the definition found in the `__init__` method of the class to create a useful representation of the object.
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.
[](https://github.com/cleder/crepr/actions/workflows/run-all-tests.yml)
[](https://codecov.io/gh/cleder/crepr)
[
](https://github.com/pre-commit/pre-commit)
[
](http://mypy-lang.org/)
[
](https://github.com/psf/black)
[](https://opensource.org/license/mit/)
[](https://www.python.org/)
[](https://pypi.org/project/crepr/)
[](https://pypi.org/project/crepr/)
## Features
* Automatically generates `__repr__` methods for all classes in a Python file
* Uses the `__init__` method's arguments to create a meaningful representation
* Can add or remove `__repr__` methods
* Provides options to display the diff or apply changes directly to the file
## Install
```bash
pip install crepr
```
## Usage
To add a `__repr__` method to all classes in a file:
```bash
crepr add <file_name> [--kwarg-splat "..."] [--diff/--inline]
```
To remove the `__repr__` method from all classes in a file:
```bash
crepr remove <file_name> [--diff/--inline]
```
### Options
* `<file_name>`: The name of the Python file to process.
* `--kwarg-splat`: The string to use for the **kwargs splat (default: "{}").
* `--diff`: Display the diff of the changes.
* `--inline`: Apply the changes directly to the file.
## 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 add tests/classes/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, )
```
Apply the changes to the file with:
```bash
❯ crepr add tests/classes/kw_only_test.py --inline
```
Give your representations some love.
❤️`.__repr__(self) -> str:`
Raw data
{
"_id": null,
"home_page": null,
"name": "crepr",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "__repr__, cli, code generator, introspection",
"author": null,
"author_email": "Christian Ledermann <christian.ledermann@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/d9/0c/f0c968462b214f0e1f265c9f3d85f4f0a54b95b0e18796024735d95a2a7e/crepr-0.5.0.tar.gz",
"platform": null,
"description": "# crepr\n\nCreate a ``__repr__`` for your python classes.\n\n\n`crepr` is a Python script that takes a file name as a command-line argument, imports the specified module, and then adds or removes a `__repr__` method for each class defined in the module. It uses the definition found in the `__init__` method of the class to create a useful representation of the object.\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\n[](https://github.com/cleder/crepr/actions/workflows/run-all-tests.yml)\n[](https://codecov.io/gh/cleder/crepr)\n[\n](https://github.com/pre-commit/pre-commit)\n[\n](http://mypy-lang.org/)\n[\n](https://github.com/psf/black)\n[](https://opensource.org/license/mit/)\n[](https://www.python.org/)\n[](https://pypi.org/project/crepr/)\n[](https://pypi.org/project/crepr/)\n\n\n## Features\n\n* Automatically generates `__repr__` methods for all classes in a Python file\n* Uses the `__init__` method's arguments to create a meaningful representation\n* Can add or remove `__repr__` methods\n* Provides options to display the diff or apply changes directly to the file\n\n## Install\n\n```bash\npip install crepr\n```\n\n## Usage\n\nTo add a `__repr__` method to all classes in a file:\n\n```bash\ncrepr add <file_name> [--kwarg-splat \"...\"] [--diff/--inline]\n```\n\nTo remove the `__repr__` method from all classes in a file:\n\n```bash\ncrepr remove <file_name> [--diff/--inline]\n```\n\n### Options\n\n* `<file_name>`: The name of the Python file to process.\n* `--kwarg-splat`: The string to use for the **kwargs splat (default: \"{}\").\n* `--diff`: Display the diff of the changes.\n* `--inline`: Apply the changes directly to the file.\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 add tests/classes/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\nApply the changes to the file with:\n\n```bash\n\u276f crepr add tests/classes/kw_only_test.py --inline\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.5.0",
"project_urls": {
"Homepage": "https://github.com/cleder/crepr/"
},
"split_keywords": [
"__repr__",
" cli",
" code generator",
" introspection"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "74dbaa1f73d29f46351f293276d4c58ae90b730c247afacc02abd7ce2d3331bb",
"md5": "9e4a74055cbc95af4e8db6a4c3ae05cb",
"sha256": "870b8cc244975ced6e59bfa780f117679b49c66c32a28f52b6438009d3e6c57f"
},
"downloads": -1,
"filename": "crepr-0.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9e4a74055cbc95af4e8db6a4c3ae05cb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 8044,
"upload_time": "2024-10-06T19:26:18",
"upload_time_iso_8601": "2024-10-06T19:26:18.012553Z",
"url": "https://files.pythonhosted.org/packages/74/db/aa1f73d29f46351f293276d4c58ae90b730c247afacc02abd7ce2d3331bb/crepr-0.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d90cf0c968462b214f0e1f265c9f3d85f4f0a54b95b0e18796024735d95a2a7e",
"md5": "23401a82c427f3a84862d0fe33280738",
"sha256": "e5aabe1ac20de8e06e95178932477c58caa65336226ff1e6d3656acd622fde06"
},
"downloads": -1,
"filename": "crepr-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "23401a82c427f3a84862d0fe33280738",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 8784,
"upload_time": "2024-10-06T19:26:18",
"upload_time_iso_8601": "2024-10-06T19:26:18.939461Z",
"url": "https://files.pythonhosted.org/packages/d9/0c/f0c968462b214f0e1f265c9f3d85f4f0a54b95b0e18796024735d95a2a7e/crepr-0.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-06 19:26:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cleder",
"github_project": "crepr",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "crepr"
}