Skip to main content

A small task runner inspired by npm scripts.

Project description

https://api.codacy.com/project/badge/Grade/6ffe1c58a9f7404293f870a5183d8ad8 https://travis-ci.org/eight04/pyXcute.svg?branch=master Documentation Status

A small task runner inspired by npm scripts.

Features

  • Use it like setuptools.

  • Chain tasks with _pre, _err, _post, _fin suffix.

  • A builtin Bump task which can bump version with semver.

  • A small set of cross-platform CLI utils.

Installation

From pypi

pip install pyxcute

Usage

Basic

Create a cute.py file:

from xcute import cute

cute(
  hello = 'echo hello xcute!'
)

then run:

$ cute hello
> Task: hello
> Cmd: echo hello xcute!
hello xcute!

If you got a “not a command” error, see How do I make Python scripts executable?)

“hello” is the name of the task that should be executed. If cute.py is executed without a task name, it will run the “default” task.

Provide additional arguments:

$ cute hello 123
> Task: hello
> Cmd: echo hello xcute! 123
hello xcute! 123

The arguments will be passed into the executor, which is xcute.Cmd.__call__ in this case.

Tasks

It can be a str:

from xcute import cute

cute(
  hello = 'echo hello'
)

If it match the name of another task, pyxcute will execute that task:

from xcute import cute

cute(
  hello = 'world', # execute "world" task when "hello" task is executed
  world = 'echo I am world task'
)

Use a list:

from xcute import cute

cute(
  hello = ['echo task1', 'echo task2']
)

Using an Exception would make the task fail:

from xcute import cute
cute(
  hello = Exception("error message")
)

Use anything that is callable:

from xcute import cute

cute(
  hello = lambda: print('say hello')
)

Actually, when you assign a non-callable value as a task, pyXcute converts it into a callable according to its type.

Task chain

Define the workflow with _pre, _err, _post, _fin suffix:

from xcute import cute

cute(
        hello_pre = 'echo _pre runs before the task',
        hello = 'echo say hello',
        hello_err = 'echo _err runs if there is an error in task, i.e, an uncaught exception or non-zero return code',
        hello_post = 'echo _post runs after the task if task successfully returned',
        hello_fin = 'echo _fin always runs after _post, _err just like finally'
)

When a task is executed, the task runner try to execute _pre task first, then the task itself, then the _post task. If the task raised an exception, then it goes to the _err task. _fin task would be executed whenever the task failed or not.

Pseudo code:

run(name + "_pre")
try:
        run(name, args)
except Exception:
        run(name + "_err")
else:
        run(name + "_post")
finally:
        run(name + "_fin")

Format string

pyXcute expands the command string with xcute.conf dictionary. The expansion is happened at run-time:

from xcute import conf, cute

conf["my_name"] = "world"

def change_my_name():
  conf["my_name"] = "bad world"

cute(
  hello = [
    "echo hello {my_name}",
    change_my_name,
    "echo hello {my_name}"
  ]
)
$ cute hello
> Task: hello
> Cmd: echo hello world
hello world
> Cmd: echo hello bad world
hello bad world

Cross-platform utils

There are some CLI utils inspired by npm-build-tools, including:

  • x-clean

  • x-cat

  • x-copy

  • x-pipe

Run each command with -h to see the help message.

Live example

Checkout the cute file of pyXcute itself.

Documentation

http://pyxcute.readthedocs.io/en/latest/

Changelog

  • 0.6.0 (Nov 1, 2019)

    • Add: LiveReload.

  • 0.5.2 (Jun 14, 2018)

    • Add: support bumper argument in Bump.

    • Add: support Python 3.4. Drop subprocess32.

  • 0.5.1 (May 12, 2018)

    • Add: conf["py"] variable.

  • 0.5.0 (May 11, 2018)

    • Add: support Python 2.

    • Add: documentation.

    • Add: Skip, run_task, task_converter.

    • Add: `Bump` task now update the version number inside `setup.cfg`.

    • Fix: Cmd task failed on Unix due to shell=True and passing args as a list.

    • Change: the command of `Cmd` is now logged. The log message is also changed.

    • Drop: `noop`.

  • 0.4.1 (Apr 3, 2017)

    • Better description for x-clean.

    • Fix broken pipe error in x-pipe.

  • 0.4.0 (Mar 28, 2017)

    • Switch to setup.cfg.

    • Add log, exc, noop, Throw, Try.

    • Drop Exc, Exit.

    • Add x-* utils.

  • 0.3.1 (Mar 23, 2017)

    • Find version from {pkg_name}/__pkginfo__.py.

  • 0.3.0 (Jul 21, 2016)

    • Add pkg_name task.

    • Add default tasks bump, version.

  • 0.2.0 (May 14, 2016)

    • Add _fin tag, which represent finally clause.

    • Add Exc and Exit tasks.

  • 0.1.2 (Apr 20, 2016)

    • Move _pre out of try clause.

  • 0.1.1 (Apr 20, 2016)

    • Bump dev status.

  • 0.1.0 (Apr 20, 2016)

    • First release.

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

pyxcute-0.6.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

pyxcute-0.6.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file pyxcute-0.6.0.tar.gz.

File metadata

  • Download URL: pyxcute-0.6.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

File hashes

Hashes for pyxcute-0.6.0.tar.gz
Algorithm Hash digest
SHA256 8f92eab696a4a3e404e5640ba8b3a904e5a4138f5fc7ec3cadd88182b5dc595f
MD5 7bbefc585d98dd6c4b29745f49a9da43
BLAKE2b-256 4e843b2f5a9e8a017bda6382375dfd62d7cff555ac8671d039f02196dc3c5386

See more details on using hashes here.

File details

Details for the file pyxcute-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: pyxcute-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

File hashes

Hashes for pyxcute-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 386441bef75d7821e25fc27922e5c138d69b68b97c0189449e49fe34b656b2c3
MD5 e581fe63a2ceef4f6917a0ba81df8718
BLAKE2b-256 c72fcaa830c695164875aa675d222c4acd06c2093a3cdd01cc99f38b8b5ec7c1

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