ayo


Nameayo JSON
Version 0.6 PyPI version JSON
download
home_page
SummaryRun & Create Python 'create app' scripts with ease.
upload_time2023-08-29 10:47:20
maintainer
docs_urlNone
author
requires_python>=3
licenseMIT License Copyright (c) 2023 AWeirdScratcher Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ayo create-app create app cli
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ayo

Run Python "create app" scripts from the web and GitHub repositories.

## Installation

```ps
$ pip install --upgrade ayo
```

## Install & Run A Script

To install and run script(s), you can use the `ayo i` command (which means `install`).

You can either run scripts from GitHub or run them locally from a specific directory.

```ps
$ ayo i @username/repo @username/repo[branch] dir-name
```

## Creating Your Script

To create your script, try:

```ps
$ ayo new
```

Two files will be generated: `ayo.config.json` and `ayo-script.py`. Currently, `ayo` itself provides two built-in utilities:

- Template: Used to create an app from a template folder or do it manually
- Steps: Represents steps for your application, and caches previous data even when canceled.

First, let's take a look at `ayo.config.json`. This configuration JSON file determines which file(s) `ayo` needs to run. Below is the default content that was generated using the `new` command:

```json
{
    "bin": "ayo-script.py",
    "with": [],
    "before-scripts": []
}
```

- `bin`: The file that runs the script. Think of it as `main.py`
- `with`: The files to also contain when downloading this from GitHub. Usually used when the `bin` file requires modules. This field should only contain `.py` files. Optional.
- `before-scripts`: Scripts to run before running the `bin` file. Optional.

Then, take a look at `ayo-script.py`. You should see the default script:

```python
#!/usr/bin/python

from ayo import Template, true_or_false

yn = input("Can I install something for you?")
if not true_or_false(yn):
    exit(1)

Template({
    "main.py": "# surprise! new app!"
}).install()
```

Decent code! But let's twist it a little bit: let's edit it so we can try out the `Steps` and `Template` feature!

It goes something like this:

```python
#!/usr/bin/python

from ayo import Steps

steps = Steps()

@steps.first # first step
def hello_world():
    print("Hello, World!")

@steps.then # then...
def ask_for_install(data):
    # 'data': data returned from the previous function
    # in this case, None!
    return input("Can I install something for you?")

@steps.then
def write_or_exit(data: str):
    # the 'data' is given from the 'input()'
    if data.lower() != "yes":
        exit(1)

    Template({
        "main.py": "# surprise! new app!",
        "another-dir": {
            "README.md": "More content!"
        }
    }).install("new-app")

steps.start() # start!
```

With `Steps`, whenever the user sneakly (or maybe they just want to go out for a bit) pressed `^C` which causes `KeyboardInterrupt`, the program writes a new file (`_ayo$cache.py`) for cache-storing so that the next time they can quickly pick up from where they left off and continue their journey!

Let's try out our freshly made script by running:

```ps
$ ayo run
```

## Available Commands

To check the available commands, run:

```ps
$ ayo --help
```

## Reference

### Template

Represents an ayo script template.

Args:

- contents (`str` | dict[str, Any]): The contents. Could be a `str` representing the directory to use as a template or a directory dictionary.

To use `contents` as `str`, you'll need a directory called `.ayo-templates`. You can define templates here. See the below file tree example:

```
.ayo-templates/
├─ template-a/
│  ├─ ... files & dirs
│
├─ template-b/
│  ├─ ... files & dirs
│
├─ .../
```

To use the templates, simply use:

```python
from ayo import Template

Template("template-a").install("app-directory")
Template("template-b").install("app-directory")
```

In some occasions, you might want to ignore some files or directories from the template. To do so, pass in the `ignores` parameter:

```python
Template("template-a").install(
    "app-directory",
    ignores={
        "unwanted-dir": ..., # use '...' here
        ".gitignore": ...,
        "venv": {
            "bin": ...
        }
    }
)
```

As the name implies, "directory dictionaries" are just plain old Python dictionaries that work like file trees. `ayo` supports them!

```python
from ayo import Template

Template({
    "main.py": "# very normal main.py",
    "venv": {
        "bin": {
            "README.md": "hahaha! this is the file content!"
        }
    }
}).install("app-directory")
```

Same as the above, you can ignore specific files and directories:

```python
Template({
    "main.py": "# very normal main.py",
    # ... existing code
}).install("app-directory", {
    "main.py": ..., # use '...' here
    ".gitignore": ...,

    "folders": {
        "work": {
            "too.txt": "WOW!"
        }
    }
})
```

### Steps

Represents steps.

Args:

- cache (`bool`, optional): Whether to cache (remember) data as completions or not, so that even if `KeyboardInterrupt` occurs, the next time when this script executes, we can get the previous data, and skip directly to the last step the user is on.

I personally don't like reading, but code is what I skip to.

Here's an example of the `Steps` class:

```python
from ayo import Steps

steps = Steps()

@steps.first # first step
def hello_world():
    print("Hello, World!")

@steps.then # then...
def ask_for_install(data):
    # 'data': data returned from the previous function
    # in this case, None!
    return input("Can I install something for you?")

@steps.then
def write_or_exit(data: str):
    # the 'data' is given from the 'input()'
    if data.lower() != "yes":
        exit(1)

    Template({
        "main.py": "# surprise! new app!",
        "another-dir": {
            "README.md": "More content!"
        }
    }).install("new-app")

steps.start() # start!
```

Now, whenever the user tries to `^C` or exit the program, `ayo` remembers everything... NO CRIMES ALLOWED!

If you're wondering how to remove the cache, simply run:

```ps
$ ayo clean-cache
```

### true\_or\_false (tof)

Checks whether the input provided by the user (Yn) is true or not.

This is useful for "parsing" (more like understanding) `Yn` user inputs.

Args:

- \_input (`str`): The input.
- false_if_unknown (`bool`, optional): Whether to return `False` if received unrecognized input or not.

```python
from ayo import tof # sneaky shortcut

a = "yes"
print(tof(a)) # -> True

b = "nope"
print(tof(b)) # -> False

c = "you'll never guess what i mean!!"

print(tof(c)) # -> False
print(tof(c, false_if_unknown=False)) # Error
```

Built by AWeirdScratcher (AWeirdDev). Right, I was bored.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ayo",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "ayo,create-app,create,app,cli",
    "author": "",
    "author_email": "AWeirdDev <aweirdscratcher@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/9e/38/ebe6079d814db999ce6c81878946114b87e29f545e9baa2ea8e64b2b21b6/ayo-0.6.tar.gz",
    "platform": null,
    "description": "# ayo\r\n\r\nRun Python \"create app\" scripts from the web and GitHub repositories.\r\n\r\n## Installation\r\n\r\n```ps\r\n$ pip install --upgrade ayo\r\n```\r\n\r\n## Install & Run A Script\r\n\r\nTo install and run script(s), you can use the `ayo i` command (which means `install`).\r\n\r\nYou can either run scripts from GitHub or run them locally from a specific directory.\r\n\r\n```ps\r\n$ ayo i @username/repo @username/repo[branch] dir-name\r\n```\r\n\r\n## Creating Your Script\r\n\r\nTo create your script, try:\r\n\r\n```ps\r\n$ ayo new\r\n```\r\n\r\nTwo files will be generated: `ayo.config.json` and `ayo-script.py`. Currently, `ayo` itself provides two built-in utilities:\r\n\r\n- Template: Used to create an app from a template folder or do it manually\r\n- Steps: Represents steps for your application, and caches previous data even when canceled.\r\n\r\nFirst, let's take a look at `ayo.config.json`. This configuration JSON file determines which file(s) `ayo` needs to run. Below is the default content that was generated using the `new` command:\r\n\r\n```json\r\n{\r\n    \"bin\": \"ayo-script.py\",\r\n    \"with\": [],\r\n    \"before-scripts\": []\r\n}\r\n```\r\n\r\n- `bin`: The file that runs the script. Think of it as `main.py`\r\n- `with`: The files to also contain when downloading this from GitHub. Usually used when the `bin` file requires modules. This field should only contain `.py` files. Optional.\r\n- `before-scripts`: Scripts to run before running the `bin` file. Optional.\r\n\r\nThen, take a look at `ayo-script.py`. You should see the default script:\r\n\r\n```python\r\n#!/usr/bin/python\r\n\r\nfrom ayo import Template, true_or_false\r\n\r\nyn = input(\"Can I install something for you?\")\r\nif not true_or_false(yn):\r\n    exit(1)\r\n\r\nTemplate({\r\n    \"main.py\": \"# surprise! new app!\"\r\n}).install()\r\n```\r\n\r\nDecent code! But let's twist it a little bit: let's edit it so we can try out the `Steps` and `Template` feature!\r\n\r\nIt goes something like this:\r\n\r\n```python\r\n#!/usr/bin/python\r\n\r\nfrom ayo import Steps\r\n\r\nsteps = Steps()\r\n\r\n@steps.first # first step\r\ndef hello_world():\r\n    print(\"Hello, World!\")\r\n\r\n@steps.then # then...\r\ndef ask_for_install(data):\r\n    # 'data': data returned from the previous function\r\n    # in this case, None!\r\n    return input(\"Can I install something for you?\")\r\n\r\n@steps.then\r\ndef write_or_exit(data: str):\r\n    # the 'data' is given from the 'input()'\r\n    if data.lower() != \"yes\":\r\n        exit(1)\r\n\r\n    Template({\r\n        \"main.py\": \"# surprise! new app!\",\r\n        \"another-dir\": {\r\n            \"README.md\": \"More content!\"\r\n        }\r\n    }).install(\"new-app\")\r\n\r\nsteps.start() # start!\r\n```\r\n\r\nWith `Steps`, whenever the user sneakly (or maybe they just want to go out for a bit) pressed `^C` which causes `KeyboardInterrupt`, the program writes a new file (`_ayo$cache.py`) for cache-storing so that the next time they can quickly pick up from where they left off and continue their journey!\r\n\r\nLet's try out our freshly made script by running:\r\n\r\n```ps\r\n$ ayo run\r\n```\r\n\r\n## Available Commands\r\n\r\nTo check the available commands, run:\r\n\r\n```ps\r\n$ ayo --help\r\n```\r\n\r\n## Reference\r\n\r\n### Template\r\n\r\nRepresents an ayo script template.\r\n\r\nArgs:\r\n\r\n- contents (`str` | dict[str, Any]): The contents. Could be a `str` representing the directory to use as a template or a directory dictionary.\r\n\r\nTo use `contents` as `str`, you'll need a directory called `.ayo-templates`. You can define templates here. See the below file tree example:\r\n\r\n```\r\n.ayo-templates/\r\n\u251c\u2500 template-a/\r\n\u2502  \u251c\u2500 ... files & dirs\r\n\u2502\r\n\u251c\u2500 template-b/\r\n\u2502  \u251c\u2500 ... files & dirs\r\n\u2502\r\n\u251c\u2500 .../\r\n```\r\n\r\nTo use the templates, simply use:\r\n\r\n```python\r\nfrom ayo import Template\r\n\r\nTemplate(\"template-a\").install(\"app-directory\")\r\nTemplate(\"template-b\").install(\"app-directory\")\r\n```\r\n\r\nIn some occasions, you might want to ignore some files or directories from the template. To do so, pass in the `ignores` parameter:\r\n\r\n```python\r\nTemplate(\"template-a\").install(\r\n    \"app-directory\",\r\n    ignores={\r\n        \"unwanted-dir\": ..., # use '...' here\r\n        \".gitignore\": ...,\r\n        \"venv\": {\r\n            \"bin\": ...\r\n        }\r\n    }\r\n)\r\n```\r\n\r\nAs the name implies, \"directory dictionaries\" are just plain old Python dictionaries that work like file trees. `ayo` supports them!\r\n\r\n```python\r\nfrom ayo import Template\r\n\r\nTemplate({\r\n    \"main.py\": \"# very normal main.py\",\r\n    \"venv\": {\r\n        \"bin\": {\r\n            \"README.md\": \"hahaha! this is the file content!\"\r\n        }\r\n    }\r\n}).install(\"app-directory\")\r\n```\r\n\r\nSame as the above, you can ignore specific files and directories:\r\n\r\n```python\r\nTemplate({\r\n    \"main.py\": \"# very normal main.py\",\r\n    # ... existing code\r\n}).install(\"app-directory\", {\r\n    \"main.py\": ..., # use '...' here\r\n    \".gitignore\": ...,\r\n\r\n    \"folders\": {\r\n        \"work\": {\r\n            \"too.txt\": \"WOW!\"\r\n        }\r\n    }\r\n})\r\n```\r\n\r\n### Steps\r\n\r\nRepresents steps.\r\n\r\nArgs:\r\n\r\n- cache (`bool`, optional): Whether to cache (remember) data as completions or not, so that even if `KeyboardInterrupt` occurs, the next time when this script executes, we can get the previous data, and skip directly to the last step the user is on.\r\n\r\nI personally don't like reading, but code is what I skip to.\r\n\r\nHere's an example of the `Steps` class:\r\n\r\n```python\r\nfrom ayo import Steps\r\n\r\nsteps = Steps()\r\n\r\n@steps.first # first step\r\ndef hello_world():\r\n    print(\"Hello, World!\")\r\n\r\n@steps.then # then...\r\ndef ask_for_install(data):\r\n    # 'data': data returned from the previous function\r\n    # in this case, None!\r\n    return input(\"Can I install something for you?\")\r\n\r\n@steps.then\r\ndef write_or_exit(data: str):\r\n    # the 'data' is given from the 'input()'\r\n    if data.lower() != \"yes\":\r\n        exit(1)\r\n\r\n    Template({\r\n        \"main.py\": \"# surprise! new app!\",\r\n        \"another-dir\": {\r\n            \"README.md\": \"More content!\"\r\n        }\r\n    }).install(\"new-app\")\r\n\r\nsteps.start() # start!\r\n```\r\n\r\nNow, whenever the user tries to `^C` or exit the program, `ayo` remembers everything... NO CRIMES ALLOWED!\r\n\r\nIf you're wondering how to remove the cache, simply run:\r\n\r\n```ps\r\n$ ayo clean-cache\r\n```\r\n\r\n### true\\_or\\_false (tof)\r\n\r\nChecks whether the input provided by the user (Yn) is true or not.\r\n\r\nThis is useful for \"parsing\" (more like understanding) `Yn` user inputs.\r\n\r\nArgs:\r\n\r\n- \\_input (`str`): The input.\r\n- false_if_unknown (`bool`, optional): Whether to return `False` if received unrecognized input or not.\r\n\r\n```python\r\nfrom ayo import tof # sneaky shortcut\r\n\r\na = \"yes\"\r\nprint(tof(a)) # -> True\r\n\r\nb = \"nope\"\r\nprint(tof(b)) # -> False\r\n\r\nc = \"you'll never guess what i mean!!\"\r\n\r\nprint(tof(c)) # -> False\r\nprint(tof(c, false_if_unknown=False)) # Error\r\n```\r\n\r\nBuilt by AWeirdScratcher (AWeirdDev). Right, I was bored.\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 AWeirdScratcher  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Run & Create Python 'create app' scripts with ease.",
    "version": "0.6",
    "project_urls": {
        "Bug Tracker": "https://github.com/AWeirdScratcher/ayo/issues",
        "Homepage": "https://github.com/AWeirdScratcher/ayo"
    },
    "split_keywords": [
        "ayo",
        "create-app",
        "create",
        "app",
        "cli"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9e38ebe6079d814db999ce6c81878946114b87e29f545e9baa2ea8e64b2b21b6",
                "md5": "4b147ec89068a9df9d0db0a48139ffee",
                "sha256": "553d5a559ef6ee916af1e20b0343e888c0cd2dda3949574156ebf596c182d783"
            },
            "downloads": -1,
            "filename": "ayo-0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "4b147ec89068a9df9d0db0a48139ffee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 17031,
            "upload_time": "2023-08-29T10:47:20",
            "upload_time_iso_8601": "2023-08-29T10:47:20.019849Z",
            "url": "https://files.pythonhosted.org/packages/9e/38/ebe6079d814db999ce6c81878946114b87e29f545e9baa2ea8e64b2b21b6/ayo-0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-29 10:47:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AWeirdScratcher",
    "github_project": "ayo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ayo"
}
        
Elapsed time: 1.32698s