summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Dolgov <ivan@dolgov.fi>2019-03-16 15:14:18 +0200
committerIvan Dolgov <ivan@dolgov.fi>2019-03-16 15:33:28 +0200
commit227c1ae67bb80a5e9b9036a9bdb9f11be073669f (patch)
tree66ed50756e86a265c8bf08d0493bcc466c83d026
parent01bdba935a667e8c1606d6d040086488c82b0e38 (diff)
downloadickapi-227c1ae67bb80a5e9b9036a9bdb9f11be073669f.tar.gz
Initial setupivan/initial
-rw-r--r--.pylintrc14
-rw-r--r--Makefile28
-rw-r--r--NEWS16
-rw-r--r--README70
-rw-r--r--foo1
-rw-r--r--gunicorn.conf7
-rw-r--r--ickapi/__init__.py6
-rw-r--r--ickapi/app.py17
-rw-r--r--ickapi/main.py38
-rw-r--r--ickapi/routes.py12
-rw-r--r--ickapi/version.py9
-rw-r--r--ickapi/version_view.py16
-rw-r--r--requirements.txt14
-rw-r--r--setup.py45
14 files changed, 291 insertions, 2 deletions
diff --git a/.pylintrc b/.pylintrc
new file mode 100644
index 0000000..1a205cd
--- /dev/null
+++ b/.pylintrc
@@ -0,0 +1,14 @@
+[MASTER]
+persistent=no
+
+[MESSAGES CONTROL]
+disable=
+ invalid-name,
+ no-self-use,
+ redefined-variable-type,
+ too-few-public-methods,
+ too-many-public-methods,
+ unused-argument,
+
+[SIMILARITIES]
+min-similarity-lines=999
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e7ec035
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,28 @@
+ENV_BIN=env/bin
+
+all: run
+
+env:
+ python3 -m venv env
+ ${ENV_BIN}/pip install --upgrade pip pip-tools setuptools
+ ${ENV_BIN}/pip install -e ".[tests]"
+ ${ENV_BIN}/pip install -e .
+
+lint:
+ pycodestyle ickapi
+ pylint -j0 -d missing-docstring ickapi
+
+test: lint
+
+run:
+ gunicorn --config gunicorn.conf --reload ickapi.main:app
+
+clean:
+ rm -rf dist/ ickapi.egg-info/
+ find . -type f -name "*~" -exec rm -f {} \;
+ find . -type d -name "__pycache__" -prune -exec rm -rf {} \;
+
+reset: clean
+ rm -rf env/
+
+.PHONY: all env lint test run clean reset
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..2ca6f47
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,16 @@
+Ick API NEWS
+============
+
+Release notes for Ick API. This project follows [Semantic
+Versioning][].
+
+[Semantic Versioning]: http://semver.org/spec/v2.0.0.html
+
+0.1.0+git (unreleased)
+----------------------
+
+New features:
+
+* Initial project setup.
+
+* Version endpoint.
diff --git a/README b/README
index dd47f73..187cbfe 100644
--- a/README
+++ b/README
@@ -1 +1,69 @@
-This will be the ick API
+README for ick API
+==================
+
+Ick API is a RESTful HTTP API/facade for [ick][] frontend(s).
+
+[ick]: https://ick.liw.fi/
+
+Dependencies
+------------
+
+Ick API is written in Python 3.5 and depends on following tools and libraries:
+
+* [aiohttp][]
+* [Gunicorn][]
+* [make][]
+* [pycodestyle][]
+* [pydocstyle][]
+* [pylint][]
+* [pytest][]
+
+[aiohttp]: http://aiohttp.readthedocs.io/
+[Gunicorn]: http://gunicorn.org/
+[make]: https://www.gnu.org/software/make/
+[pycodestyle]: http://pycodestyle.pycqa.org/
+[pydocstyle]: http://www.pydocstyle.org/
+[pylint]: https://www.pylint.org/
+[pytest]: https://www.pytest.org/
+
+Usage
+-----
+
+FIXME
+
+Development
+-----------
+
+FIXME
+
+Releasing
+---------
+
+FIXME
+
+Deployment
+----------
+
+FIXME
+
+License
+-------
+
+Ick API in its entirety is copyright by its authors, and released under
+the GNU Affero General Public Licence, version 3, or later.
+
+ Ick API, a RESTful HTTP API/facade for Ick CI frontends
+ Copyright (C) 2019 Ivan Dolgov, Pyry Heiskanen
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/foo b/foo
deleted file mode 100644
index 257cc56..0000000
--- a/foo
+++ /dev/null
@@ -1 +0,0 @@
-foo
diff --git a/gunicorn.conf b/gunicorn.conf
new file mode 100644
index 0000000..81c8aa1
--- /dev/null
+++ b/gunicorn.conf
@@ -0,0 +1,7 @@
+bind = '0.0.0.0:8080'
+workers = 1
+worker_class = 'aiohttp.worker.GunicornWebWorker'
+errorlog = '-'
+accesslog = '-'
+loglevel = 'info'
+pidfile = '/tmp/ickapi.pid'
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__})
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..ee23afb
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,14 @@
+#
+# This file is autogenerated by pip-compile
+# To update, run:
+#
+# pip-compile
+#
+aiohttp==3.5.4
+async-timeout==3.0.1 # via aiohttp
+attrs==19.1.0 # via aiohttp
+chardet==3.0.4 # via aiohttp
+gunicorn==19.9.0
+idna==2.8 # via yarl
+multidict==4.5.2 # via aiohttp, yarl
+yarl==1.3.0 # via aiohttp
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..30bf11c
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python3
+
+import setuptools
+
+
+with open('ickapi/version.py', 'r') as f:
+ exec(f.read())
+
+with open('README', 'r') as f:
+ long_description = f.read()
+
+setuptools.setup(
+ name='ickapi',
+ version=__version__,
+ description='Ick API, a RESTful HTTP API/facade for Ick CI frontends',
+ long_description=long_description,
+ long_description_content_type='text/markdown',
+ url='http://git.liw.fi/ickapi/',
+ author='Ivan Dolgov',
+ author_email='ivan@dolgov.fi',
+ license='GPLv3+',
+ packages=setuptools.find_packages(exclude=['tests']),
+ python_requires='>=3.6',
+ install_requires=[
+ 'aiohttp',
+ 'gunicorn',
+ ],
+ extras_require={
+ 'tests': [
+ 'pycodestyle',
+ 'pydocstyle',
+ 'pylint',
+ 'pytest',
+ ]
+ },
+ classifiers=[
+ 'Development Status :: 3 - Alpha',
+ 'License :: OSI Approved :: '
+ + 'GNU General Public License v3 or later (GPLv3+)',
+ 'Environment :: Web Environment',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.6',
+ 'Operating System :: POSIX :: Linux',
+ ],
+)