mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2026-04-06 21:20:33 +02:00
* gnu/packages/machine-learning.scm (libretranslate): New variable. * gnu/packages/patches/libretranslate-use-flasgger.patch: New file. * gnu/local.mk (dist_patch_DATA): Register it. Change-Id: I82ca207ee8c724e3ee0623768b502512c494e9c1 Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
80 lines
2.9 KiB
Diff
80 lines
2.9 KiB
Diff
Migrate to Flasgger, as flask-swagger is no longer maintained
|
|
|
|
Upstream-Status: https://github.com/LibreTranslate/LibreTranslate/pull/943
|
|
|
|
diff --git a/libretranslate/app.py b/libretranslate/app.py
|
|
index 9793a918b971..9511f2ceea80 100644
|
|
--- a/libretranslate/app.py
|
|
+++ b/libretranslate/app.py
|
|
@@ -15,8 +15,7 @@ import argostranslatefiles
|
|
from argostranslatefiles import get_supported_formats
|
|
from flask import Blueprint, Flask, Response, abort, jsonify, render_template, request, send_file, url_for, make_response
|
|
from flask_babel import Babel
|
|
-from flask_swagger import swagger
|
|
-from flask_swagger_ui import get_swaggerui_blueprint
|
|
+from flasgger import Swagger
|
|
from argostranslatefiles.translatehtml import translate_html
|
|
from werkzeug.exceptions import HTTPException
|
|
from werkzeug.http import http_date
|
|
@@ -1310,17 +1309,25 @@ def create_app(args):
|
|
|
|
limiter.init_app(app)
|
|
|
|
- swag = swagger(app)
|
|
- swag["basePath"] = args.url_prefix if args.url_prefix != "" else "/"
|
|
- swag["info"]["version"] = get_version()
|
|
- swag["info"]["title"] = "LibreTranslate"
|
|
- swag["info"]["description"] = "Free and Open Source Machine Translation API."
|
|
- swag["info"]["license"] = {"name": "AGPL-3.0"}
|
|
+ swagger_config = Swagger.DEFAULT_CONFIG | {
|
|
+ "specs": [{"endpoint": "spec", "route": api_url}],
|
|
+ "specs_route": "/docs/",
|
|
+ }
|
|
+ swagger_template = {
|
|
+ "basePath": args.url_prefix if args.url_prefix != "" else "/",
|
|
+ "info": {
|
|
+ "version": get_version(),
|
|
+ "title": "LibreTranslate",
|
|
+ "description": "Free and Open Source Machine Translation API.",
|
|
+ "license": {"name": "AGPL-3.0"},
|
|
+ },
|
|
+ }
|
|
+ swag = Swagger(app, config=swagger_config, template=swagger_template)
|
|
|
|
@app.route(api_url)
|
|
@limiter.exempt
|
|
def spec():
|
|
- return jsonify(lazy_swag(swag))
|
|
+ return jsonify(lazy_swag(swag.get_apispecs()))
|
|
|
|
app.config["BABEL_TRANSLATION_DIRECTORIES"] = 'locales'
|
|
|
|
@@ -1343,12 +1350,6 @@ def create_app(args):
|
|
|
|
app.jinja_env.globals.update(_e=gettext_escaped, _h=gettext_html)
|
|
|
|
- # Call factory function to create our blueprint
|
|
- # The Blueprint is not using url_for which means the middleware does not work properly and we need to manually fix things
|
|
- swaggerui_blueprint = get_swaggerui_blueprint(swagger_url, args.url_prefix + api_url)
|
|
- swaggerui_blueprint.url_prefix = "/docs"
|
|
- app.register_blueprint(swaggerui_blueprint)
|
|
-
|
|
if os.environ.get("LT_POWERCYCLE") is not None:
|
|
print("Power cycling...")
|
|
sys.exit(0)
|
|
diff --git a/pyproject.toml b/pyproject.toml
|
|
index ff1a0a4be8a4..f5f18207365d 100644
|
|
--- a/pyproject.toml
|
|
+++ b/pyproject.toml
|
|
@@ -37,9 +37,8 @@ dynamic = ["version"]
|
|
|
|
dependencies = [
|
|
"argos-translate-lt ==1.12.1",
|
|
+ "flasgger ==0.9.7.1",
|
|
"Flask ==2.2.5",
|
|
- "flask-swagger ==0.2.14",
|
|
- "flask-swagger-ui ==4.11.1",
|
|
"Flask-Limiter ==2.6.3",
|
|
"Flask-Babel ==3.1.0",
|
|
"waitress ==2.1.2",
|