1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-22 00:02:28 +00:00

Added indentation and default plugins

* setup.py:
This commit is contained in:
J. Fernando Sánchez 2015-09-29 11:14:28 +02:00
parent 7c2e0ddec7
commit b484b453e0
7 changed files with 17 additions and 13 deletions

View File

@ -17,7 +17,3 @@
""" """
Sentiment analysis server in Python Sentiment analysis server in Python
""" """
import extensions
import blueprints
import plugins

View File

@ -44,6 +44,10 @@ if __name__ == '__main__':
action='store_true', action='store_true',
default=False, default=False,
help='Run the application in debug mode') help='Run the application in debug mode')
parser.add_argument('--default-plugins',
action='store_true',
default=False,
help='Run the application in debug mode')
parser.add_argument('--host', parser.add_argument('--host',
type=str, type=str,
default="127.0.0.1", default="127.0.0.1",
@ -62,14 +66,14 @@ if __name__ == '__main__':
logging.basicConfig(level=getattr(logging, args.level)) logging.basicConfig(level=getattr(logging, args.level))
app = Flask(__name__) app = Flask(__name__)
app.debug = args.debug app.debug = args.debug
sp = Senpy(app, args.plugins_folder) sp = Senpy(app, args.plugins_folder, default_plugins=args.default_plugins)
sp.activate_all() sp.activate_all()
import logging import logging
http_server = WSGIServer((args.host, args.port), app) http_server = WSGIServer((args.host, args.port), app)
try: try:
print "Server running on port %s:%d. Ctrl+C to quit" % (args.host, print("Server running on port %s:%d. Ctrl+C to quit" % (args.host,
args.port) args.port))
http_server.serve_forever() http_server.serve_forever()
except KeyboardInterrupt: except KeyboardInterrupt:
http_server.stop() http_server.stop()
print "Bye!" print("Bye!")

View File

@ -27,14 +27,14 @@ class Senpy(object):
""" Default Senpy extension for Flask """ """ Default Senpy extension for Flask """
def __init__(self, app=None, plugin_folder="plugins", base_plugins=True): def __init__(self, app=None, plugin_folder="plugins", default_plugins=False):
self.app = app self.app = app
self._search_folders = set() self._search_folders = set()
self._outdated = True self._outdated = True
self.add_folder(plugin_folder) self.add_folder(plugin_folder)
if base_plugins: if default_plugins:
base_folder = os.path.join(os.path.dirname(__file__), "plugins") base_folder = os.path.join(os.path.dirname(__file__), "plugins")
self.add_folder(base_folder) self.add_folder(base_folder)

View File

@ -154,7 +154,7 @@ class Leaf(dict):
' type="application/ld+json"' % url) ' type="application/ld+json"' % url)
} }
del js["@context"] del js["@context"]
return FlaskResponse(json.dumps(js), return FlaskResponse(json.dumps(js, indent=4),
status=self.get("status", 200), status=self.get("status", 200),
headers=headers, headers=headers,
mimetype="application/json") mimetype="application/json")

View File

@ -15,7 +15,7 @@ except AttributeError:
install_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] test_reqs = [str(ir.req) for ir in test_reqs]
VERSION = "0.4.6" VERSION = "0.4.7"
setup( setup(
name='senpy', name='senpy',
@ -34,5 +34,6 @@ extendable, so new algorithms and sources can be used.
classifiers=[], classifiers=[],
install_requires=install_reqs, install_requires=install_reqs,
tests_require=test_reqs, tests_require=test_reqs,
test_suite="nose.collector",
include_package_data=True, include_package_data=True,
) )

View File

@ -0,0 +1,3 @@
nose
mock
pbr

View 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, base_plugins=False) self.senpy = Senpy(plugin_folder=self.dir, default_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