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 entrydony.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 keypressdony.echo(): styled text outputdony.error(): ✕ error messagedony.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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dony-0.4.1.tar.gz.
File metadata
- Download URL: dony-0.4.1.tar.gz
- Upload date:
- Size: 48.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b3812a520c8be3fbf64c3400b5e2cac838794153a84521d00fd31a43fa272b1
|
|
| MD5 |
427f5c583643e62c44202b6a06a31431
|
|
| BLAKE2b-256 |
a5445d1b37f137190ad7210badeaaaaa97e6c09ed4f0f6a5f1e15c37fa2d9131
|
File details
Details for the file dony-0.4.1-py3-none-any.whl.
File metadata
- Download URL: dony-0.4.1-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27db90d782c94cd2159986d12f8981820600413c77e0577f41ca6c9b26b5a98f
|
|
| MD5 |
6c1aae709e6f03b440c96a3273fbcdc6
|
|
| BLAKE2b-256 |
7afab69e1f462aefc6b714a99d32fe9e977110e8ff9a5eacad9740466fba4cd1
|