Run functions as scripts
Project description
Tasker is a way to organize your scripts. If you have dozens of small scripts and you keep forgetting what they do and what parameters they take, tasker is for you. Instead of scripts you write functions, put them in a file or a couple of them, and then run the main tasker script giving them the task name and the parameters of the task like this:
run_task <task-name> [<task-parameter>]...
The help task will scan your tasks package and give you the signatures and docstrings of your tasks.
To be considered as a task, the function name should end with _task. The task name is the function name less the suffix. Suppose we have the following file stucture:
run_task tasks/ __init__.py moretasks.py
__init__.py
def one_task(p1):
print 'in one_task, parameters:', p1
def two_task(p1, p2):
print 'in two_task, parameters:', p1, p2
and moretasks.py
def t1_task(p1):
print 'in t1_task, parameters:', p1
def t2_task(p1, p2=None):
print 'in t2_task, parameters:', p1, p2
Then we can run the following examples:
run_task one foo run_task two foo baz run_task two foo # fails, not enough parameters run_task moretasks.t1 spam run_task moretasks.t2 spam ham run_task moretasks.t2 spam # works too because of default value of the second parameter
To generate the run_task script in the current directory run:
python -m tasker <fully-qualified-name-of-tasks-package> # default = "tasks"
IMPORTANT: All task parameters are strings.
You can include tasks with distribution of your project and run them all with a single installed script. Suppose your project looks like this:
someproject/ __init__.py somestuff.py tasks/
Then you can include the following snippet in __init__.py:
def run_task():
import tasker
tasker.main('tasks')
then include the following in your setuptools-based setup.py:
entry_points={ 'console_scripts': [ 'someproject_task = someproject:run_task', ], }
This setup will create script someproject_task, which will know about your tasks.
Installation
pip install tasker
The current version is Python 3 only. Use version 0.1.2 for Python 2.7.
Origin
This was inspired by the Ruby’s rake utility. I used for some time the shovel python clone of rake until I got dissatisfied with it. The important difference of tasker (apart from simplicity) is that it does not depend on current working directory.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tasker-0.2.tar.gz
.
File metadata
- Download URL: tasker-0.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c9a401e8b7b61bd62afb2f40f03f4916de943aa27502dc59cf3c0eb80f9285f |
|
MD5 | 9687a43986962bc4818ffc298b2f8213 |
|
BLAKE2b-256 | 8db32cf0b63629171d09469772f52df2aa5972a79d163f433e39a85964932a9f |
File details
Details for the file tasker-0.2-py3-none-any.whl
.
File metadata
- Download URL: tasker-0.2-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7793210a1791bc9c48080a36bcb54e0110c47727bd31eaf0a67772ef60ab0781 |
|
MD5 | d46a8fc88057c86b444177cc489e5a73 |
|
BLAKE2b-256 | c8209c74f2e7fb4f488086dbed1fbb3e9b8ad4675b82c9561d1c7b131286145f |