From 62124b3c2fb0b6e3adf58157d802de693cdc5421 Mon Sep 17 00:00:00 2001 From: Nikolay Stanchev <ns17@it-innovation.soton.ac.uk> Date: Fri, 11 May 2018 12:08:22 +0100 Subject: [PATCH] [Issue #73] - structure of the CLMC service --- .coveragerc | 3 +++ .gitignore | 4 +++ CLMCservice/__init__.py | 10 +++++++ CLMCservice/tests.py | 1 + CLMCservice/views.py | 7 +++++ README.md | 41 +++++++++++++++++++++++++++- development.ini | 59 +++++++++++++++++++++++++++++++++++++++++ production.ini | 53 ++++++++++++++++++++++++++++++++++++ pytest.ini | 3 +++ setup.py | 33 ++++++++++++++++++----- 10 files changed, 206 insertions(+), 8 deletions(-) create mode 100644 .coveragerc create mode 100644 CLMCservice/__init__.py create mode 100644 CLMCservice/tests.py create mode 100644 CLMCservice/views.py create mode 100644 development.ini create mode 100644 production.ini create mode 100644 pytest.ini diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..a5040ab --- /dev/null +++ b/.coveragerc @@ -0,0 +1,3 @@ +[run] +source = CLMCservice +omit = CLMCservice/tests.py diff --git a/.gitignore b/.gitignore index 03f004a..6f78280 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ *egg-info* *git-commit-ref* ubuntu-xenial-16.04-cloudimg-console.log +.idea/ +*.egg +*.pyc +*$py.class diff --git a/CLMCservice/__init__.py b/CLMCservice/__init__.py new file mode 100644 index 0000000..b87c12f --- /dev/null +++ b/CLMCservice/__init__.py @@ -0,0 +1,10 @@ +from pyramid.config import Configurator + + +def main(global_config, **settings): + """ This function returns a Pyramid WSGI application.""" + + config = Configurator(settings=settings) + config.add_route('home', '/') + config.scan() + return config.make_wsgi_app() diff --git a/CLMCservice/tests.py b/CLMCservice/tests.py new file mode 100644 index 0000000..54f2941 --- /dev/null +++ b/CLMCservice/tests.py @@ -0,0 +1 @@ +# Specific tests related to the CLMC service \ No newline at end of file diff --git a/CLMCservice/views.py b/CLMCservice/views.py new file mode 100644 index 0000000..10a8d11 --- /dev/null +++ b/CLMCservice/views.py @@ -0,0 +1,7 @@ +from pyramid.view import view_config +from pyramid.response import Response + + +@view_config(route_name='home') +def my_view(request): + return Response("Hello world") diff --git a/README.md b/README.md index 0d9dbc7..8560bdd 100644 --- a/README.md +++ b/README.md @@ -119,4 +119,43 @@ If pytest is not installed, an easy solution is to use the Python Package Index `sudo apt-get install python3-pip` -`pip3 install pytest` \ No newline at end of file +`pip3 install pytest` + + +#### CLMC Service + +The CLMC service is implemented using the Pyramid framework. (currently under development) + +Before installing the CLMC service and its dependencies, it is recommended to use a virtual environment. To manage virtual +environments, **virtualenvwrapper** can be used. + +``` +pip install virtualenvwrapper +``` + +To create a virtual environment use the **mkvirtualenv** command: + +``` +mkvirtualenv CLMC +``` + +When created, you should already be set to use the new virtual environment, but to make sure of this use the **workon** command: + +``` +workon CLMC +``` + +Now, any installed libraries will be specificly installed in this environment only. To install and use the CLMC service +locally, the easiest thing to do is to use **pip** (make sure you are in the root folder of the project - ***flame-clmc***): + +``` +pip install -e . +``` + +Finally, start the service on localhost by using pyramid's **pserve**: + +``` +pserve development.ini --reload +``` + +You should now be able to see the 'Hello world' message when visiting **http://localhost:8080** in your browser. \ No newline at end of file diff --git a/development.ini b/development.ini new file mode 100644 index 0000000..0d37eed --- /dev/null +++ b/development.ini @@ -0,0 +1,59 @@ +### +# app configuration +# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + +[app:main] +use = egg:CLMCservice + +pyramid.reload_templates = true +pyramid.debug_authorization = false +pyramid.debug_notfound = false +pyramid.debug_routematch = false +pyramid.default_locale_name = en +pyramid.includes = pyramid_debugtoolbar +aggregator_running = false + +# By default, the toolbar only appears for clients from IP addresses +# '127.0.0.1' and '::1'. +# debugtoolbar.hosts = 127.0.0.1 ::1 + +### +# wsgi server configuration +### + +[server:main] +use = egg:waitress#main +listen = localhost:8080 + +### +# logging configuration +# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### + +[loggers] +keys = root, CLMCservice + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = INFO +handlers = console + +[logger_CLMCservice] +level = DEBUG +handlers = +qualname = CLMCservice + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s diff --git a/production.ini b/production.ini new file mode 100644 index 0000000..1331c1b --- /dev/null +++ b/production.ini @@ -0,0 +1,53 @@ +### +# app configuration +# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + +[app:main] +use = egg:CLMCservice + +pyramid.reload_templates = false +pyramid.debug_authorization = false +pyramid.debug_notfound = false +pyramid.debug_routematch = false +pyramid.default_locale_name = en + +### +# wsgi server configuration +### + +[server:main] +use = egg:waitress#main +listen = *:8080 + +### +# logging configuration +# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### + +[loggers] +keys = root, CLMCservice + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console + +[logger_CLMCservice] +level = WARN +handlers = +qualname = CLMCservice + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..d30f667 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +testpaths = CLMCservice +python_files = *.py diff --git a/setup.py b/setup.py index f015c18..d715b33 100644 --- a/setup.py +++ b/setup.py @@ -21,27 +21,46 @@ // Created for Project : FLAME """ -import os from setuptools import setup, find_packages -def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() +requires = [ + 'plaster_pastedeploy', + 'pyramid', + 'pyramid_debugtoolbar', + 'waitress', + 'influxdb', +] + +tests_require = [ + 'WebTest >= 1.3.1', # py3 compat + 'pytest', + 'pytest-cov', +] setup( - name = "clmctest", + name = "CLMCservice", version = "SNAPSHOT", author = "Michael Boniface", author_email = "mjb@it-innovation.soton.ac.uk", description = "FLAME CLMC Testing Module", + long_description="long description", license = "license", - keywords = "FLAME CLMC test", + keywords = "FLAME CLMC service test", packages=find_packages(exclude=["services"]), include_package_data=True, - package_data={'': ['git-commit-ref', '*.yml', '*.sh', '*.json', '*.conf']}, - long_description="long description", + install_requires=requires, + extras_require={ + 'testing': tests_require, + }, + package_data={'': ['git-commit-ref', '*.yml', '*.sh', '*.json', '*.conf']}, classifiers=[ "Development Status :: Alpha", "Topic :: FLAME Tests", "License :: ", ], + entry_points={ + 'paste.app_factory': [ + 'main = CLMCservice:main', + ], + }, ) \ No newline at end of file -- GitLab