More click.
Project description
more_click
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:
# 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.
# 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:
# 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:
# 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()
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
File details
Details for the file more_click-0.0.5.tar.gz
.
File metadata
- Download URL: more_click-0.0.5.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01c60865fdffeefaad35cc93b1b5ec11e2c30d639bb90c2131a971fe97023004 |
|
MD5 | 929538b385b12878a7cabb8ddd8465de |
|
BLAKE2b-256 | d111480fca64c69663095a64d7e038aabc7890fe40837a7536e65f28dfe2beea |
File details
Details for the file more_click-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: more_click-0.0.5-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e43bd7c3b5aa880b864aaa319d4f27d8a6cf553db77bd91a56802879ccfd16f |
|
MD5 | 0402fa9f3dac299b5bae96cfdaebc6fd |
|
BLAKE2b-256 | 8f50674c173a2290b85ddc644e925e05c8057198140afd53208a4d4dd96ef8ed |