A simple library to run one task, or multiples ones in sequence or parallel
Project description
simpletasks
Simple tasks runner for Python.
This can be helpful to handle automated processes and make them available via command line interface via click.
Usage
Sample:
import click
from simpletasks import Cli, CliParams, Task
@click.group()
def cli():
pass
@Cli(cli, params=[click.argument("n", type=int), CliParams.progress()])
class FibonacciTask(Task):
def compute(self, n: int) -> int:
self.logger.debug(f"Called with n={n}")
f1, f2 = 0, 1
if n == 0:
return f1
if n == 1:
return f2
for _ in self.progress(range(1, n)):
f1, f2 = f2, f1 + f2
return f2
def do(self) -> None:
n = cast(int, self.options.get("n"))
result = self.compute(n)
print(f"f({n}) = {result}")
if __name__ == "__main__":
cli()
Gives:
$ python sample/compute.py fibonacci 3 --no-progress
f(3) = 2
Contributing
To initialize the environment:
poetry install --no-root
poetry install -E click -E tqdm
To run tests (including linting and code formatting checks), please run:
poetry run pytest --mypy --flake8 && poetry run black --check .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simpletasks-0.1.1.tar.gz
(11.1 kB
view details)
Built Distribution
File details
Details for the file simpletasks-0.1.1.tar.gz
.
File metadata
- Download URL: simpletasks-0.1.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.6.7 Linux/4.15.0-1077-gcp
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6976784e09093e130cde2aca3e81374bbd9e0da6c254de800d8b9b2bf326618b |
|
MD5 | 479fcf5b180766250f110e20fa706876 |
|
BLAKE2b-256 | 2a9750e28e3396c438fb5d72f55561e56d181ed35212839c60285698f8341fbf |
File details
Details for the file simpletasks-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: simpletasks-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.6.7 Linux/4.15.0-1077-gcp
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f0eefe78eedc969e6ca10179477cdbe373396228c33a769348af9bf129504c0 |
|
MD5 | 62eb6440f69ab329af4ede444b6b5855 |
|
BLAKE2b-256 | c5c6321939c7d137aba78f1ea56fbb122cbced426806b16364d47a2100fb9c4e |