Skip to main content

A lightweight Python command runner

Project description

🍥️ dony

A lightweight Python command runner with shell execution and user interactions.

Installation

pip install dony

Optional dependencies:

brew install fzf     # For fuzzy selection
brew install shfmt   # For shell command formatting

Example

import dony

@dony.command(run_from="git_root")
def deploy():
    """Deploy application"""

    if not dony.confirm("Deploy to production?"):
        return

    env = dony.select("Select environment:", ["staging", "production"])

    dony.shell(f"""
        npm run build
        npm test
        ./deploy.sh {env}
    """)

    dony.success(f"Deployed to {env}")

if __name__ == "__main__":
    deploy()

Run with python deploy.py

CLI arguments

To support non-interactive mode, keep all interactions within arguments:

import dony

@dony.command(run_from="git_root")
def build(env: str | None = None):
    """Build application"""

    # CLI arg if provided, otherwise prompt interactively
    env = env or dony.select("Select environment:", ["staging", "production"])

    dony.shell(f"""
        npm run build --env={env}
        npm test
    """)

    dony.success(f"Built for {env}")

if __name__ == "__main__":
    build()

Run interactively: python build.py Run with CLI args: python build.py --env=production

Things to know

  • Available directories to run from:
    • "current_dir" (default)
    • "git_root"
    • "command_file"
    • "temp_dir"
    • Custom path string
  • Available prompts based on questionary:
    • dony.input(): free-text entry
    • dony.confirm(): yes/no ([Y/n] or [y/N])
    • dony.select(): option picker (supports fuzzy)
    • dony.select_many(): multiple option picker (supports fuzzy)
    • dony.press_any_key(): pause until keypress
    • dony.echo(): styled text output
    • dony.error(): ✕ error message
    • dony.success(): ✓ success message

API Reference

def command(
    run_from: Union[str, Path, Literal[ "current_dir", "git_root", "command_file", "temp_dir"]] = "current_dir",
    verbose: bool = True,
) -> Callable[[F], F]:
    ...

def dony.shell(
    command: str,
    run_from: Optional[Union[str, Path]] = None,   # Working directory
    dry_run: bool = False,                         # Print without executing
    quiet: bool = False,                           # Suppress printing output
    capture_output: bool = True,                   # Return output as string
    abort_on_failure: bool = True,                 # Prepends 'set -e'
    abort_on_unset_variable: bool = True,          # Prepends 'set -u'
    trace_execution: bool = False,                 # Prepends 'set -x'
    show_command: bool = True,                     # Print formatted command
    confirm: bool = False,                         # Ask before executing
) -> str:
    ...

License

MIT License

Author

Mark Lidenberg marklidenberg@gmail.com

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

dony-0.4.2.tar.gz (49.0 kB view details)

Uploaded Source

Built Distribution

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

dony-0.4.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file dony-0.4.2.tar.gz.

File metadata

  • Download URL: dony-0.4.2.tar.gz
  • Upload date:
  • Size: 49.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for dony-0.4.2.tar.gz
Algorithm Hash digest
SHA256 a48699b7643f5f04da3b2d9eab2c6cac3a4486991c9c259399a0faefdfc9d0b4
MD5 4e7c2142bd08eab398c0784e74d958a8
BLAKE2b-256 1c253512a2fe86dfc2d16f14b80e754d7743a4f8d2c4f3b43f63c2d7a8b0d203

See more details on using hashes here.

File details

Details for the file dony-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: dony-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for dony-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1871d6e560972cbae7c2a48b7c559dcab0deda84b8991203de3984d9366e3e32
MD5 1e6a2ae9be5257aa6c1b8b6a7a2b172d
BLAKE2b-256 96ba3cafdd3d672c9d8d65900d54a14cbfebbebbd5551d4ab19ff365e64dcb0c

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