diff --git a/README.md b/README.md index 2c3b063..ecb97a2 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ pipenv install gunicorn ### Getting Started An example of the smallest Bobtail app ```python -from typing import Tuple, Optional, Dict from bobtail import BobTail, AbstractRoute, Request, Response class Images: @@ -33,20 +32,29 @@ routes = [ ] app = BobTail(routes=routes) - ``` ### Run ``` pipenv run gunicorn api:app ``` +### Options +To define port, static directory, template directory etc. you can +create a concrete version of the BaseOptions abstract class. See the [docs](https://bobtail.readthedocs.io/en/latest/) for more info. +```python +from bobtail.options import BaseOptions +class Options(BaseOptions): + PORT = 8001 + +app = Bobtail(Options) +``` ### Middleware Bobtail middleware #### Using third party middleware ```python -from bobttail_logger import BobtailLogger +from bobtail_logger import BobtailLogger app = Bobtail(routes=routes) diff --git a/bobtail/options.py b/bobtail/options.py index e2d16f9..0080e39 100644 --- a/bobtail/options.py +++ b/bobtail/options.py @@ -2,6 +2,24 @@ class BaseOptions(ABC): + """ + To define port, static directory, template directory etc. you can + create a concrete version of the BaseOptions abstract class. + For Example:: + + from bobtail.options import BaseOptions + + class Options(BaseOptions): + PORT = 8001 + + app = Bobtail(Options) + + """ + #: The port by default is set to `8000` PORT = 8000 + + #: The static directory relative path is set by default to `static` STATIC_DIR = "static" + + #: The template directory relative path is set by default to `templates` TEMPLATE_DIR = "templates" diff --git a/bobtail/wsgi.py b/bobtail/wsgi.py index 7e52e25..5955b1b 100644 --- a/bobtail/wsgi.py +++ b/bobtail/wsgi.py @@ -30,12 +30,17 @@ class BobTail: routes: List[Route] #: Options (Optional). See :class:`~BaseOptions` for option list. Base options - #: can be overriden & or set on a concrete BaseOptions instance. + #: can be overridden & or set on a concrete BaseOptions instance. #: For Example:: #: + #: from bobtail.options import BaseOptions + #: #: class Options(BaseOptions): - #: STATIC_DIR = "app/static" - #: TEMPLATE_DIR = "app/templates" + #: PORT = 8000 # set by default + #: STATIC_DIR = "app/static" # set by default + #: TEMPLATE_DIR = "app/templates" # set by default + #: + #: app = Bobtail(Options, routes=[]) #: options: BaseOptions diff --git a/docs/options.rst b/docs/options.rst new file mode 100644 index 0000000..2fa70c3 --- /dev/null +++ b/docs/options.rst @@ -0,0 +1,4 @@ +Options +======= +.. automodule:: bobtail.options + :members: diff --git a/tox.ini b/tox.ini index 32e6db0..ce0819b 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py310-dev, py311-dev +envlist = py310-dev, py311-dev, py312-dev [pytest]