summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2024-02-03 11:32:44 +0100
committerMichał Górny <mgorny@gentoo.org>2024-02-03 11:41:29 +0100
commit9a37a4262a07bac8acc24015287bef65596d5a4d (patch)
treefb6a8ddc306208d3267b0132d17e91cd66ecc340 /dev-python/httpbin
parentapp-text/poppler: 24.02.0 version bump, bump subslot (diff)
downloadgentoo-9a37a4262a07bac8acc24015287bef65596d5a4d.tar.gz
gentoo-9a37a4262a07bac8acc24015287bef65596d5a4d.tar.bz2
gentoo-9a37a4262a07bac8acc24015287bef65596d5a4d.zip
dev-python/httpbin: Make dev-python/flasgger dep optional
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'dev-python/httpbin')
-rw-r--r--dev-python/httpbin/files/httpbin-0.10.1-optional-flasgger.patch87
-rw-r--r--dev-python/httpbin/httpbin-0.10.1-r4.ebuild (renamed from dev-python/httpbin/httpbin-0.10.1-r3.ebuild)23
2 files changed, 105 insertions, 5 deletions
diff --git a/dev-python/httpbin/files/httpbin-0.10.1-optional-flasgger.patch b/dev-python/httpbin/files/httpbin-0.10.1-optional-flasgger.patch
new file mode 100644
index 000000000000..c3d87ec4144d
--- /dev/null
+++ b/dev-python/httpbin/files/httpbin-0.10.1-optional-flasgger.patch
@@ -0,0 +1,87 @@
+From 65e397d7332ab87e3b2455ff9dc99af24861b58b Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Sat, 3 Feb 2024 11:20:00 +0100
+Subject: [PATCH] Support using httpbin without flasgger
+
+Make the dependency on flasgger optional. The dependency has been added
+relatively recently (i.e. before the original package was abandoned but
+after its last release), and it is only used to provide a more dynamic
+landing page. This is unnecessary for use of httpbin for testing,
+and it introduces an indirect dependency on Rust that is problematic.
+
+With this change, flasgger is no longer installed by default. It can be
+enabled via "[flasgger]" extra. When flasgger is not available, httpbin
+redirects to the "legacy" index page.
+---
+ httpbin/core.py | 17 +++++++++++++++--
+ pyproject.toml | 4 +++-
+ tests/test_httpbin.py | 4 +++-
+ 3 files changed, 21 insertions(+), 4 deletions(-)
+
+diff --git a/httpbin/core.py b/httpbin/core.py
+index a82c1b8..77576a4 100644
+--- a/httpbin/core.py
++++ b/httpbin/core.py
+@@ -33,7 +33,10 @@ try:
+ except ImportError: # werkzeug < 2.1
+ from werkzeug.wrappers import BaseResponse as Response
+
+-from flasgger import Swagger, NO_SANITIZER
++try:
++ from flasgger import Swagger, NO_SANITIZER
++except ImportError:
++ Swagger = None
+
+ from . import filters
+ from .helpers import (
+@@ -165,7 +168,10 @@ swagger_config = {
+ "specs_route": "/",
+ }
+
+-swagger = Swagger(app, sanitizer=NO_SANITIZER, template=template, config=swagger_config)
++if Swagger is not None:
++ swagger = Swagger(app, sanitizer=NO_SANITIZER, template=template, config=swagger_config)
++else:
++ app.logger.warning("Swagger not found, legacy index will be used.")
+
+ # Set up Bugsnag exception tracking, if desired. To use Bugsnag, install the
+ # Bugsnag Python client with the command "pip install bugsnag", and set the
+@@ -244,6 +250,13 @@ def set_cors_headers(response):
+ # ------
+
+
++if Swagger is None:
++ @app.route("/")
++ def no_flasgger_index():
++ """Redirect to legacy index if flasgger is not available."""
++ return redirect(url_for("view_landing_page"))
++
++
+ @app.route("/legacy")
+ def view_landing_page():
+ """Generates Landing Page in legacy layout."""
+diff --git a/tests/test_httpbin.py b/tests/test_httpbin.py
+index 6b75124..2ce63a6 100755
+--- a/tests/test_httpbin.py
++++ b/tests/test_httpbin.py
+@@ -10,6 +10,7 @@ from hashlib import md5, sha256, sha512
+ from io import BytesIO
+
+ import httpbin
++from httpbin.core import Swagger
+ from httpbin.helpers import parse_multi_value_header
+
+
+@@ -115,7 +116,8 @@ class HttpbinTestCase(unittest.TestCase):
+
+ def test_index(self):
+ response = self.app.get('/', headers={'User-Agent': 'test'})
+- self.assertEqual(response.status_code, 200)
++ self.assertEqual(response.status_code,
++ 200 if Swagger is not None else 302)
+
+ def get_data(self, response):
+ if 'get_data' in dir(response):
+--
+2.43.0
+
diff --git a/dev-python/httpbin/httpbin-0.10.1-r3.ebuild b/dev-python/httpbin/httpbin-0.10.1-r4.ebuild
index 5d029ef8a9f6..d34c543e7976 100644
--- a/dev-python/httpbin/httpbin-0.10.1-r3.ebuild
+++ b/dev-python/httpbin/httpbin-0.10.1-r4.ebuild
@@ -1,4 +1,4 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
@@ -6,7 +6,7 @@ EAPI=8
DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{10..12} pypy3 )
-inherit distutils-r1 pypi
+inherit distutils-r1 optfeature pypi
DESCRIPTION="HTTP Request and Response Service"
HOMEPAGE="
@@ -17,16 +17,23 @@ HOMEPAGE="
LICENSE="|| ( MIT ISC )"
SLOT="0"
KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~loong ~mips ppc ppc64 ~riscv ~s390 sparc x86"
+IUSE="test-rust"
RDEPEND="
dev-python/brotlicffi[${PYTHON_USEDEP}]
dev-python/decorator[${PYTHON_USEDEP}]
- dev-python/flasgger[${PYTHON_USEDEP}]
>=dev-python/flask-2.2.4[${PYTHON_USEDEP}]
dev-python/itsdangerous[${PYTHON_USEDEP}]
dev-python/markupsafe[${PYTHON_USEDEP}]
dev-python/six[${PYTHON_USEDEP}]
"
+BDEPEND="
+ test? (
+ test-rust? (
+ dev-python/flasgger[${PYTHON_USEDEP}]
+ )
+ )
+"
distutils_enable_tests pytest
@@ -34,9 +41,15 @@ src_prepare() {
local PATCHES=(
# https://github.com/psf/httpbin/pull/29
"${FILESDIR}/${P}-werkzeug-3.patch"
+ # https://github.com/psf/httpbin/pull/44 (simplified)
+ "${FILESDIR}/${P}-optional-flasgger.patch"
)
- # unpin greenlet
- sed -i -e '/greenlet/d' pyproject.toml || die
+ # remove unnecessary deps
+ sed -i -e '/greenlet/d' -e '/flasgger/d' pyproject.toml || die
distutils-r1_src_prepare
}
+
+pkg_postinst() {
+ optfeature "Fancy index" dev-python/flasgger
+}