Skip to main content

Your faithful sidekick

Project description

Zrb (WIP)

Your faithful sidekick

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 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
Directory [.]:
๐Ÿค– โžœ 2023-01-31T13:00:46.960990 โš™ 13321 โžค 1 of 3 โ€ข ๐Ÿˆ         hello โ€ข Hello Go Frendi
๐Ÿค– โžœ 2023-01-31T13:00:47.266618 โš™ 13323 โžค 1 of 3 โ€ข ๐Ÿฏ   make coffee โ€ข Coffee for you โ˜•
๐Ÿค– โžœ 2023-01-31T13:00:47.266753 โš™ 13325 โžค 1 of 3 โ€ข ๐Ÿฆ     make beer โ€ข Cheers ๐Ÿบ
๐Ÿค– โžœ 2023-01-31T13:00:47.601470 โš™ 13327 โžค 1 of 3 โ€ข ๐Ÿฆ    server run โ€ข Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
๐Ÿค– โžœ 2023-01-31T13:00:47.864159 โš™ 13320 โžค 1 of 3 โ€ข ๐Ÿจ  http_checker โ€ข HEAD http://localhost:8080/ 200 (OK)
๐Ÿค– ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰
๐Ÿค– run completed in
๐Ÿค– 0.9100210666656494 seconds
๐Ÿค– ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰

๐Ÿค– โš  2023-01-31T13:00:47.864545 โš™ 13327 โžค 1 of 3 โ€ข ๐Ÿฆ    server run โ€ข 127.0.0.1 - - [31/Jan/2023 13:00:47] "HEAD / HTTP/1.1" 200 -

Configuration

The following configurations are available:

  • ZRB_LOGGING_LEVEL: Logging verbosity.
    • Default: WARNING
    • Possible values:
      • CRITICAL
      • ERROR
      • WARNING
      • WARN (The same as WARNING)
      • INFO
      • DEBUG
      • NOTSET
  • 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

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

# Test zrb in playground
prepare-playground
cd playground
source venv/bin/activate
# Start testing/creating use cases...

For maintainers

To publish Zrb, you need a Pypi account:

You can also create a TestPypi account:

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

This version

0.0.5

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zrb-0.0.5.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

zrb-0.0.5-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file zrb-0.0.5.tar.gz.

File metadata

  • Download URL: zrb-0.0.5.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for zrb-0.0.5.tar.gz
Algorithm Hash digest
SHA256 3c2096d76a76ea5861be2b8a641af47ebc06ceed5d314e9e233a622ccb31a1c8
MD5 5197a88a93228ade0c83a38c32f06155
BLAKE2b-256 25cf366a1be19cf73cb99c3c8e1c2718fb0b5dc2ec654c348a19933b8d73d97b

See more details on using hashes here.

File details

Details for the file zrb-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: zrb-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for zrb-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 811b5d06fd479414ffb2b0aa34bacd27f3719edafb48fc0bf18c8b051a561bad
MD5 4a982dc302b369ed9c28059dbb8d773e
BLAKE2b-256 123937bd4a489db19b179e6edbdfeffc53717ed5de2e05b35afdc3ca477e9e22

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page