mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-22 00:02:28 +00:00
parent
384aba4654
commit
7c2e0ddec7
@ -1,4 +1,5 @@
|
|||||||
include requirements.txt
|
include requirements.txt
|
||||||
|
include test-requirements.txt
|
||||||
include README.md
|
include README.md
|
||||||
include senpy/context.jsonld
|
include senpy/context.jsonld
|
||||||
recursive-include *.senpy
|
graft senpy/plugins
|
||||||
|
2728
logo.svg
Normal file
2728
logo.svg
Normal file
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 180 KiB |
@ -18,7 +18,7 @@
|
|||||||
Blueprints for Senpy
|
Blueprints for Senpy
|
||||||
"""
|
"""
|
||||||
from flask import Blueprint, request, current_app
|
from flask import Blueprint, request, current_app
|
||||||
from .models import Error, Response
|
from .models import Error, Response, Leaf
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@ -158,9 +158,9 @@ def plugins(plugin=None, action="list"):
|
|||||||
method = "{}_plugin".format(action)
|
method = "{}_plugin".format(action)
|
||||||
if(hasattr(sp, method)):
|
if(hasattr(sp, method)):
|
||||||
getattr(sp, method)(plugin)
|
getattr(sp, method)(plugin)
|
||||||
return "Ok"
|
return Leaf(message="Ok").flask()
|
||||||
else:
|
else:
|
||||||
return "action '{}' not allowed".format(action), 400
|
return Error("action '{}' not allowed".format(action)).flask()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
import gevent
|
||||||
|
from gevent import monkey
|
||||||
|
monkey.patch_all()
|
||||||
|
|
||||||
from .plugins import SenpyPlugin, SentimentPlugin, EmotionPlugin
|
from .plugins import SenpyPlugin, SentimentPlugin, EmotionPlugin
|
||||||
from .models import Error
|
from .models import Error
|
||||||
from .blueprints import nif_blueprint
|
from .blueprints import nif_blueprint
|
||||||
@ -23,15 +27,16 @@ class Senpy(object):
|
|||||||
|
|
||||||
""" Default Senpy extension for Flask """
|
""" Default Senpy extension for Flask """
|
||||||
|
|
||||||
def __init__(self, app=None, plugin_folder="plugins"):
|
def __init__(self, app=None, plugin_folder="plugins", base_plugins=True):
|
||||||
self.app = app
|
self.app = app
|
||||||
base_folder = os.path.join(os.path.dirname(__file__), "plugins")
|
|
||||||
|
|
||||||
self._search_folders = set()
|
self._search_folders = set()
|
||||||
self._outdated = True
|
self._outdated = True
|
||||||
|
|
||||||
for folder in (base_folder, plugin_folder):
|
self.add_folder(plugin_folder)
|
||||||
self.add_folder(folder)
|
if base_plugins:
|
||||||
|
base_folder = os.path.join(os.path.dirname(__file__), "plugins")
|
||||||
|
self.add_folder(base_folder)
|
||||||
|
|
||||||
if app is not None:
|
if app is not None:
|
||||||
self.init_app(app)
|
self.init_app(app)
|
||||||
@ -124,7 +129,13 @@ class Senpy(object):
|
|||||||
|
|
||||||
def activate_plugin(self, plugin_name, sync=False):
|
def activate_plugin(self, plugin_name, sync=False):
|
||||||
plugin = self.plugins[plugin_name]
|
plugin = self.plugins[plugin_name]
|
||||||
th = gevent.spawn(plugin.activate)
|
def act():
|
||||||
|
try:
|
||||||
|
plugin.activate()
|
||||||
|
except Exception as ex:
|
||||||
|
logger.error("Error activating plugin {}: {}".format(plugin.name,
|
||||||
|
ex))
|
||||||
|
th = gevent.spawn(act)
|
||||||
th.link_value(partial(self._set_active_plugin, plugin_name, True))
|
th.link_value(partial(self._set_active_plugin, plugin_name, True))
|
||||||
if sync:
|
if sync:
|
||||||
th.join()
|
th.join()
|
||||||
|
@ -239,7 +239,7 @@ class Emotion(Leaf):
|
|||||||
_context = {}
|
_context = {}
|
||||||
|
|
||||||
|
|
||||||
class Error(Response):
|
class Error(Leaf):
|
||||||
# A better pattern would be this:
|
# A better pattern would be this:
|
||||||
# http://flask.pocoo.org/docs/0.10/patterns/apierrors/
|
# http://flask.pocoo.org/docs/0.10/patterns/apierrors/
|
||||||
_frame = {}
|
_frame = {}
|
||||||
|
20
setup.py
20
setup.py
@ -1,16 +1,21 @@
|
|||||||
|
import pip
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
from pip.req import parse_requirements
|
from pip.req import parse_requirements
|
||||||
|
|
||||||
# parse_requirements() returns generator of pip.req.InstallRequirement objects
|
# parse_requirements() returns generator of pip.req.InstallRequirement objects
|
||||||
install_reqs = parse_requirements("requirements.txt")
|
|
||||||
|
try:
|
||||||
|
install_reqs = parse_requirements("requirements.txt", session=pip.download.PipSession())
|
||||||
|
test_reqs = parse_requirements("test-requirements.txt", session=pip.download.PipSession())
|
||||||
|
except AttributeError:
|
||||||
|
install_reqs = parse_requirements("requirements.txt")
|
||||||
|
test_reqs = parse_requirements("test-requirements.txt")
|
||||||
|
|
||||||
# reqs is a list of requirement
|
# reqs is a list of requirement
|
||||||
# e.g. ['django==1.5.1', 'mezzanine==1.4.6']
|
# e.g. ['django==1.5.1', 'mezzanine==1.4.6']
|
||||||
reqs = [str(ir.req) for ir in install_reqs]
|
install_reqs = [str(ir.req) for ir in install_reqs]
|
||||||
|
test_reqs = [str(ir.req) for ir in test_reqs]
|
||||||
|
|
||||||
VERSION = "0.4.1"
|
VERSION = "0.4.6"
|
||||||
|
|
||||||
print(reqs)
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='senpy',
|
name='senpy',
|
||||||
@ -27,6 +32,7 @@ extendable, so new algorithms and sources can be used.
|
|||||||
.format(VERSION),
|
.format(VERSION),
|
||||||
keywords=['eurosentiment', 'sentiment', 'emotions', 'nif'],
|
keywords=['eurosentiment', 'sentiment', 'emotions', 'nif'],
|
||||||
classifiers=[],
|
classifiers=[],
|
||||||
install_requires=reqs,
|
install_requires=install_reqs,
|
||||||
|
tests_require=test_reqs,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
)
|
)
|
||||||
|
0
test-requirements.txt
Normal file
0
test-requirements.txt
Normal file
@ -15,7 +15,7 @@ class ExtensionsTest(TestCase):
|
|||||||
def create_app(self):
|
def create_app(self):
|
||||||
self.app = Flask("test_extensions")
|
self.app = Flask("test_extensions")
|
||||||
self.dir = os.path.join(os.path.dirname(__file__), "..")
|
self.dir = os.path.join(os.path.dirname(__file__), "..")
|
||||||
self.senpy = Senpy(plugin_folder=self.dir)
|
self.senpy = Senpy(plugin_folder=self.dir, base_plugins=False)
|
||||||
self.senpy.init_app(self.app)
|
self.senpy.init_app(self.app)
|
||||||
self.senpy.activate_plugin("Dummy", sync=True)
|
self.senpy.activate_plugin("Dummy", sync=True)
|
||||||
return self.app
|
return self.app
|
||||||
@ -75,7 +75,7 @@ class ExtensionsTest(TestCase):
|
|||||||
resp = self.senpy.analyse(input="tupni")
|
resp = self.senpy.analyse(input="tupni")
|
||||||
logging.debug("Response: {}".format(resp))
|
logging.debug("Response: {}".format(resp))
|
||||||
assert resp["status"] == 404
|
assert resp["status"] == 404
|
||||||
|
|
||||||
|
|
||||||
def test_filtering(self):
|
def test_filtering(self):
|
||||||
""" Filtering plugins """
|
""" Filtering plugins """
|
||||||
|
Loading…
Reference in New Issue
Block a user