Skip to main content

qwikfire

Release Build status codecov Commit activity License

Decorate class methods with one or more shell commands

QwikFire allows users to annotate class methods with a list of shell commands. The decorator does not execute these commands but injects an extra (hidden) QwikFire argument into the annotated method's argument list right after self. The method implementation can use the qf handle to execute all commands in the annotation using a one-liner: qf.run().

An brief example should clearly demonstrate the benefits of using the @qwikfire annotation to keep your python code clean and easy to read. The annotation executes two echo commands one after the other using Jinja style variable substitution. If an exception were to occur it will be caught, wrapped within a user defined, domain specific WrappingException which extends QwikFireException, and re-raised:

  class WrappingException(QwikFireException):
    pass

  class MyAnnotatedClass:
    ...
    @qwikfire(WrappingException, "echo {{hello_var}}", "echo {{world_var}}")
    def many_twovars(self, qf: QwikFire) -> str:
      return qf.run(self, hello_var="hello", world_var="world").stripped

  ...
  # invoking the method without the (hidden) QwikFire argument
  instance.many_twovars()

Callers do not include the injected hidden QwikFire argument intended for the implementation to use. Notice that no warnings arise with callers missing the QwikFire argument: i.e. instance.many_twovars().

The example above, demonstrates how almost all the boilerplate for try / except blocks, conditional checks, logging, etc, is gone. Reading and understanding what commands the method executes and what exceptions it raises makes the annotation self documenting.

QwikFire and its annotation is properly typed preventing Python typing tools (i.e pyright, pyre, mypy) from needlessly littering your code with complaint's. This is a common problem with decorators that inject additional parameters since the signature of the definition differs from the signature of callers. Overall the code is much more readable while the pattern results in pythonic OO code when chaining method outputs to other method inputs.

sh package kwargs (see https://sh.readthedocs.io/en/latest/sections/special_arguments.html#) can be used in the run() method. They're prefixed with _, and are passed through to the sh.Command. If the class whose methods are annotated, exposes a dictionary accessor method called sh_defaults(self, method: Caller[..., Any]), the values of the dictionary it returns are used for defaults both for variable substitutions and for pass-through arguments to the sh.Command. NOTE: the method is provided to, if needed, tailor defaults to specific class methods. Method specific kwarg key pairs provided to the run method override these defaults.

Why?

Even with the glorious sh package, I still find myself writing boilerplate code, logging, error handling and raising higher level (wrapper) exceptions specific to the domain of the package or application using sh. Even though sh does a great job minimizing the boilerplate, it still clutters my code, and reduces its readability. Other code maintainers will still need to know about sh and how I used it.

NOTE: Piped commands do NOT work. Use output chaining of one annotated method as input into another, if needed as a one off. Multiple semi-colon separated commands in the same string, i.e. "echo {{hello_var}}; echo {{world_var}}" will NOT work, just use separate commands in the variadic string commands array.

If you find you need these or other shell features you're probably over doing it. Write an actual shell script and execute that instead, or directly use the sh package in your code. QwikFire is purposefully meant to be simple and there to prevent the occasional shell command from cluttering up your code.


Metadata

Release files for qwikfire 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qwikfire 0.1.3
File Size Uploaded Provenance
qwikfire-0.1.3.tar.gz 8.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for qwikfire 0.1.3
File Interpreter ABI Platform
qwikfire-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / qwikfire-0.1.3.tar.gz

Download URL qwikfire-0.1.3.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
94ef8de175983863f0dcc589e4d8ffb206d449211d7078fd36362cdb124b54d5
BLAKE2b-256 checksum
How to use checksums
e0e0a20ed1f64138eda1d94aa9dfad536bfbd711cef05f0b7f78aff08af6e8c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.10.12 Linux/6.8.0-49-generic

Release files / qwikfire-0.1.3-py3-none-any.whl

Download URL qwikfire-0.1.3-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04092e4c4e5a3fbb249e4218b3893f6003082f3ffedbd345326f0289908069a0
BLAKE2b-256 checksum
How to use checksums
ab0399216580e71b65fb189c4b66f954f9592e95c37c430a05c292444e3a0809
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.10.12 Linux/6.8.0-49-generic

Security for qwikfire 0.1.3

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page