Skip to content

Shell Commands with sh

make is an orchestrator — it doesn't do much work itself, it calls other commands which do the work. That's what we recommend doing with jeeves as well. Among numerous ways to call other programs from Python we recommend a library named, quite concisely, sh: amoffat/sh.

Installation

It will be installed as an optional dependency of jeeves-shell[all].

Alternatives

See shell cobminators to check out other available tools.

By default, it is bundled as a dependency for jeeves, and here is a simple example.

jeeves.py
import typer
from sh import grep, pip


def list_flake8_plugins():
    """List installed plugins for Flake8."""
    typer.echo(
        grep( # (1)!
            'flake8-',
            _in=pip.freeze(),
        ),
    )
  1. Equivalent to: pip freeze | grep flake8-

Shall we execute it?

j list-flake8-plugins
flake8-bandit==3.0.0
flake8-broken-line==0.5.0
flake8-bugbear==22.12.6
flake8-commas==2.1.0
flake8-comprehensions==3.14.0
flake8-debugger==4.1.2
flake8-docstrings==1.7.0
flake8-eradicate==1.4.0
flake8-isort==4.2.0
flake8-polyfill==1.0.2
flake8-quotes==3.3.2
flake8-rst-docstrings==0.2.7
flake8-string-format==0.3.0

sh allows to call shell commands with conciseness and readability of Pythonic syntax. See 📖 the package docs for more detail.