1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-09-18 04:22:21 +00:00

Flake8, Semver, Pre-commit

* Added pre-commit: http://pre-commit.com
* Fixed flake8 errors
* Added flake8 pre-commit hooks
* Added pre-commit to Makefile
* Changed VERSION numbering
* Changed versioning to match PEP-0440
This commit is contained in:
J. Fernando Sánchez
2017-01-10 11:10:10 +01:00
parent 7fd69cc690
commit db30257373
21 changed files with 59 additions and 102 deletions

View File

@@ -1 +1 @@
pre-0.7.0
0.7.0-dev1

View File

@@ -17,9 +17,24 @@
"""
Sentiment analysis server in Python
"""
import os
from __future__ import print_function
from .version import __version__
try:
import semver
__version_info__ = semver.parse_version_info(__version__)
if __version_info__.prerelease:
import logging
logger = logging.getLogger(__name__)
msg = 'WARNING: You are using a pre-release version of {} ({})'.format(
__name__, __version__)
if len(logging.root.handlers) > 0:
logger.info(msg)
else:
import sys
print(msg, file=sys.stderr)
except ImportError:
print('semver not installed. Not doing version checking')
__all__ = ['api', 'blueprints', 'cli', 'extensions', 'models', 'plugins']

View File

@@ -24,7 +24,6 @@ from flask import Flask
from senpy.extensions import Senpy
from gevent.wsgi import WSGIServer
from gevent.monkey import patch_all
import gevent
import logging
import os
import argparse
@@ -77,7 +76,7 @@ def main():
'-i',
action='store_true',
default=False,
help='Do not run a server, only install the dependencies of the plugins.'
help='Do not run a server, only install plugin dependencies'
)
args = parser.parse_args()
logging.basicConfig()

View File

@@ -1,9 +1,8 @@
from future.utils import iteritems
from .models import Error
import logging
logger = logging.getLogger(__name__)
from .models import Error
API_PARAMS = {
"algorithm": {
"aliases": ["algorithm", "a", "algo"],

View File

@@ -17,12 +17,12 @@
"""
Blueprints for Senpy
"""
from flask import Blueprint, request, current_app, render_template, url_for, jsonify
from flask import (Blueprint, request, current_app,
render_template, url_for, jsonify)
from .models import Error, Response, Plugins, read_schema
from .api import NIF_PARAMS, WEB_PARAMS, parse_params
from .api import WEB_PARAMS, parse_params
from functools import wraps
import json
import logging
logger = logging.getLogger(__name__)
@@ -105,9 +105,7 @@ def plugins():
@api_blueprint.route('/plugins/<plugin>/<action>', methods=['POST', 'GET'])
@basic_api
def plugin(plugin=None, action="list"):
filt = {}
sp = current_app.senpy
plugs = sp.filter_plugins(name=plugin)
if plugin == 'default' and sp.default_plugin:
response = sp.default_plugin
plugin = response.name
@@ -123,11 +121,3 @@ def plugin(plugin=None, action="list"):
return Response(message="Ok")
else:
return Error(message="action '{}' not allowed".format(action))
if __name__ == '__main__':
import config
app.register_blueprint(api_blueprint)
app.debug = config.DEBUG
app.run(host='0.0.0.0', port=5000)

View File

@@ -6,7 +6,7 @@ import gevent
from gevent import monkey
monkey.patch_all()
from .plugins import SenpyPlugin, SentimentPlugin, EmotionPlugin
from .plugins import SentimentPlugin
from .models import Error
from .blueprints import api_blueprint, demo_blueprint
from .api import API_PARAMS, NIF_PARAMS, parse_params
@@ -21,7 +21,6 @@ import sys
import imp
import logging
import traceback
import gevent
import yaml
import pip
@@ -230,7 +229,6 @@ class Senpy(object):
return None, None
module = info["module"]
name = info["name"]
requirements = info.get("requirements", [])
sys.path.append(root)
(fp, pathname, desc) = imp.find_module(module, [root, ])
try:

View File

@@ -1,9 +1,9 @@
'''
Senpy Models.
Senpy Models.
This implementation should mirror the JSON schema definition.
For compatibility with Py3 and for easier debugging, this new version drops introspection
and adds all arguments to the models.
For compatibility with Py3 and for easier debugging, this new version drops
introspection and adds all arguments to the models.
'''
from __future__ import print_function
from six import string_types
@@ -124,9 +124,9 @@ class SenpyMixin(object):
context = self.context.copy()
if hasattr(self, 'prefix'):
# This sets @base for the document, which will be used in
# all relative URIs will. For example, if a uri is "Example" and
# prefix =s "http://example.com", the absolute URI after expanding
# with JSON-LD will be "http://example.com/Example"
# all relative URIs. For example, if a uri is "Example" and
# prefix =s "http://example.com", the absolute URI after
# expanding with JSON-LD will be "http://example.com/Example"
prefix_context = {"@base": self.prefix}
if isinstance(context, list):

View File

@@ -6,7 +6,7 @@ import os.path
import pickle
import logging
import tempfile
from .models import Response, PluginModel, Error
from .models import PluginModel, Error
logger = logging.getLogger(__name__)
@@ -50,7 +50,6 @@ class SentimentPlugin(SenpyPlugin):
class EmotionPlugin(SenpyPlugin):
def __init__(self, info, *args, **kwargs):
resp = super(EmotionPlugin, self).__init__(info, *args, **kwargs)
self.minEmotionValue = float(info.get("minEmotionValue", 0))
self.maxEmotionValue = float(info.get("maxEmotionValue", 0))
self["@type"] = "onyx:EmotionAnalysis"

View File

@@ -1,4 +1,3 @@
import json
import random
from senpy.plugins import SentimentPlugin