more-click


Namemore-click JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/cthoyt/more_click
SummaryMore click.
upload_time2022-12-06 11:45:11
maintainerCharles Tapley Hoyt
docs_urlNone
authorCharles Tapley Hoyt
requires_python>=3.7
licenseMIT
keywords databases biological databases biomedical databases
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # more_click

<a href="https://pypi.org/project/more_click">
    <img alt="PyPI" src="https://img.shields.io/pypi/v/more_click" />
</a>
<a href="https://pypi.org/project/more_click">
    <img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/more_click" />
</a>
<a href="https://github.com/cthoyt/more_click/blob/main/LICENSE">
    <img alt="PyPI - License" src="https://img.shields.io/pypi/l/more_click" />
</a>
<a href="https://zenodo.org/badge/latestdoi/319609575">
    <img src="https://zenodo.org/badge/319609575.svg" alt="DOI">
</a>

Extra stuff for click I use in basically every repo

## More Options

The module `more_click.options` has several options (pre-defined instances of `click.option()`) that I use often. First,
`verbose_option` makes it easy to adjust the logger of your package using `-v`.

There are also several that are useful for web stuff, including

| Name                     | Type | Flag     |
| ------------------------ | ---- | -------- |
| `more_click.host_option` | str  | `--host` |
| `more_click.port_option` | str  | `--port` |

## Web Tools

In many packages, I've included a Flask web application in `wsgi.py`. I usually use the following form inside `cli.py`
file to import the web application and keep it insulated from other package-related usages:

```python
# cli.py
import click
from more_click import host_option, port_option


@click.command()
@host_option
@port_option
def web(host: str, port: str):
    from .wsgi import app  # modify to point to your module-level flask.Flask instance
    app.run(host=host, port=port)


if __name__ == '__main__':
    web()
```

However, sometimes I want to make it possible to run via `gunicorn` from the CLI, so I would use the following
extensions to automatically determine if it should be run with Flask's development server or gunicorn.

```python
# cli.py
import click
from more_click import host_option, port_option, with_gunicorn_option, workers_option, run_app


@click.command()
@host_option
@port_option
@with_gunicorn_option
@workers_option
def web(host: str, port: str, with_gunicorn: bool, workers: int):
    from .wsgi import app  # modify to point to your module-level flask.Flask instance
    run_app(app=app, with_gunicorn=with_gunicorn, host=host, port=port, workers=workers)


if __name__ == '__main__':
    web()
```

For ultimate lazy mode, I've written a wrapper around the second:

```python
# cli.py
from more_click import make_web_command

web = make_web_command('my_package_name.wsgi:app')

if __name__ == '__main__':
    web()
```

This uses a standard `wsgi`-style string to locate the app, since you don't want to be eagerly importing the app in your
CLI since it might rely on optional dependencies like Flask. If your CLI has other stuff, you can include the web
command in a group like:

```python
# cli.py
import click
from more_click import make_web_command


@click.group()
def main():
    """My awesome CLI."""


make_web_command('my_package_name.wsgi:app', group=main)

if __name__ == '__main__':
    main()
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cthoyt/more_click",
    "name": "more-click",
    "maintainer": "Charles Tapley Hoyt",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "cthoyt@gmail.com",
    "keywords": "databases,biological databases,biomedical databases",
    "author": "Charles Tapley Hoyt",
    "author_email": "cthoyt@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cf/c7/da345a948fb09129c524e81209c32c07c56f5e30786b973116247c4eba61/more_click-0.1.2.tar.gz",
    "platform": null,
    "description": "# more_click\n\n<a href=\"https://pypi.org/project/more_click\">\n    <img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/more_click\" />\n</a>\n<a href=\"https://pypi.org/project/more_click\">\n    <img alt=\"PyPI - Python Version\" src=\"https://img.shields.io/pypi/pyversions/more_click\" />\n</a>\n<a href=\"https://github.com/cthoyt/more_click/blob/main/LICENSE\">\n    <img alt=\"PyPI - License\" src=\"https://img.shields.io/pypi/l/more_click\" />\n</a>\n<a href=\"https://zenodo.org/badge/latestdoi/319609575\">\n    <img src=\"https://zenodo.org/badge/319609575.svg\" alt=\"DOI\">\n</a>\n\nExtra stuff for click I use in basically every repo\n\n## More Options\n\nThe module `more_click.options` has several options (pre-defined instances of `click.option()`) that I use often. First,\n`verbose_option` makes it easy to adjust the logger of your package using `-v`.\n\nThere are also several that are useful for web stuff, including\n\n| Name                     | Type | Flag     |\n| ------------------------ | ---- | -------- |\n| `more_click.host_option` | str  | `--host` |\n| `more_click.port_option` | str  | `--port` |\n\n## Web Tools\n\nIn many packages, I've included a Flask web application in `wsgi.py`. I usually use the following form inside `cli.py`\nfile to import the web application and keep it insulated from other package-related usages:\n\n```python\n# cli.py\nimport click\nfrom more_click import host_option, port_option\n\n\n@click.command()\n@host_option\n@port_option\ndef web(host: str, port: str):\n    from .wsgi import app  # modify to point to your module-level flask.Flask instance\n    app.run(host=host, port=port)\n\n\nif __name__ == '__main__':\n    web()\n```\n\nHowever, sometimes I want to make it possible to run via `gunicorn` from the CLI, so I would use the following\nextensions to automatically determine if it should be run with Flask's development server or gunicorn.\n\n```python\n# cli.py\nimport click\nfrom more_click import host_option, port_option, with_gunicorn_option, workers_option, run_app\n\n\n@click.command()\n@host_option\n@port_option\n@with_gunicorn_option\n@workers_option\ndef web(host: str, port: str, with_gunicorn: bool, workers: int):\n    from .wsgi import app  # modify to point to your module-level flask.Flask instance\n    run_app(app=app, with_gunicorn=with_gunicorn, host=host, port=port, workers=workers)\n\n\nif __name__ == '__main__':\n    web()\n```\n\nFor ultimate lazy mode, I've written a wrapper around the second:\n\n```python\n# cli.py\nfrom more_click import make_web_command\n\nweb = make_web_command('my_package_name.wsgi:app')\n\nif __name__ == '__main__':\n    web()\n```\n\nThis uses a standard `wsgi`-style string to locate the app, since you don't want to be eagerly importing the app in your\nCLI since it might rely on optional dependencies like Flask. If your CLI has other stuff, you can include the web\ncommand in a group like:\n\n```python\n# cli.py\nimport click\nfrom more_click import make_web_command\n\n\n@click.group()\ndef main():\n    \"\"\"My awesome CLI.\"\"\"\n\n\nmake_web_command('my_package_name.wsgi:app', group=main)\n\nif __name__ == '__main__':\n    main()\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "More click.",
    "version": "0.1.2",
    "split_keywords": [
        "databases",
        "biological databases",
        "biomedical databases"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "169a1ea214448f83202d7ce860077f6a",
                "sha256": "f6387af37ef7e7423bd94b72a81a53c79c5086a3bfe5cc035da534ff0c2a0a9e"
            },
            "downloads": -1,
            "filename": "more_click-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "169a1ea214448f83202d7ce860077f6a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6680,
            "upload_time": "2022-12-06T11:45:08",
            "upload_time_iso_8601": "2022-12-06T11:45:08.907508Z",
            "url": "https://files.pythonhosted.org/packages/ad/8e/4e25da8883c5d661eaf4225a951046b8f4466e75eadb8594e204550b3179/more_click-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "cb1e412ce364d9f752accf3e920cacff",
                "sha256": "085da66d5a9b823c5d912a888dca1fa0c8b3a14ed1b21ea9c8a1b814857a3981"
            },
            "downloads": -1,
            "filename": "more_click-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "cb1e412ce364d9f752accf3e920cacff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8040,
            "upload_time": "2022-12-06T11:45:11",
            "upload_time_iso_8601": "2022-12-06T11:45:11.395010Z",
            "url": "https://files.pythonhosted.org/packages/cf/c7/da345a948fb09129c524e81209c32c07c56f5e30786b973116247c4eba61/more_click-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-06 11:45:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "cthoyt",
    "github_project": "more_click",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "more-click"
}
        
Elapsed time: 0.01594s