sanka
a function decorator for surfacing dead code
Quick start
The "examples/" directory is home to sanka use cases.
examples/
├── actionpack/
│ ├── example.py
│ └── requirements.txt
└── ...
A docker image capable of running an example can be built using a nox command:
EXAMPLE=actionpack nox -s image
where the example referenced in the image can be specified using the "EXAMPLE" environment variable. To run a container, execute something like the following:
docker run -e RUN_DURATION_SECONDS=10 -e CALL_DELAY_SECONDS=5 sanka:0.3.0
Setup
Ensure nox is installed.
pip install nox
Run nox to install sanka and run tests.
Usage
the basics
Decorate any funciton with @sanka.
@sanka
def function():
pass
The decorator instance tracks function calls so the call count can be gotten as follows:
function(YaDead) #=> returns number of times `function` was called
callbacks
One can also pass a callback argument to the @sanka decorator:
from string import Template
report = Template('Called $f called $this_many times')
callback: Callable[[int], None] = lambda tally: print(
"Ya, mon."
if tally == 0
else report.substitute(f=str(function), this_many=tally)
)
@sanka(callback=callback)
def function():
pass
The callback is expected to be a single-parameter function that accepts an int.
This int is the latest tally for the number of times the decorated function has been called.
To access the call count for the docorated function, just ask @sanka if it's "dead":
function(YaDead)
and as per the example you'd get this response if the function had never been called:
Ya, mon.
callback control
By default, callbacks are only executed when YaDead is passed.
The callback can be executed on every function call if desired.
@sanka(callback=callback, only_callback_when_dead=False)
def function():
pass
Now, every time function is called, the callback will also be called.
Metadata
Release files for sanka 0.3.2
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 | Actions |
|---|---|---|---|---|
| sanka-0.3.2.tar.gz | 7.9 kB | Without provenance | Details for sanka-0.3.2.tar.gz |
Release files / sanka-0.3.2.tar.gz
| Download URL | sanka-0.3.2.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6c4db4f419e0e398c32181542c5dcd2b49cc83054c71081c5d9ce79a2308449
|
|
BLAKE2b-256 checksum How to use checksums |
aa180e954ad28bc66c8a34b99b985e0e7f07451c6c74bf357cc8f3df5967d25e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Security for sanka 0.3.2
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.