diff options
author | Ivan Dolgov <ivan@dolgov.fi> | 2019-03-16 15:14:18 +0200 |
---|---|---|
committer | Ivan Dolgov <ivan@dolgov.fi> | 2019-03-16 15:33:28 +0200 |
commit | 227c1ae67bb80a5e9b9036a9bdb9f11be073669f (patch) | |
tree | 66ed50756e86a265c8bf08d0493bcc466c83d026 /ickapi | |
parent | 01bdba935a667e8c1606d6d040086488c82b0e38 (diff) | |
download | ickapi-227c1ae67bb80a5e9b9036a9bdb9f11be073669f.tar.gz |
Initial setupivan/initial
Diffstat (limited to 'ickapi')
-rw-r--r-- | ickapi/__init__.py | 6 | ||||
-rw-r--r-- | ickapi/app.py | 17 | ||||
-rw-r--r-- | ickapi/main.py | 38 | ||||
-rw-r--r-- | ickapi/routes.py | 12 | ||||
-rw-r--r-- | ickapi/version.py | 9 | ||||
-rw-r--r-- | ickapi/version_view.py | 16 |
6 files changed, 98 insertions, 0 deletions
diff --git a/ickapi/__init__.py b/ickapi/__init__.py new file mode 100644 index 0000000..84485a0 --- /dev/null +++ b/ickapi/__init__.py @@ -0,0 +1,6 @@ +"""Ick API package module.""" + +from .version import __version__ +from .app import create_app +from .routes import setup_routes +from .version_view import VersionView diff --git a/ickapi/app.py b/ickapi/app.py new file mode 100644 index 0000000..25ea649 --- /dev/null +++ b/ickapi/app.py @@ -0,0 +1,17 @@ +"""Web application module. + +Provides methods for creating and configuring aiohhtp web application. +""" + +import aiohttp + +import ickapi + + +def create_app(): + """Create a web app to be passed to a server.""" + app = aiohttp.web.Application() + + ickapi.setup_routes(app) + + return app diff --git a/ickapi/main.py b/ickapi/main.py new file mode 100644 index 0000000..c40bf22 --- /dev/null +++ b/ickapi/main.py @@ -0,0 +1,38 @@ +"""Main module. + +A web server application that can be passed to gunicorn. Also works as +standalone program (run from project root): + + python ickapi/main.py --host 127.0.0.1 --port 8080 +""" + +import argparse +import logging + +import aiohttp + +import ickapi + +DEFAULT_HOST = '127.0.0.1' +DEFAULT_PORT = 8080 + +app = ickapi.create_app() + + +def main(): + """Run a standalone development server.""" + logging.basicConfig(level=logging.INFO) + + parser = argparse.ArgumentParser() + parser.add_argument('--host', default=None) + parser.add_argument('--port', type=int, default=0) + + args = parser.parse_args() + host = args.host or DEFAULT_HOST + port = args.port or DEFAULT_PORT + + aiohttp.web.run_app(app, host=host, port=port) + + +if __name__ == '__main__': + main() diff --git a/ickapi/routes.py b/ickapi/routes.py new file mode 100644 index 0000000..3111cca --- /dev/null +++ b/ickapi/routes.py @@ -0,0 +1,12 @@ +"""Route module. + +All endpoints are added to the router here. +""" + +import ickapi + + +def setup_routes(app): + """Add endpoints to a router.""" + version = ickapi.VersionView() + app.router.add_get('/version', version.get_version) diff --git a/ickapi/version.py b/ickapi/version.py new file mode 100644 index 0000000..14baa36 --- /dev/null +++ b/ickapi/version.py @@ -0,0 +1,9 @@ +"""Version module. + +This module contains only project version info. It is used by setup.py +and version endpoint. + +Remember to update NEWS file too when bumping a version. +""" + +__version__ = '0.1.0+git' diff --git a/ickapi/version_view.py b/ickapi/version_view.py new file mode 100644 index 0000000..23f723a --- /dev/null +++ b/ickapi/version_view.py @@ -0,0 +1,16 @@ +"""Version view module. + +Contains `/version` endpoint implementation. +""" + +from aiohttp import web + +import ickapi + + +class VersionView: + """Endpoint methods.""" + + async def get_version(self, request): + """Return component versions.""" + return web.json_response({'api': ickapi.__version__}) |