Skip to main content

A framework for writing console scripts and running commands

Project description

A simple command runner that uses argparse from the Python standard library under the hood. Runs on Python 3 only (3.7 and up). Uses annotations to configure options.

There are two basic use cases:

  1. Standalone console scripts (including scripts with subcommands).

  2. Collections of commands (similar to make, Fabric, etc).

Building on these, especially #2, there are a couple of more advanced use cases:

  1. A simple orchestration/deployment tool. If you have a simple build process and just need to rsync some files to a server, a few simple commands might be all you need.

  2. A wrapper for more sophisticated orchestration/deployment tools–an alternative to the Bash scripts you might use to drive Ansible playbooks and the like.

Basic Usage

Define a command:

from runcommands import arg, command
from runcommands.commands import local

@command
def test(*tests: arg(help='Specific tests to run (instead of using discovery)')):
    if tests:
        local(('python', '-m', 'unittest', tests))
    else:
        local('python -m unittest discover .')

Show its help:

> run test -h
test [-h] [TESTS [TESTS ...]]

positional arguments:
  TESTS       Specific tests to run (instead of using discovery)

optional arguments:
  -h, --help  show this help message and exit

Run it:

> run test
..........
----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

Create a standalone console script using a standard setuptools entry point:

# setup.py
setup(
    ...
    entry_points="""
    [console_scripts]
    my-test-script = package.module:test.console_script

    """
)

Run it (after reinstalling the package):

> my-test-script
..........
----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

See the main documentation for more information on installation, defining & running commands, configuration, etc.

Features

  • Easily create standalone console scripts: simply define a function and wrap it with the @command decorator.

  • Easily create standalone console scripts that have subcommands (a la git).

  • Create collections of commands (similar to make, Fabric, etc).

  • Run multiple commands in sequence: run build deploy.

  • Uses argparse under the hood so command line usage is familiar.

  • Provides built-in help/usage for all commands via argparse.

  • Provides command line completion (including example scripts for bash and fish).

Documentation

Detailed documentation is on Read the Docs.

License

MIT. See the LICENSE file in the source distribution.

TODO

  • Improve command line completion

  • Add more documentation and examples

  • Write tests

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

runcommands-1.0a71.tar.gz (61.3 kB view details)

Uploaded Source

Built Distribution

runcommands-1.0a71-py3-none-any.whl (70.7 kB view details)

Uploaded Python 3

File details

Details for the file runcommands-1.0a71.tar.gz.

File metadata

  • Download URL: runcommands-1.0a71.tar.gz
  • Upload date:
  • Size: 61.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.13 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.7.14

File hashes

Hashes for runcommands-1.0a71.tar.gz
Algorithm Hash digest
SHA256 d33b352a0fab76da4a8448da4b300fdf377f1ac54b22bc6036b8968a0d479a3e
MD5 85cbb861d77d62f3f8b0e1c09c8f99f9
BLAKE2b-256 684f7639beca21aa241110790323db1100490f8f7af37f5b5db04fc5bdc89db2

See more details on using hashes here.

File details

Details for the file runcommands-1.0a71-py3-none-any.whl.

File metadata

  • Download URL: runcommands-1.0a71-py3-none-any.whl
  • Upload date:
  • Size: 70.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.13 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.7.14

File hashes

Hashes for runcommands-1.0a71-py3-none-any.whl
Algorithm Hash digest
SHA256 3d0dfa51b1d40435526f572b8b0298099c9369dd44d68ce5d0906ce579989f64
MD5 4a1922494501459bf01cb808fd5ff079
BLAKE2b-256 dacf0a8bcea46d18df33ed36e96ecd59ed951c9877092ce89b569bb43a688283

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