From 606d92e3391424812cb590acf2f41b21f457cfa0 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Dec 24 2016 23:23:52 +0000 Subject: Update Python 3 compat fixes, enable tests --- diff --git a/anyjson-py34.patch b/anyjson-py34.patch deleted file mode 100644 index 1447a1e..0000000 --- a/anyjson-py34.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff -Nur anyjson-0.3.3/anyjson/__init__.py anyjson-0.3.3.py34/anyjson/__init__.py ---- anyjson-0.3.3/anyjson/__init__.py 2012-06-22 01:08:51.000000000 +0200 -+++ anyjson-0.3.3.py34/anyjson/__init__.py 2016-05-15 00:28:10.166808278 +0200 -@@ -85,7 +85,7 @@ - TypeError if the object could not be serialized.""" - try: - return self._encode(data) -- except self._encode_error, exc: -+ except self._encode_error as exc: - raise TypeError, TypeError(*exc.args), sys.exc_info()[2] - serialize = dumps - -@@ -97,7 +97,7 @@ - if self._filedecode and not isinstance(s, basestring): - return self._filedecode(StringIO(s)) - return self._decode(s) -- except self._decode_error, exc: -+ except self._decode_error as exc: - raise ValueError, ValueError(*exc.args), sys.exc_info()[2] - deserialize = loads - diff --git a/anyjson-python3.patch b/anyjson-python3.patch new file mode 100644 index 0000000..521325b --- /dev/null +++ b/anyjson-python3.patch @@ -0,0 +1,58 @@ +--- anyjson-0.3.3/anyjson/__init__.py 2012-06-21 16:08:51.000000000 -0700 ++++ anyjson-0.3.3/anyjson/__init__.py.new 2016-12-24 14:52:05.027940293 -0800 +@@ -1,6 +1,7 @@ + """Wraps the best available JSON implementation available in a common + interface""" + ++from six import (reraise, string_types) + import sys + + VERSION = (0, 3, 3) +@@ -64,9 +65,9 @@ + self._encode_error = modinfo["encerror"] + self._decode_error = modinfo["decerror"] + +- if isinstance(modinfo["encerror"], basestring): ++ if isinstance(modinfo["encerror"], string_types): + self._encode_error = getattr(module, modinfo["encerror"]) +- if isinstance(modinfo["decerror"], basestring): ++ if isinstance(modinfo["decerror"], string_types): + self._decode_error = getattr(module, modinfo["decerror"]) + + self.name = modinfo["modname"] +@@ -85,8 +86,8 @@ + TypeError if the object could not be serialized.""" + try: + return self._encode(data) +- except self._encode_error, exc: +- raise TypeError, TypeError(*exc.args), sys.exc_info()[2] ++ except self._encode_error as exc: ++ reraise(TypeError, TypeError(*exc.args), sys.exc_info()[2]) + serialize = dumps + + def loads(self, s): +@@ -94,11 +95,11 @@ + ValueError if the string could not be parsed.""" + # uses StringIO to support buffer objects. + try: +- if self._filedecode and not isinstance(s, basestring): ++ if self._filedecode and not isinstance(s, string_types): + return self._filedecode(StringIO(s)) + return self._decode(s) +- except self._decode_error, exc: +- raise ValueError, ValueError(*exc.args), sys.exc_info()[2] ++ except self._decode_error as exc: ++ reraise(ValueError, ValueError(*exc.args), sys.exc_info()[2]) + deserialize = loads + + +@@ -117,8 +118,7 @@ + # We do NOT try to load a compatible module because that may throw an + # exception, which renders the package uninstallable with easy_install + # (It trys to execfile the script when installing, to make sure it works) +- print "Running anyjson as a stand alone script is not supported" +- sys.exit(1) ++ sys.exit("Running anyjson as a stand alone script is not supported") + else: + for modspec in _modules: + try: diff --git a/python-anyjson.spec b/python-anyjson.spec index 77705ca..8d14c48 100644 --- a/python-anyjson.spec +++ b/python-anyjson.spec @@ -9,13 +9,35 @@ Summary: %{sum} License: BSD URL: http://pypi.python.org/pypi/anyjson Source0: http://pypi.python.org/packages/source/a/%{srcname}/%{srcname}-%{version}.tar.gz -Patch0: anyjson-py34.patch +# Fix Python 3 compatibility +Patch0: anyjson-python3.patch BuildArch: noarch BuildRequires: python2-devel +BuildRequires: python2-six +BuildRequires: python2-nose BuildRequires: python3-devel BuildRequires: python3-setuptools -BuildRequires: python3-Cython +BuildRequires: python3-six +BuildRequires: python3-nose +# The tests test whichever parsers they can find, so install as many +# as we can for the tests to use +# Note: there is a PR with a patch for ujson support: +# https://bitbucket.org/runeh/anyjson/pull-requests/6 +# and we have python-ujson packaged, but ujson has very questionable +# default behaviour (it silently serializes all sorts of not-really- +# serializable things, lossily): +# https://github.com/esnme/ultrajson/issues/168 +# so I don't think enabling this support is a good idea at present. +# AFAICT, we do not have these packaged: +# python-yajl +# python-jsonlib +# python-jsonlib2 +# and django.utils.simplejson doesn't seem to exist upstream any more +BuildRequires: python2-simplejson +BuildRequires: python3-simplejson +# No Python 3 build of this +BuildRequires: python-cjson %description Anyjson loads whichever is the fastest JSON module installed and @@ -24,6 +46,7 @@ provides a uniform API regardless of which JSON implementation is used. %package -n python2-%{srcname} Summary: %{sum} %{?python_provide:%python_provide python2-%{srcname}} +Requires: python2-six %description -n python2-%{srcname} Anyjson loads whichever is the fastest JSON module installed and @@ -32,14 +55,14 @@ provides a uniform API regardless of which JSON implementation is used. %package -n python3-%{srcname} Summary: %{sum} %{?python_provide:%python_provide python3-%{srcname}} +Requires: python3-six %description -n python3-%{srcname} Anyjson loads whichever is the fastest JSON module installed and provides a uniform API regardless of which JSON implementation is used. %prep -%setup -n %{srcname}-%{version} -%patch0 -p1 -b .py34 +%autosetup -n %{srcname}-%{version} -p1 %build %py2_build @@ -48,6 +71,10 @@ provides a uniform API regardless of which JSON implementation is used. %install %py2_install %py3_install + +%check +%{__python2} setup.py test +%{__python3} setup.py test %files -n python2-%{srcname} %doc CHANGELOG README @@ -62,7 +89,12 @@ provides a uniform API regardless of which JSON implementation is used. %{python3_sitelib}/%{srcname}*.egg-info %changelog -* Mon Dec 19 2016 Miro Hrončok - 0.3.3-13 +* Sat Dec 24 2016 Adam Williamson - 0.3.3-13 +- update the Python 3 compatibility patch (fixes build) +- enable tests +- add some more BuildRequires to extend test coverage + +* Mon Dec 19 2016 Miro Hrončok - Rebuild for Python 3.6 * Tue Jul 19 2016 Fedora Release Engineering - 0.3.3-12