Skip to main content

A lightweight Python command runner

Project description

🍥️ dony

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

Commands are just Python functions. You run them by running Python files directly (python deploy.py).

Installation

pip install dony

Optional dependencies:

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

Example

import asyncio
import dony

@dony.command()
async def deploy():
    """Deploy application"""

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

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

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

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

if __name__ == "__main__":
    asyncio.run(deploy())

Run with python deploy.py

CLI Support

For CLI support, use fire or any other CLI framework:

import asyncio
import dony
import fire

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

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

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

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

if __name__ == "__main__":
    fire.Fire(build)

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

Recipes

Working from git repo root

import asyncio
from functools import partial
import dony

async def main():
    shell = partial(dony.shell, run_from=dony.find_repo_root(__file__))

    await shell("npm run build")
    await shell("npm test")

if __name__ == "__main__":
    asyncio.run(main())

Things to know

  • @dony.command(): marker decorator for commands (currently a no-op)
  • 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

async 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:
    ...

def dony.find_repo_root(path: Union[str, Path]) -> Path:
    """Find the git root directory starting from the given path."""
    ...

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.5.0.tar.gz (48.4 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.5.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dony-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fe8146bc97dc371921ab379600e23acdc498c61d1e02cadbdf175e6a990ed7f4
MD5 6885cf3407a6680ad8314b51d6edbe52
BLAKE2b-256 e1f1901ad446f646f67634b7ab8c62ebcc9ebb4cf8e5b38a50f9bc30d4109451

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dony-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 985c24774c39cf95ff401273299a709ac1a14949908fb166a8516fda950f3a4f
MD5 e133a30a2fc1c588cb6ae6e984dc7c1d
BLAKE2b-256 3d2a090c2b7ac6d27a75381a7a9abe2c2edcbe71e0b70ce24ce3962e4ef79750

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