15
0
forked from pool/python-pecan

Accepting request 890868 from devel:languages:python

OBS-URL: https://build.opensuse.org/request/show/890868
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-pecan?expand=0&rev=26
This commit is contained in:
2021-05-12 17:31:08 +00:00
committed by Git OBS Bridge
7 changed files with 179 additions and 20 deletions
+14
View File
@@ -1,3 +1,17 @@
-------------------------------------------------------------------
Wed May 5 08:23:44 UTC 2021 - Antonio Larrosa <alarrosa@suse.com>
- version update to 1.4.0
* pecan now requires webob >= 1.8
* fixed a bug when parsing certain Accept headers
(https://github.com/Pylons/webob/issues/403)
* removed official support for Python 3.5
- Rebase patch:
* pecan-no-kajiki.patch
- Add patches to support SQLAlchemy 1.4.x (gh#pecan/pecan#125)
* 0001-Support-SQLAlchemy-1.4.x.patch
* 0002-Fix-typo-from-bad-copy-paste.patch
-------------------------------------------------------------------
Sat Mar 14 08:01:12 UTC 2020 - Tomáš Chvátal <tchvatal@suse.com>
+13 -12
View File
@@ -1,7 +1,7 @@
#
# spec file for package python-pecan
#
# Copyright (c) 2020 SUSE LLC
# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -17,20 +17,22 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%bcond_without python2
%define skip_python2 1
Name: python-pecan
Version: 1.3.3
Version: 1.4.0
Release: 0
Summary: A WSGI object-dispatching web framework
License: BSD-3-Clause
URL: https://github.com/pecan/pecan
Source: https://files.pythonhosted.org/packages/source/p/pecan/pecan-%{version}.tar.gz
Patch0: pecan-no-kajiki.patch
Patch1: 0001-Support-SQLAlchemy-1.4.x.patch
Patch2: 0002-Fix-typo-from-bad-copy-paste.patch
BuildRequires: %{python_module Genshi >= 0.7}
BuildRequires: %{python_module Jinja2}
BuildRequires: %{python_module Mako >= 0.4.0}
BuildRequires: %{python_module SQLAlchemy}
BuildRequires: %{python_module WebOb >= 1.2}
BuildRequires: %{python_module WebOb >= 1.8}
BuildRequires: %{python_module WebTest >= 1.3.1}
BuildRequires: %{python_module gunicorn}
BuildRequires: %{python_module logutils}
@@ -38,25 +40,20 @@ BuildRequires: %{python_module mock}
BuildRequires: %{python_module setuptools}
BuildRequires: %{python_module six}
BuildRequires: %{python_module virtualenv}
BuildRequires: uwsgi
# we need sqlite module
BuildRequires: %{pythons}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
Requires: python-Mako >= 0.4.0
Requires: python-WebOb >= 1.2
Requires: python-WebOb >= 1.8
Requires: python-WebTest >= 1.3.1
Requires: python-logutils >= 0.3
Requires: python-setuptools
Requires: python-six
Requires(post): update-alternatives
Requires(postun): update-alternatives
Requires(postun):update-alternatives
BuildArch: noarch
%if %{with python2}
BuildRequires: python-singledispatch
%endif
%ifpython2
Requires: python-singledispatch
%endif
%if 0%{?suse_version}
Suggests: python-Genshi
Suggests: python-Jinja2
@@ -70,6 +67,10 @@ A WSGI object-dispatching web framework.
%prep
%setup -q -n pecan-%{version}
%patch0 -p1
%patch1 -p1
%patch2 -p1
sed -ie "/^uwsgi$/d" test-requirements.txt
sed -ie "/^pep8$/d" test-requirements.txt
%build
%python_build
+114
View File
@@ -0,0 +1,114 @@
From a89d425c183ea6fa3d1ad86c2f7bc8b0acf63323 Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <antonio.larrosa@gmail.com>
Date: Wed, 5 May 2021 13:45:02 +0200
Subject: [PATCH 1/2] Support SQLAlchemy 1.4.x
SQLAlchemy 1.4 is returning new types, LegacyCursorResult and LegacyRow,
which are not JSON serializable and this makes tests fail with:
```
======================================================================
ERROR: test_result_proxy (pecan.tests.test_jsonify.TestJsonifySQLAlchemyGenericEncoder)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/abuild/rpmbuild/BUILD/pecan-1.3.3/pecan/tests/test_jsonify.py", line 220, in test_result_proxy
result = encode(self.result_proxy)
File "/home/abuild/rpmbuild/BUILD/pecan-1.3.3/pecan/jsonify.py", line 133, in encode
return _instance.encode(obj)
File "/usr/lib64/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib64/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/home/abuild/rpmbuild/BUILD/pecan-1.3.3/pecan/jsonify.py", line 127, in default
return jsonify(obj)
File "/usr/lib64/python3.6/functools.py", line 807, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
File "/home/abuild/rpmbuild/BUILD/pecan-1.3.3/pecan/jsonify.py", line 122, in jsonify
return _default.default(obj)
File "/home/abuild/rpmbuild/BUILD/pecan-1.3.3/pecan/jsonify.py", line 108, in default
return JSONEncoder.default(self, obj)
File "/usr/lib64/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'LegacyCursorResult' is not JSON serializable
======================================================================
ERROR: test_row_proxy (pecan.tests.test_jsonify.TestJsonifySQLAlchemyGenericEncoder)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/abuild/rpmbuild/BUILD/pecan-1.3.3/pecan/tests/test_jsonify.py", line 227, in test_row_proxy
result = encode(self.row_proxy)
File "/home/abuild/rpmbuild/BUILD/pecan-1.3.3/pecan/jsonify.py", line 133, in encode
return _instance.encode(obj)
File "/usr/lib64/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib64/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/home/abuild/rpmbuild/BUILD/pecan-1.3.3/pecan/jsonify.py", line 127, in default
return jsonify(obj)
File "/usr/lib64/python3.6/functools.py", line 807, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
File "/home/abuild/rpmbuild/BUILD/pecan-1.3.3/pecan/jsonify.py", line 122, in jsonify
return _default.default(obj)
File "/home/abuild/rpmbuild/BUILD/pecan-1.3.3/pecan/jsonify.py", line 108, in default
return JSONEncoder.default(self, obj)
File "/usr/lib64/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'LegacyRow' is not JSON serializable
```
The SQLALchemy migration guide at [1] says:
```
For mapping-like behaviors from a Row object, including support for
these methods as well as a key-oriented __contains__ operator, the API
going forward will be to first access a special attribute Row._mapping,
which will then provide a complete mapping interface to the row, rather
than a tuple interface.
```
This commit fixes this by handling these new returned classes as a
special case and using _mapping to convert them to dicts.
[1] https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#rowproxy-is-no-longer-a-proxy-is-now-called-row-and-behaves-like-an-enhanced-named-tuple
---
pecan/jsonify.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/pecan/jsonify.py b/pecan/jsonify.py
index 5b74877..5da9638 100644
--- a/pecan/jsonify.py
+++ b/pecan/jsonify.py
@@ -33,6 +33,19 @@ except ImportError: # pragma no cover
pass
+try:
+ from sqlalchemy.engine.cursor import LegacyCursorResult, LegacyRow
+except ImportError: # pragma no cover
+ # dummy classes since we don't have SQLAlchemy installed
+ # or we're using SQLAlchemy < 1.4
+
+ class ResultProxy(object): # noqa
+ pass
+
+ class RowProxy(object): # noqa
+ pass
+
+
#
# encoders
#
@@ -100,6 +113,11 @@ class GenericJSON(JSONEncoder):
if props['count'] < 0:
props['count'] = len(props['rows'])
return props
+ elif isinstance(obj, LegacyCursorResult):
+ rows = [dict(row._mapping) for row in obj.fetchall()]
+ return {'count': len(rows), 'rows': rows}
+ elif isinstance(obj, LegacyRow):
+ return dict(obj._mapping)
elif isinstance(obj, RowProxy):
return dict(obj)
elif isinstance(obj, webob_dicts):
--
2.31.1
+31
View File
@@ -0,0 +1,31 @@
From 942d92e7eb83e2eccb5d172b226b8e5fdc2d0368 Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <antonio.larrosa@gmail.com>
Date: Wed, 5 May 2021 13:57:57 +0200
Subject: [PATCH 2/2] Fix typo from bad copy&paste
I copied the structure of the code from a few lines above and forgot
to change the name of the classes
---
pecan/jsonify.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pecan/jsonify.py b/pecan/jsonify.py
index 5da9638..c5cbc15 100644
--- a/pecan/jsonify.py
+++ b/pecan/jsonify.py
@@ -39,10 +39,10 @@ except ImportError: # pragma no cover
# dummy classes since we don't have SQLAlchemy installed
# or we're using SQLAlchemy < 1.4
- class ResultProxy(object): # noqa
+ class LegacyCursorResult(object): # noqa
pass
- class RowProxy(object): # noqa
+ class LegacyRow(object): # noqa
pass
--
2.31.1
-3
View File
@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b5461add4e3f35a7ee377b3d7f72ff13e93f40f3823b3208ab978b29bde936ff
size 120595
+3
View File
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4b2acd6802a04b59e306d0a6ccf37701d24376f4dc044bbbafba3afdf9d3389a
size 124233
+4 -5
View File
@@ -2,11 +2,10 @@ Index: pecan-1.3.2/setup.py
===================================================================
--- pecan-1.3.2.orig/setup.py
+++ pecan-1.3.2/setup.py
@@ -35,16 +35,8 @@ tests_require = requirements + [
'mock',
'sqlalchemy'
]
-
@@ -35,15 +35,8 @@ tests_require = requirements + [
tests_require = requirements + test_requirements
-if sys.version_info < (3, 0):
- # These don't support Python3 yet - don't run their tests
- if platform.python_implementation() != 'PyPy':