|build| |license| |code style| |coverage| |colab-badge|
Supercharge
This package allows you to automatically run code before and after a given class method. Furthermore, this behaviour can be enforced on child classes as well.
Supercharge is available via:
.. code-block::
pip install supercharge
Example
.. code-block:: py
from supercharge import Charge
class HelloWorld:
def __init__(self):
self.run_prepared = False
self.run_state = False
@Charge
def run(self):
if self.run_prepared:
print("running ...")
@run.enter
def pre_run(self):
self.run_prepared = True
@run.exit
def post_run(self):
self.run_state = True
If this is behaviour is desired in subclassed runs one must use the Base class.
.. code-block:: py
from supercharge import Charge, Base
class HelloWorld(Base):
def __init__(self):
self.run_prepared = False
self.run_state = False
@Charge
def run(self):
raise NotImplementedError
@run.enter
def pre_run(self):
self.run_prepared = True
@run.exit
def post_run(self):
self.run_state = True
class Child(HelloWorld):
def run(self):
if self.run_prepared:
print("running ...")
Noticeable Alternatives
Using supercharge might not always be the best way to go. In many scenarios an easier way to achieve a similar functionality can be
.. code-block:: py
class HelloWorld:
def __init__(self):
self.run_prepared = False
self.run_state = False
def run(self):
self.pre_run()
self.base_run()
self.post_run()
def base_run(self):
raise NotImplementedError
def pre_run(self):
self.run_prepared = True
def post_run(self):
self.run_state = True
class Child(HelloWorld):
def base_run(self):
if self.run_prepared:
print("running ...")
where you call Child.run() and overwrite Child.base_run().
.. badges
.. |build| image:: https://github.com/zincware/supercharge/actions/workflows/pytest.yaml/badge.svg :alt: Build tests passing :target: https://github.com/zincware/py-test/blob/readme_badges/
.. |license| image:: https://img.shields.io/badge/License-EPL-purple.svg?style=flat :alt: Project license :target: https://www.eclipse.org/legal/epl-2.0/faq.php
.. |code style| image:: https://img.shields.io/badge/code%20style-black-black :alt: Code style: black :target: https://github.com/psf/black/
.. |coverage| image:: https://coveralls.io/repos/github/zincware/supercharge/badge.svg :alt: Code coverage :target: https://coveralls.io/github/zincware/supercharge
.. |colab-badge| image:: https://colab.research.google.com/assets/colab-badge.svg :alt: Open Example in Google Colab :target: https://colab.research.google.com/github/zincware/supercharge/blob/main/examples/introduction.ipynb
Metadata
Release files for supercharge 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| supercharge-0.1.0.tar.gz | 9.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| supercharge-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.9 kB
Release files / supercharge-0.1.0.tar.gz
| Download URL | supercharge-0.1.0.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c68dec077d293b0fe2ad54734c8393fc761f2251b7fc9ef2ea0f200e2268d8af
|
|
BLAKE2b-256 checksum How to use checksums |
3398210d22c1eda71e154ff8f7d0cdf86f2fc555149700d288401bbc998169c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / supercharge-0.1.0-py3-none-any.whl
| Download URL | supercharge-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d9d9c6afce7387ebcaceb95fa60923133b8e38142ff874f39058249a033ca0b
|
|
BLAKE2b-256 checksum How to use checksums |
16265f663d4fec5b7b70cb84c2c296ba9fd3bdab900d9b034dc63d8458d79512
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Security for supercharge 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.