Skip to main content

A simple Python-based command line tool that is not quite a fully-fledged task runner

Project description

More affectionately known as jogger.

jogger is a simple Python-based command line tool that isn’t quite a fully-fledged task runner. In addition to supporting arbitrary tasks, run either directly on the command line or as Python scripts, it ships with some common, useful, Django-aware tasks that can adapt their behaviour based on which packages are available in the system.

Full documentation at: https://task-jogger.readthedocs.io/

Installation

Install the latest stable version from PyPI:

pip install task-jogger

Quick start

1. Create jog.py

The jog.py file, created in the project root directory, stores the tasks defined for the project. It is a regular Python module, the only requirement being that it defines a tasks variable as a dictionary.

2. Define tasks

Keys in the jog.py file’s tasks dictionary form each task’s name, and values describe the tasks themselves. At their simplest, a task can be a string defining a command to execute on the command line:

# jog.py
tasks = {
    'hello': 'echo "Hello, World!"',
    'test': 'coverage run python manage.py test'
}

Alternatively, a task can be a Python function that returns a command to execute on the command line. This can be useful if the command is more complex to construct or depends on dynamic values:

# jog.py
def run_tests(settings, stdout, stderr):
    """
    Run the Django test suite, with coverage.py if installed.
    """

    try:
        import coverage
    except ImportError:
        stdout.write('Warning: coverage.py not installed.', style='warning')
        return 'python manage.py test'
    else:
        return 'coverage run python manage.py test'

tasks = {
    'test': run_tests
}

Finally, particularly complex tasks can be defined as classes. Such tasks can define their own custom arguments:

# jog.py
from jogger.tasks import Task


class TestTask(Task):

    help = 'Run the Django test suite, with coverage.py if installed.'

    def add_arguments(self, parser):

        parser.add_argument(
            '-q', '--quick',
            action='store_true',
            help=(
                'Run a "quick" variant of the task: no coverage analysis and '
                'running tests in parallel.'
            )
        )

    def handle(self, *args, **options):

        command = 'python manage.py test'

        if options['quick']:
            command = f'{command} --parallel'
        else:
            try:
                import coverage
            except ImportError:
                self.stdout.write('Warning: coverage.py not installed.', style='warning')
            else:
                command = f'coverage run {command}'

        self.cli(command)

tasks = {
    'test': TestTask
}

3. Run jog

The jog command is the interface to the tasks defined in jog.py.

Given the name of a task, jog will run that task:

$ jog test

If the task accepts arguments, they can also be provided:

$ jog test --quick

Executed with no arguments, jog will display a list of all available tasks. Tasks defined as functions or classes can define a description to be displayed in this listing. Tasks defined as strings simply display the command they will run. The following shows the output of a jog.py file containing a mixture of string-based, function-based, and class-based tasks:

$ jog
Available tasks:
string: echo "Hello, World!"
function: A task defined as a function.
class: A task defined as a class.
    See "jog class --help" for usage details

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

task-jogger-1.2.0a1.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

task_jogger-1.2.0a1-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file task-jogger-1.2.0a1.tar.gz.

File metadata

  • Download URL: task-jogger-1.2.0a1.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for task-jogger-1.2.0a1.tar.gz
Algorithm Hash digest
SHA256 eb32766c0d01c292b1d9a9619c613cc86ee919a494215ae9533d310769e63641
MD5 7fcaab955b3ebfefbb1284d741d22e24
BLAKE2b-256 1425281c984fe525f14cb0c2547a8c983be79a9c9038de2a2204e2a4a9d471ff

See more details on using hashes here.

File details

Details for the file task_jogger-1.2.0a1-py3-none-any.whl.

File metadata

  • Download URL: task_jogger-1.2.0a1-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for task_jogger-1.2.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 a94786934ba996723349c8e772a58a413d2df489b76899a7351e5ebbd7fe9556
MD5 1eaeab6cad52da8519bbf906918797c9
BLAKE2b-256 9802ba50e547b1dc7abd0ade79d334a780df751624aa7eb91bddb1a7f6850103

See more details on using hashes here.

Supported by

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