Name | hotfunc JSON |
Version |
0.0.1
JSON |
| download |
home_page | |
Summary | Make functions hot-reloadable with a decorator |
upload_time | 2023-07-11 21:51:25 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.4 |
license | MIT License Copyright (c) 2023-present Michał Szajbe <michal.szajbe@gmail.com> 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 |
hotreload
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# hotfunc
This package provides a decorator for hot-reloading python functions.
It allows to redefine the function in the source code and see the changes immediately without restarting the program.
## Installation
Install with `pip`
```bash
$ python -m pip install hotfunc
```
## Usage
The following example uses the REPL, but `hotfunc` can be used in any python program.
Begin with importing the module and decorating the function that you want to hot-reload.
```python
# myfile.py
from hotfunc import hotreload
name = "Mike"
@hotreload
def say():
print(f"Hello world! My name is {name}.")
```
Start python REPL, import the source file and call your function.
```
>>> from myfile import say
>>> say()
Hello world! My name is Mike.
```
Now, without stopping the interpreter, edit the source file changing the decorated function's body.
```python
# myfile.py
from hotfunc import hotreload
name = "Mike"
@hotreload
def say():
print(f"Ciao mondo! Mi chiamo {name}.")
```
Switch back to REPL and call the function again.
```
>>> say()
Ciao mondo! Mi chiamo Mike.
```
As you can see, the function has been redefined, but its local environment (`name` variable defined outside the function) was preserved.
## Caveats
When hot-reloading a function, its source file is read, definition found and the function itself redefined. Currenty **it is done on every call**, so is rather slow.
As of now, only top-level functions (defined at indentation level zero) are supported.
By default, exceptions raised when redefining or calling hot-reloaded functions are not re-raised. Instead, they are printed to `stdout` and the result of last successful function call is returned. This behaviour can be changed by enabling `reraise` flag:
```python
@hotreload(reraise=True)
def myfunc():
# ...
```
## License
Copyright (c) 2023 Michał Szajbe
Licensed under [The MIT License](LICENSE).
Raw data
{
"_id": null,
"home_page": "",
"name": "hotfunc",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.4",
"maintainer_email": "",
"keywords": "hotreload",
"author": "",
"author_email": "Micha\u0142 Szajbe <michal.szajbe@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/5f/cc/fe864d633d8c0715c15eb6f39a68ed33e671574df4580df2b628179d4dc3/hotfunc-0.0.1.tar.gz",
"platform": null,
"description": "# hotfunc\n\nThis package provides a decorator for hot-reloading python functions.\n\nIt allows to redefine the function in the source code and see the changes immediately without restarting the program.\n\n## Installation\n\nInstall with `pip`\n\n```bash\n$ python -m pip install hotfunc\n```\n\n## Usage\n\nThe following example uses the REPL, but `hotfunc` can be used in any python program.\n\nBegin with importing the module and decorating the function that you want to hot-reload.\n\n```python\n# myfile.py\nfrom hotfunc import hotreload\n\nname = \"Mike\"\n\n@hotreload\ndef say():\n print(f\"Hello world! My name is {name}.\")\n```\n\nStart python REPL, import the source file and call your function.\n\n```\n>>> from myfile import say\n>>> say()\nHello world! My name is Mike.\n```\n\nNow, without stopping the interpreter, edit the source file changing the decorated function's body.\n\n```python\n# myfile.py\nfrom hotfunc import hotreload\n\nname = \"Mike\"\n\n@hotreload\ndef say():\n print(f\"Ciao mondo! Mi chiamo {name}.\")\n```\n\nSwitch back to REPL and call the function again.\n\n```\n>>> say()\nCiao mondo! Mi chiamo Mike.\n```\n\nAs you can see, the function has been redefined, but its local environment (`name` variable defined outside the function) was preserved.\n\n## Caveats\n\nWhen hot-reloading a function, its source file is read, definition found and the function itself redefined. Currenty **it is done on every call**, so is rather slow.\n\nAs of now, only top-level functions (defined at indentation level zero) are supported.\n\nBy default, exceptions raised when redefining or calling hot-reloaded functions are not re-raised. Instead, they are printed to `stdout` and the result of last successful function call is returned. This behaviour can be changed by enabling `reraise` flag:\n\n```python\n@hotreload(reraise=True)\ndef myfunc():\n # ...\n```\n\n## License\n\nCopyright (c) 2023 Micha\u0142 Szajbe\n\nLicensed under [The MIT License](LICENSE).\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2023-present Micha\u0142 Szajbe <michal.szajbe@gmail.com> 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": "Make functions hot-reloadable with a decorator",
"version": "0.0.1",
"project_urls": {
"Homepage": "https://github.com/szajbus/hotfunc"
},
"split_keywords": [
"hotreload"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f426567800ee57a7455dec9ffff95b2a297573b24eecb431066cef244c9c37b6",
"md5": "7e3fb6a6842bab1c3573364b46f09d1b",
"sha256": "986ee430e6d5dca90b9710feb1c6b38876945e8cc58b009349413d33fd3b2ece"
},
"downloads": -1,
"filename": "hotfunc-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7e3fb6a6842bab1c3573364b46f09d1b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.4",
"size": 4813,
"upload_time": "2023-07-11T21:51:23",
"upload_time_iso_8601": "2023-07-11T21:51:23.846958Z",
"url": "https://files.pythonhosted.org/packages/f4/26/567800ee57a7455dec9ffff95b2a297573b24eecb431066cef244c9c37b6/hotfunc-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5fccfe864d633d8c0715c15eb6f39a68ed33e671574df4580df2b628179d4dc3",
"md5": "df310230cf3f48e8c1400fedecea77aa",
"sha256": "b0468fad262645ade30d6da75a429fb7cd33ecf4104a41da73a903cfc1599c39"
},
"downloads": -1,
"filename": "hotfunc-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "df310230cf3f48e8c1400fedecea77aa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.4",
"size": 3921,
"upload_time": "2023-07-11T21:51:25",
"upload_time_iso_8601": "2023-07-11T21:51:25.333456Z",
"url": "https://files.pythonhosted.org/packages/5f/cc/fe864d633d8c0715c15eb6f39a68ed33e671574df4580df2b628179d4dc3/hotfunc-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-11 21:51:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "szajbus",
"github_project": "hotfunc",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "hotfunc"
}