Write and manage your project's development scripts with modern Python syntax
Project description
YARU (やる)
Write and manage your project's development scripts with modern Python syntax.
The project's name comes from the Japanese verb やる, which means "to do".
Highlights
- 🗂️ Lightweight package with zero dependencies.
- 🐍 Supports modern Python versions (>=3.12).
- 🚀 Simply write your development scripts as Python functions.
- 🖥️ Supports macOS, Linux, and Windows.
Installation
If using the uv package manager:
uv add --dev yaru
If using pip:
pip install yaru
Documentation
Yaru's documentation is available at https://github.com/c0dearm/yaru.
Features
A single decorator to rule them all
Simply decorate your Python functions to convert them into cli commands:
# :commands.py file
from typing import Annotated
from yaru import Arg, Context, command
# Add two numbers
@command
def add_numbers(c: Context, a: int, b: int) -> None:
"""Given `a` and `b`, print the sum of both numbers to stdout."""
print(a + b)
The decorated functions must be discovered by yaru, so they need to be in a module named commands at
the root of your project, for example a commands.py file.
The add_numbers command is now invokable through the cli, this is the output of yaru --help:
usage: yaru [-h] {add-numbers} ...
Project's development commands
positional arguments:
{add-numbers}
add-numbers Add two numbers
options:
-h, --help show this help message and exit
For specific help on the command usage, you can do: yaru add-numbers --help:
usage: yaru add-numbers [-h] a b
Given `a` and `b`, print the sum of both numbers to stdout.
positional arguments:
a
b
options:
-h, --help show this help message and exit
Running the command yaru add-numbers 42 69 in your terminal will output 111.
Automated command metadata
The help text for the cli command is automatically parsed from the comments immiediatelly preceding the decorated function. Similarly, the command's description is obtained from the function's docstrings.
Moreover, you can use annotated type hints on your function's arguments in order to add help texts to the command's parameters too:
# :commands.py file
from typing import Annotated
from yaru import Arg, Context, command
# Add two numbers
@command
def add_numbers(
c: Context,
a: Annotated[int, Arg(help="First operand")],
b: Annotated[int, Arg(help="Second operand")],
) -> None:
"""Given `a` and `b`, print the sum of both numbers to stdout."""
print(a + b)
The add-numbers cli help will now display as:
usage: yaru add-numbers [-h] a b
Given `a` and `b`, print the sum of both numbers to stdout.
positional arguments:
a First operand
b Second operand
options:
-h, --help show this help message and exit
Optional arguments
If you define the function's arguments as optional (keyword arguments with defaults), yaru will treat
them as such in the cli. For example:
# :commands.py file
from yaru import Context, command
@command
def say_something(c: Context, phrase: str, twice: bool = False) -> None:
print(phrase)
if twice:
print(phrase)
Will be handled like this:
usage: yaru say-something [-h] [--twice | --no-twice] phrase
positional arguments:
phrase
options:
-h, --help show this help message and exit
--twice, --no-twice
Context to run commands in a shell
You may have noticed an extra first Context argument in all the commands. This is automatically injected
by yaru and provides a handy method run to execute instructions in your shell.
Going back to the example of number addition, we could do this in bash instead of python:
# :commands.py file
from yaru import Context, command
# Add two numbers
@command
def add_numbers(c: Context, a: int, b: int) -> None:
c.run(f"echo $(({a} + {b}))")
The behavior when executed is exactly the same.
Contributing
We welcome contributions! Please read our CONTRIBUTING.md file for guidelines on how to contribute to this project.
Acknowledgements
Yaru exists thanks to pyinvoke, which was the main inspirer.
License
Yaru is licensed under the MIT license (LICENSE or https://opensource.org/licenses/MIT)
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 yaru-0.2.0.tar.gz.
File metadata
- Download URL: yaru-0.2.0.tar.gz
- Upload date:
- Size: 24.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d5404d976a33d87c27daad878f781273efb723b9719230877854e300dae6738
|
|
| MD5 |
5befa6b97db60ef1e62651b7d9221f58
|
|
| BLAKE2b-256 |
fa41c7897972e96c34cfa720844870adbb6355512313f77899396b4dd9353084
|
Provenance
The following attestation bundles were made for yaru-0.2.0.tar.gz:
Publisher:
release.yml on c0dearm/yaru
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yaru-0.2.0.tar.gz -
Subject digest:
6d5404d976a33d87c27daad878f781273efb723b9719230877854e300dae6738 - Sigstore transparency entry: 186516820
- Sigstore integration time:
-
Permalink:
c0dearm/yaru@df5bf105fa9f4503e762d04ab3f2d4a14bd4245b -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/c0dearm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@df5bf105fa9f4503e762d04ab3f2d4a14bd4245b -
Trigger Event:
release
-
Statement type:
File details
Details for the file yaru-0.2.0-py3-none-any.whl.
File metadata
- Download URL: yaru-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fc331cb2079b11fc2aaedd56c4669dd439fd12fb775dee3a2951b15bb448255
|
|
| MD5 |
05a89c9adb97e36980f7d9070469e845
|
|
| BLAKE2b-256 |
353e4e5113670756e627bee1e25bd3e84f63d99bda33be63283cd3ca49c86484
|
Provenance
The following attestation bundles were made for yaru-0.2.0-py3-none-any.whl:
Publisher:
release.yml on c0dearm/yaru
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yaru-0.2.0-py3-none-any.whl -
Subject digest:
2fc331cb2079b11fc2aaedd56c4669dd439fd12fb775dee3a2951b15bb448255 - Sigstore transparency entry: 186516823
- Sigstore integration time:
-
Permalink:
c0dearm/yaru@df5bf105fa9f4503e762d04ab3f2d4a14bd4245b -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/c0dearm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@df5bf105fa9f4503e762d04ab3f2d4a14bd4245b -
Trigger Event:
release
-
Statement type: