Your faithful companion
Project description
Zrb (WIP)
Your faithful companion.
How to install
pip install zrb
How to use
To run a task, you can invoke the following command:
zrb <task> [arguments]
How to define tasks
Zrb will automatically load:
zrb_init.py
in your current directory.- or any Python file defined in
ZRB_INIT_SCRIPTS
environment.
You can use a colon separator (:
) to define multiple scripts in ZRB_INIT_SCRIPTS
. For example:
ZRB_SCRIPTS=~/personal/zrb_init.py:~/work/zrb_init.py
Your Zrb script (e.g: ./zrb_init.py
) should contain your task definitions. For example:
from zrb import (
runner, Env, StrInput, Group, CmdTask, HTTPChecker
)
'''
Simple task, read input and show output
'''
hello = CmdTask(
name='hello',
inputs=[StrInput(name='name', description='Name', default='world')],
cmd='echo Hello {{input.name}}'
)
runner.register(hello)
make = Group(name='make', description='Make things')
'''
Simple task, part of 'make' group
'''
make_coffee = CmdTask(
name='coffee',
group=make,
upstreams=[hello],
cmd='echo Coffee for you โ'
)
runner.register(make_coffee)
'''
Simple task, part of 'make' group
'''
make_beer = CmdTask(
name='beer',
group=make,
upstreams=[hello],
cmd='echo Cheers ๐บ'
)
runner.register(make_beer)
'''
Sub group of 'make'
'''
make_gitignore = Group(
name='gitignore', description='Make gitignore', parent=make
)
'''
Simple task, part of 'make_gitignore' group.
Having multiline cmd
'''
make_gitignore_python = CmdTask(
name='node',
group=make_gitignore,
cmd=[
'echo "node_modules/" >> .gitignore'
'echo ".npm" >> .gitignore'
'echo "npm-debug.log" >> .gitignore'
]
)
runner.register(make_gitignore_python)
'''
Simple task, part of 'make_gitignore' group.
Having multiline cmd
'''
make_gitignore_nodejs = CmdTask(
name='node',
group=make_gitignore,
cmd=[
'echo "__pycache__/" >> .gitignore'
'echo "venv" >> .gitignore'
]
)
runner.register(make_gitignore_nodejs)
server = Group(
name='server', description='Server related commands'
)
'''
Long running task.
Run a server and waiting for the port to be ready.
'''
run_server = CmdTask(
name='run',
group=server,
upstreams=[make_coffee, make_beer],
inputs=[StrInput(name='dir', description='Directory', default='.')],
envs=[Env(name='PORT', os_name='WEB_PORT', default='3000')],
cmd='python -m http.server $PORT --directory {{input.dir}}',
checkers=[HTTPChecker(port='{{env.PORT}}')]
)
runner.register(run_server)
Once registered, your task will be accessible from the terminal:
export WEB_PORT=8080
zrb server run
The output will be similar to this:
Name [world]: Go Frendi
Dir [.]:
๐ค โ 2023-02-02T07:17:35.384284 โ 6095 โค 1 of 3 โข ๐ hello โข Hello Go Frendi
๐ค โ 2023-02-02T07:17:35.491491 โ 6097 โค 1 of 3 โข ๐ท make coffee โข Coffee for you โ
๐ค โ 2023-02-02T07:17:35.492019 โ 6099 โค 1 of 3 โข ๐ฆ make beer โข Cheers ๐บ
๐ค โ 2023-02-02T07:17:35.618819 โ 6101 โค 1 of 3 โข ๐ server run โข Serving HTTP on 0.0.0.0 port 3000 (http://0.0.0.0:3000/) ...
๐ค โ 2023-02-02T07:17:35.684434 โ 6094 โค 1 of 1 โข ๐ http_check โข HEAD http://localhost:3000/ 200 (OK)
๐ค ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐
๐ค ๐ server run completed in
๐ค ๐ 0.31129932403564453 seconds
๐ค ๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐
๐ค โ 2023-02-02T07:17:35.685651 โ 6101 โค 1 of 3 โข ๐ server run โข 127.0.0.1 - - [02/Feb/2023 07:17:35] "HEAD / HTTP/1.1" 200 -
How to run tasks programmatically
To run a task programmatically, you need to create a main loop
.
For example:
from zrb import CmdTask
cmd_task = CmdTask(
name='sample',
cmd='echo hello'
)
main_loop = cmd_task.create_main_loop(env_prefix='')
main_loop() # This run the task
Configuration
The following configurations are available:
ZRB_LOGGING_LEVEL
: Logging verbosity.- Default:
WARNING
- Possible values:
CRITICAL
ERROR
WARNING
WARN
(The same asWARNING
)INFO
DEBUG
NOTSET
- Default:
ZRB_INIT_SCRIPTS
: List of task registration script that should be loaded by default.- Default: Empty
- Possible values: List of script paths, separated by colons(
:
). - Example:
~/personal/zrb_init.py:~/work/zrb_init.py
ZRB_ENV
: Environment prefix that will be used when loading Operating System's environment.- Default: Empty
- Possible values: Any combination of alpha-numeric and underscore
- Example:
DEV
ZRB_SHOULD_LOAD_DEFAULT
: Whether load default tasks or not- Default:
1
- Possible values:
1
0
- Default:
For contributors
There is a toolkit you can use to test whether Zrb is working as intended.
To use the toolkit, you can invoke the following:
source ./toolkit.sh
# Build Zrb
build-zrb
# Run test and show coverage.
# You can access the coverage report by visiting http://localhost:9000
# You can also change the port by setting __TEST_COVERAGE_PORT variable
test-zrb
# Test zrb in playground
prepare-playground
play
# Start testing/creating use cases...
zrb server run
For maintainers
To publish Zrb, you need a Pypi
account:
- Log in or register to https://pypi.org/
- Create an API token
You can also create a TestPypi
account:
- Log in or register to https://test.pypi.org/
- Create an API token
Once you have your API token, you need to create a ~/.pypirc
file:
[distutils]
index-servers =
pypi
testpypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = __token__
password = pypi-xxx-xxx
[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-xxx-xxx
To publish Zrb, you can do the following:
source ./toolkit.sh
# Build Zrb
build-zrb
# Publish Zrb to TestPypi
test-publish-zrb
# Publish Zrb to Pypi
publish-zrb
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
Built Distribution
File details
Details for the file zrb-0.0.6.tar.gz
.
File metadata
- Download URL: zrb-0.0.6.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e86955651e98c19d222dd4a79c18033a3421cef87a5674a8cd9b90985d07ff6b |
|
MD5 | ae6cf0073a98369d83cfe52d7f0077d9 |
|
BLAKE2b-256 | 993beb8296ce74ae626ab40bdac0b7ff53be02845fb76a4af3605860dc44e78d |
File details
Details for the file zrb-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: zrb-0.0.6-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac9cd4dc1e0264f414ede3b588a216bff5a627e8075043df535029a9674c818f |
|
MD5 | c9bd42c07be71b4bda23882a6478a46b |
|
BLAKE2b-256 | df3f7b348ab9851955fff623ffe84a461471228281654e4400776692095a63e7 |