From f0248dee52062295507cfc14c11b4fb1367db05b Mon Sep 17 00:00:00 2001 From: Stefano Cossu Date: Mon, 2 Apr 2018 23:17:46 -0500 Subject: [PATCH] Package software. * Add setup.py * Integrate with pytest-runner * Remove requirements_dev.txt * Rework console scripts to produce binaries with distro * Adapt travis.yml --- .travis.yml | 5 +- etc.defaults/gunicorn.py | 32 --------- etc.defaults/gunicorn.yml | 24 +++++++ fcrepo | 5 -- lsup-admin => lsup_admin.py | 1 - profiler.py | 6 +- requirements.txt | 12 +++- requirements_dev.txt | 6 -- server.py | 2 - setup.cfg | 6 ++ setup.py | 131 ++++++++++++++++++++++++++++++++++++ 11 files changed, 177 insertions(+), 53 deletions(-) delete mode 100644 etc.defaults/gunicorn.py create mode 100644 etc.defaults/gunicorn.yml delete mode 100755 fcrepo rename lsup-admin => lsup_admin.py (99%) delete mode 100644 requirements_dev.txt create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.travis.yml b/.travis.yml index 462e90b..e947e03 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ python: - "3.5" - "3.6" install: - - pip install -r requirements.txt - - coilmq& + - pip -e . script: -- pytest tests + - python setup.py test diff --git a/etc.defaults/gunicorn.py b/etc.defaults/gunicorn.py deleted file mode 100644 index 77c7264..0000000 --- a/etc.defaults/gunicorn.py +++ /dev/null @@ -1,32 +0,0 @@ -# See: http://docs.gunicorn.org/en/stable/settings.html - -# Directory where to store logs, PIDfile, etc. -_data_dir = 'data/' - -# Set app_mode to either 'prod', 'test' or 'dev'. -# 'prod' is normal running mode. 'test' is used for running test suites. -# 'dev' is similar to normal mode but with reload and debug enabled. -_app_mode = 'dev' - - -bind = "0.0.0.0:8000" -workers = 4 -worker_class = 'gevent' -max_requests = 512 - -#user = "user" -#group = "group" - -raw_env = 'APP_MODE={}'.format(_app_mode) - -# Set this to the directory containing logs, etc. -# The path must end with a slash. -#chdir = "/usr/local/lakesuperior/" - -daemon = _app_mode=='prod' -pidfile = _data_dir + "run/fcrepo.pid" -reload = _app_mode=='dev' - -accesslog = _data_dir + "log/gunicorn-access.log" -errorlog = _data_dir + "log/gunicorn-error.log" - diff --git a/etc.defaults/gunicorn.yml b/etc.defaults/gunicorn.yml new file mode 100644 index 0000000..68467c8 --- /dev/null +++ b/etc.defaults/gunicorn.yml @@ -0,0 +1,24 @@ +# Set up main GUnicorn options. +# See: http://docs.gunicorn.org/en/stable/settings.html + +# Commented values are the application defaults. + +# Directory where the WSGI server data are stored. +data_dir: 'data' + +# Set app_mode to either 'prod', 'test' or 'dev'. +# 'prod' is normal running mode. 'test' is used for running test suites. +# 'dev' is similar to normal mode but with reload and debug enabled. +app_mode: 'dev' + +#listen_addr: '0.0.0.0' +#listen_port: 8000 +#workers: 4 +#worker_class: 'gevent' +#max_requests: 512 + +#user: '' +#group: '' + +#preload_app: True + diff --git a/fcrepo b/fcrepo deleted file mode 100755 index 6ea9361..0000000 --- a/fcrepo +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -default_conf_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/etc.defaults" -conf_dir=${FCREPO_CONFIG_DIR:-$default_conf_dir} - -gunicorn -c "${conf_dir}/gunicorn.py" server:fcrepo --preload diff --git a/lsup-admin b/lsup_admin.py similarity index 99% rename from lsup-admin rename to lsup_admin.py index fd41331..99ab9ec 100755 --- a/lsup-admin +++ b/lsup_admin.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python import click import click_log import json diff --git a/profiler.py b/profiler.py index 7ffa084..574aa13 100755 --- a/profiler.py +++ b/profiler.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import logging from logging.config import dictConfig from werkzeug.contrib.profiler import ProfilerMiddleware @@ -18,9 +16,11 @@ from lakesuperior.app import create_app -if __name__ == '__main__': +def run(): fcrepo = create_app(config['application']) fcrepo.wsgi_app = ProfilerMiddleware(fcrepo.wsgi_app, **options) fcrepo.config['PROFILE'] = True fcrepo.run(debug = True) +if __name__ == '__main__': + run() diff --git a/requirements.txt b/requirements.txt index 73047cc..25bcfa9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,24 @@ CoilMQ==1.0.1 Flask==0.12.2 HiYaPyCo==0.4.11 +Pillow==4.3.0 PyYAML==3.12 arrow==0.10.0 -click==6.7 click-log==0.2.1 +click==6.7 gevent==1.2.2 gunicorn==19.7.1 lmdb==0.93 +numpy==1.14.1 +pytest-flask==0.10.0 +pytest==3.2.2 rdflib==4.2.2 requests-toolbelt==0.8.0 requests==2.18.4 +sphinx-rtd-theme==0.2.4 stomp.py==4.1.20 +wheel==0.30.0a0 + +# Uncomment this and remove all above when the project will be in PyPI. +#--index-url https://pypi.python.org/lakesuperior/ +#-e . diff --git a/requirements_dev.txt b/requirements_dev.txt deleted file mode 100644 index 17eb83f..0000000 --- a/requirements_dev.txt +++ /dev/null @@ -1,6 +0,0 @@ -Pillow==4.3.0 -numpy==1.14.1 -pytest==3.2.2 -pytest-flask==0.10.0 -sphinx-rtd-theme==0.2.4 -wheel==0.30.0a0 diff --git a/server.py b/server.py index 23bee3d..b1fbb19 100755 --- a/server.py +++ b/server.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import logging from logging.config import dictConfig diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..83082d8 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,6 @@ +[aliases] +test = pytest + +[tool:pytest] +addopts = --verbose +#python_files = tests diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7542caa --- /dev/null +++ b/setup.py @@ -0,0 +1,131 @@ +""" +LAKEsuperior setup script. + +Proudly ripped from https://github.com/pypa/sampleproject/blob/master/setup.py +""" + +import sys + +# Always prefer setuptools over distutils +from setuptools import setup, find_packages +# To use a consistent encoding +from codecs import open +from os import path + +here = path.abspath(path.dirname(__file__)) + +# ``pytest_runner`` is referenced in ``setup_requires``. +# See https://github.com/pytest-dev/pytest-runner#conditional-requirement +needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv) +pytest_runner = ['pytest-runner'] if needs_pytest else [] + + +# Get the long description from the README file +with open(path.join(here, 'README.rst'), encoding='utf-8') as f: + long_description = f.read() + +setup( + name='lakesuperior', + version='1.0.0a9pre1', + + description='A Linked Data Platform repository sever.', + long_description=long_description, + long_description_content_type='text/x-rst; charset=UTF-8', + + url='https://lakesuperior.readthedocs.io', + + author='Stefano Cossu <@scossu>', + #author_email='', # Optional + license='Apache License Version 2.0', + + # https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + 'Development Status :: 3 - Alpha', + + 'Environment :: Console', + 'Environment :: Web Environment', + + 'Framework :: Flask', + + 'Intended Audience :: Developers', + 'Intended Audience :: Information Technology', + 'Intended Audience :: Science/Research', + + 'License :: OSI Approved :: Apache Software License', + + 'Natural Language :: English', + + 'Operating System :: MacOS', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX :: Linux', + + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + + 'Topic :: Database :: Database Engines/Servers', + ], + + keywords='repository linked-data', + + python_requires='~=3.5', + + packages=find_packages(exclude=['contrib', 'docs', 'tests']), + + # Great reference read about dependency management: + # https://caremad.io/posts/2013/07/setup-vs-requirement/ + install_requires=[ + 'CoilMQ', + 'Flask', + 'HiYaPyCo', + 'PyYAML', + 'arrow', + 'click', + 'click-log', + 'gevent', + 'gunicorn', + 'lmdb', + 'rdflib', + 'requests', + 'requests-toolbelt', + 'sphinx-rtd-theme', + 'stomp.py', + ], + + setup_requires=[] + pytest_runner, + tests_require=[ + 'Pillow', + 'numpy', + 'pytest', + 'pytest-flask', + ], + + #extras_require={}, + #package_data={}, + #data_files=[], + + entry_points={ + 'console_scripts': [ + 'lsup-admin=lsup_admin:admin', + 'profiler=profiler:run', + 'fcrepo=wsgi:run', + ], + }, + + # List additional URLs that are relevant to your project as a dict. + # + # This field corresponds to the "Project-URL" metadata fields: + # https://packaging.python.org/specifications/core-metadata/#project-url-multiple-use + # + # Examples listed include a pattern for specifying where the package tracks + # issues, where the source is hosted, where to say thanks to the package + # maintainers, and where to support the project financially. The key is + # what's used to render the link text on PyPI. + project_urls={ # Optional + 'Source Code': 'https://github.com/scossu/lakesuperior/', + 'Documentation': 'https://lakesuperior.readthedocs.io', + 'Discussion': 'https://groups.google.com/forum/#!forum/lakesuperior', + 'Bug Reports': 'https://github.com/scossu/lakesuperior/issues', + } +) +