# Python Tools Scripts
This is a tool, similar to [invoke](https://www.pyinvoke.org).
It's more recent and uses [argparse](https://docs.python.org/3/library/argparse.html) under the hood
and some additional magic to define the CLI arguments.
To use it, you must have a `tools` package in your repository root.
On your `tools/__init__.py` import your scripts and *Python Tools Scripts* will add them to it's CLI.
## An Example Script `tools/vm.py`
```python
"""
These commands are used to create/destroy VMs, sync the local checkout
to the VM and to run commands on the VM.
"""
from ptscripts import Context, command_group
# Define the command group
vm = command_group(name="vm", help="VM Related Commands", description=__doc__)
@vm.command(
arguments={
"name": {
"help": "The VM Name",
"metavar": "VM_NAME",
"choices": list(AMIS),
},
"key_name": {
"help": "The SSH key name.",
},
"instance_type": {
"help": "The instance type to use.",
},
"region": {
"help": "The AWS regsion.",
},
}
)
def create(
ctx: Context,
name: str,
key_name: str = None,
instance_type: str = None,
region: str = "eu-central-1",
):
"""
Create VM.
"""
vm = VM(ctx=ctx, name=name)
vm.create(region_name=region, key_name=key_name, instance_type=instance_type)
@vm.command(
arguments={
"name": {
"help": "The VM Name",
"metavar": "VM_NAME",
},
}
)
def destroy(ctx: Context, name: str):
"""
Destroy VM.
"""
vm = VM(ctx=ctx, name=name)
vm.destroy()
```
The, on your repository root, run:
```
❯ tools -h
usage: tools [-h] [--debug] {vm} ...
Python Tools Scripts
optional arguments:
-h, --help show this help message and exit
--debug, -d Show debug messages
Commands:
{vm}
vm VM Related Commands
These tools are discovered under `<repo-root>/tools`.
```
```
❯ tools vm -h
usage: tools vm [-h] {create,destroy} ...
These commands are used to create/destroy VMs, sync the local checkout to the VM and to run commands on the VM.
optional arguments:
-h, --help show this help message and exit
Commands:
{create,destroy}
create Create VM.
destroy Destroy VM.
```
Raw data
{
"_id": null,
"home_page": "https://github.com/s0undt3ch/python-tools-scripts",
"name": "python-tools-scripts",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "",
"author": "Pedro Algarvio",
"author_email": "pedro@algarvio.me",
"download_url": "https://files.pythonhosted.org/packages/18/4d/9aae16821648c0019e4b989a216548a56d4e3af9ce3a8e711802e873cae2/python-tools-scripts-0.20.5.tar.gz",
"platform": "unix",
"description": "# Python Tools Scripts\n\nThis is a tool, similar to [invoke](https://www.pyinvoke.org).\nIt's more recent and uses [argparse](https://docs.python.org/3/library/argparse.html) under the hood\nand some additional magic to define the CLI arguments.\n\nTo use it, you must have a `tools` package in your repository root.\nOn your `tools/__init__.py` import your scripts and *Python Tools Scripts* will add them to it's CLI.\n\n## An Example Script `tools/vm.py`\n\n```python\n\"\"\"\nThese commands are used to create/destroy VMs, sync the local checkout\nto the VM and to run commands on the VM.\n\"\"\"\n\nfrom ptscripts import Context, command_group\n\n# Define the command group\nvm = command_group(name=\"vm\", help=\"VM Related Commands\", description=__doc__)\n\n\n@vm.command(\n arguments={\n \"name\": {\n \"help\": \"The VM Name\",\n \"metavar\": \"VM_NAME\",\n \"choices\": list(AMIS),\n },\n \"key_name\": {\n \"help\": \"The SSH key name.\",\n },\n \"instance_type\": {\n \"help\": \"The instance type to use.\",\n },\n \"region\": {\n \"help\": \"The AWS regsion.\",\n },\n }\n)\ndef create(\n ctx: Context,\n name: str,\n key_name: str = None,\n instance_type: str = None,\n region: str = \"eu-central-1\",\n):\n \"\"\"\n Create VM.\n \"\"\"\n vm = VM(ctx=ctx, name=name)\n vm.create(region_name=region, key_name=key_name, instance_type=instance_type)\n\n\n@vm.command(\n arguments={\n \"name\": {\n \"help\": \"The VM Name\",\n \"metavar\": \"VM_NAME\",\n },\n }\n)\ndef destroy(ctx: Context, name: str):\n \"\"\"\n Destroy VM.\n \"\"\"\n vm = VM(ctx=ctx, name=name)\n vm.destroy()\n```\n\nThe, on your repository root, run:\n\n```\n\u276f tools -h\nusage: tools [-h] [--debug] {vm} ...\n\nPython Tools Scripts\n\noptional arguments:\n -h, --help show this help message and exit\n --debug, -d Show debug messages\n\nCommands:\n {vm}\n vm VM Related Commands\n\nThese tools are discovered under `<repo-root>/tools`.\n```\n\n```\n\u276f tools vm -h\nusage: tools vm [-h] {create,destroy} ...\n\nThese commands are used to create/destroy VMs, sync the local checkout to the VM and to run commands on the VM.\n\noptional arguments:\n -h, --help show this help message and exit\n\nCommands:\n {create,destroy}\n create Create VM.\n destroy Destroy VM.\n```\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "Python Tools Scripts",
"version": "0.20.5",
"project_urls": {
"Documentation": "https://python-tools-scripts.readthedocs.io",
"Homepage": "https://github.com/s0undt3ch/python-tools-scripts",
"Source": "https://github.com/s0undt3ch/python-tools-scripts",
"Tracker": "https://github.com/s0undt3ch/python-tools-scripts/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9d7fcb725bf93405f0a7f8e0840890674820cf6407f097ad52b13926cb9e42b5",
"md5": "6b801ad23a9afdc55ef08cef8a8df8ce",
"sha256": "a2c88c2d14537432ed0b0513f8025e2f67b2a5da8b00d465a2ae2de7e7dd6b08"
},
"downloads": -1,
"filename": "python_tools_scripts-0.20.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6b801ad23a9afdc55ef08cef8a8df8ce",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 24443,
"upload_time": "2024-02-29T10:15:23",
"upload_time_iso_8601": "2024-02-29T10:15:23.282029Z",
"url": "https://files.pythonhosted.org/packages/9d/7f/cb725bf93405f0a7f8e0840890674820cf6407f097ad52b13926cb9e42b5/python_tools_scripts-0.20.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "184d9aae16821648c0019e4b989a216548a56d4e3af9ce3a8e711802e873cae2",
"md5": "d7acf1d3f0c4178c5119659a173d5012",
"sha256": "c2a3ffb6a0ec6ccb3cfe0bee1ae73447d3ea4ba7583b07fa219d2dddaff4a36e"
},
"downloads": -1,
"filename": "python-tools-scripts-0.20.5.tar.gz",
"has_sig": false,
"md5_digest": "d7acf1d3f0c4178c5119659a173d5012",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 31155,
"upload_time": "2024-02-29T10:15:24",
"upload_time_iso_8601": "2024-02-29T10:15:24.889291Z",
"url": "https://files.pythonhosted.org/packages/18/4d/9aae16821648c0019e4b989a216548a56d4e3af9ce3a8e711802e873cae2/python-tools-scripts-0.20.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-29 10:15:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "s0undt3ch",
"github_project": "python-tools-scripts",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "python-tools-scripts"
}