From a5a57d3f03522b88682ff9a7f4c2fbbdd628231b Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Nov 26 2015 01:23:12 +0000 Subject: many Python fixes, especially for Python 3 --- diff --git a/0001-make-version-status-PEP440-compliant.patch b/0001-make-version-status-PEP440-compliant.patch new file mode 100644 index 0000000..8992612 --- /dev/null +++ b/0001-make-version-status-PEP440-compliant.patch @@ -0,0 +1,25 @@ +From eaa2fd32ad6a5c1fda22b0b03776bb579d35d2be Mon Sep 17 00:00:00 2001 +From: Nils Philippsen +Date: Wed, 25 Nov 2015 23:56:23 +0100 +Subject: [PATCH 1/6] make version status PEP440 compliant + +--- + python/VERSION | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/python/VERSION b/python/VERSION +index ff49ec1..fe7b7ac 100644 +--- a/python/VERSION ++++ b/python/VERSION +@@ -1,7 +1,7 @@ + AUBIO_MAJOR_VERSION=0 + AUBIO_MINOR_VERSION=4 + AUBIO_PATCH_VERSION=2 +-AUBIO_VERSION_STATUS='~alpha' ++AUBIO_VERSION_STATUS='a0' + LIBAUBIO_LT_CUR=4 + LIBAUBIO_LT_REV=1 + LIBAUBIO_LT_AGE=1 +-- +2.5.0 + diff --git a/0002-Python-3-use-explicit-relative-import.patch b/0002-Python-3-use-explicit-relative-import.patch new file mode 100644 index 0000000..d23c8ce --- /dev/null +++ b/0002-Python-3-use-explicit-relative-import.patch @@ -0,0 +1,25 @@ +From 6bd3fbe86acab15bfe1c788077855ac3ad430066 Mon Sep 17 00:00:00 2001 +From: Nils Philippsen +Date: Thu, 26 Nov 2015 00:02:26 +0100 +Subject: [PATCH 2/6] Python 3: use explicit relative import + +--- + python/lib/generator.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/python/lib/generator.py b/python/lib/generator.py +index 195c2ef..7d95945 100755 +--- a/python/lib/generator.py ++++ b/python/lib/generator.py +@@ -3,7 +3,7 @@ + """ This file generates a c file from a list of cpp prototypes. """ + + import os, sys, shutil +-from gen_pyobject import write_msg, gen_new_init, gen_do, gen_members, gen_methods, gen_finish ++from .gen_pyobject import write_msg, gen_new_init, gen_do, gen_members, gen_methods, gen_finish + + def get_cpp_objects(): + +-- +2.5.0 + diff --git a/0003-Python-3-coerce-iterators-into-lists-where-necessary.patch b/0003-Python-3-coerce-iterators-into-lists-where-necessary.patch new file mode 100644 index 0000000..e09307a --- /dev/null +++ b/0003-Python-3-coerce-iterators-into-lists-where-necessary.patch @@ -0,0 +1,79 @@ +From 9398ad2999ff6c73ad7409f895757dcf35019f64 Mon Sep 17 00:00:00 2001 +From: Nils Philippsen +Date: Thu, 26 Nov 2015 00:09:08 +0100 +Subject: [PATCH 3/6] Python 3: coerce iterators into lists where necessary + +--- + python/lib/gen_pyobject.py | 2 +- + python/lib/generator.py | 12 +++++++++--- + 2 files changed, 10 insertions(+), 4 deletions(-) + +diff --git a/python/lib/gen_pyobject.py b/python/lib/gen_pyobject.py +index ba8274e..1cc9bde 100644 +--- a/python/lib/gen_pyobject.py ++++ b/python/lib/gen_pyobject.py +@@ -70,7 +70,7 @@ def get_params_types_names(proto): + example: proto = "int main (int argc, char ** argv)" + returns: [['int', 'argc'], ['char **','argv']] + """ +- return map(split_type, get_params(proto)) ++ return list(map(split_type, get_params(proto))) + + def get_return_type(proto): + import re +diff --git a/python/lib/generator.py b/python/lib/generator.py +index 7d95945..90c145d 100755 +--- a/python/lib/generator.py ++++ b/python/lib/generator.py +@@ -11,6 +11,7 @@ def get_cpp_objects(): + + cpp_output = filter(lambda y: len(y) > 1, cpp_output) + cpp_output = filter(lambda y: not y.startswith('#'), cpp_output) ++ cpp_output = list(cpp_output) + + i = 1 + while 1: +@@ -85,9 +86,11 @@ def generate_object_files(output_path): + object_methods = filter(lambda x: this_object in x, cpp_output) + object_methods = [a.strip() for a in object_methods] + object_methods = filter(lambda x: not x.startswith('typedef'), object_methods) ++ object_methods = list(object_methods) + #for method in object_methods: + # write_msg(method) +- new_methods = filter(lambda x: 'new_'+object_name in x, object_methods) ++ new_methods = list(filter( ++ lambda x: 'new_'+object_name in x, object_methods)) + if len(new_methods) > 1: + write_msg("-- WARNING: more than one new method for", object_name) + for method in new_methods: +@@ -98,7 +101,8 @@ def generate_object_files(output_path): + for method in new_methods: + write_msg(method) + +- del_methods = filter(lambda x: 'del_'+object_name in x, object_methods) ++ del_methods = list(filter( ++ lambda x: 'del_'+object_name in x, object_methods)) + if len(del_methods) > 1: + write_msg("-- WARNING: more than one del method for", object_name) + for method in del_methods: +@@ -106,7 +110,8 @@ def generate_object_files(output_path): + elif len(del_methods) < 1: + write_msg("-- WARNING: no del method for", object_name) + +- do_methods = filter(lambda x: object_name+'_do' in x, object_methods) ++ do_methods = list(filter( ++ lambda x: object_name+'_do' in x, object_methods)) + if len(do_methods) > 1: + pass + #write_msg("-- WARNING: more than one do method for", object_name) +@@ -135,6 +140,7 @@ def generate_object_files(output_path): + other_methods = filter(lambda x: x not in do_methods, other_methods) + other_methods = filter(lambda x: x not in get_methods, other_methods) + other_methods = filter(lambda x: x not in set_methods, other_methods) ++ other_methods = list(other_methods) + + if len(other_methods) > 0: + write_msg("-- WARNING: some methods for", object_name, "were unidentified") +-- +2.5.0 + diff --git a/0004-Python-3-use-Py_TYPE-instead-of-ob_type-member.patch b/0004-Python-3-use-Py_TYPE-instead-of-ob_type-member.patch new file mode 100644 index 0000000..98e64f6 --- /dev/null +++ b/0004-Python-3-use-Py_TYPE-instead-of-ob_type-member.patch @@ -0,0 +1,70 @@ +From 16e3209e730152f78a794256a24fd69d215dabf1 Mon Sep 17 00:00:00 2001 +From: Nils Philippsen +Date: Thu, 26 Nov 2015 00:38:48 +0100 +Subject: [PATCH 4/6] Python 3: use Py_TYPE() instead of ob_type member + +--- + python/ext/aubio-types.h | 5 +++++ + python/ext/aubiowraphell.h | 2 +- + python/ext/py-cvec.c | 2 +- + python/ext/py-filter.c | 2 +- + 4 files changed, 8 insertions(+), 3 deletions(-) + +diff --git a/python/ext/aubio-types.h b/python/ext/aubio-types.h +index 280d01b..c206a8b 100644 +--- a/python/ext/aubio-types.h ++++ b/python/ext/aubio-types.h +@@ -39,6 +39,11 @@ + #define AUBIO_NPY_SMPL NPY_FLOAT + #endif + ++// compat with Python < 2.6 ++#ifndef Py_TYPE ++#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) ++#endif ++ + // special python type for cvec + typedef struct + { +diff --git a/python/ext/aubiowraphell.h b/python/ext/aubiowraphell.h +index d60cc30..b9146ef 100644 +--- a/python/ext/aubiowraphell.h ++++ b/python/ext/aubiowraphell.h +@@ -25,7 +25,7 @@ static void \ + Py_ ## NAME ## _del ( Py_ ## NAME * self) \ + { \ + del_aubio_ ## NAME (self->o); \ +- self->ob_type->tp_free ((PyObject *) self); \ ++ Py_TYPE(self)->tp_free ((PyObject *) self); \ + } + + #define AUBIO_MEMBERS_START(NAME) \ +diff --git a/python/ext/py-cvec.c b/python/ext/py-cvec.c +index 940508f..a060696 100644 +--- a/python/ext/py-cvec.c ++++ b/python/ext/py-cvec.c +@@ -59,7 +59,7 @@ static void + Py_cvec_del (Py_cvec * self) + { + del_cvec (self->o); +- self->ob_type->tp_free ((PyObject *) self); ++ Py_TYPE(self)->tp_free ((PyObject *) self); + } + + static PyObject * +diff --git a/python/ext/py-filter.c b/python/ext/py-filter.c +index 416bba8..ad508be 100644 +--- a/python/ext/py-filter.c ++++ b/python/ext/py-filter.c +@@ -55,7 +55,7 @@ static void + Py_filter_del (Py_filter * self) + { + del_aubio_filter (self->o); +- self->ob_type->tp_free ((PyObject *) self); ++ Py_TYPE(self)->tp_free ((PyObject *) self); + } + + static PyObject * +-- +2.5.0 + diff --git a/0005-Python-3-raise-RuntimeErrors-not-generic-exceptions.patch b/0005-Python-3-raise-RuntimeErrors-not-generic-exceptions.patch new file mode 100644 index 0000000..14a57ba --- /dev/null +++ b/0005-Python-3-raise-RuntimeErrors-not-generic-exceptions.patch @@ -0,0 +1,53 @@ +From 7ea234f00f0d9c166f20e3ddbbd9be147b24bb16 Mon Sep 17 00:00:00 2001 +From: Nils Philippsen +Date: Thu, 26 Nov 2015 00:57:19 +0100 +Subject: [PATCH 5/6] Python 3: raise RuntimeErrors, not generic exceptions + +--- + python/ext/aubiowraphell.h | 2 +- + python/ext/py-sink.c | 2 +- + python/ext/py-source.c | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/python/ext/aubiowraphell.h b/python/ext/aubiowraphell.h +index b9146ef..c75567d 100644 +--- a/python/ext/aubiowraphell.h ++++ b/python/ext/aubiowraphell.h +@@ -13,7 +13,7 @@ Py_ ## NAME ## _init (Py_ ## NAME * self, PyObject * args, PyObject * kwds) \ + { \ + self->o = new_aubio_## NAME ( PARAMS ); \ + if (self->o == NULL) { \ +- PyErr_SetString (PyExc_StandardError, "error creating object"); \ ++ PyErr_SetString (PyExc_RuntimeError, "error creating object"); \ + return -1; \ + } \ + \ +diff --git a/python/ext/py-sink.c b/python/ext/py-sink.c +index be5de36..51b9bc3 100644 +--- a/python/ext/py-sink.c ++++ b/python/ext/py-sink.c +@@ -115,7 +115,7 @@ Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) + aubio_sink_preset_samplerate ( self->o, self->samplerate ); + } + if (self->o == NULL) { +- PyErr_SetString (PyExc_StandardError, "error creating sink with this uri"); ++ PyErr_SetString (PyExc_RuntimeError, "error creating sink with this uri"); + return -1; + } + self->samplerate = aubio_sink_get_samplerate ( self->o ); +diff --git a/python/ext/py-source.c b/python/ext/py-source.c +index f9f972f..085b9ea 100644 +--- a/python/ext/py-source.c ++++ b/python/ext/py-source.c +@@ -137,7 +137,7 @@ Py_source_init (Py_source * self, PyObject * args, PyObject * kwds) + if (self->o == NULL) { + char_t errstr[30 + strlen(self->uri)]; + sprintf(errstr, "error creating source with %s", self->uri); +- PyErr_SetString (PyExc_StandardError, errstr); ++ PyErr_SetString (PyExc_RuntimeError, errstr); + return -1; + } + self->samplerate = aubio_source_get_samplerate ( self->o ); +-- +2.5.0 + diff --git a/0006-Python-3-use-new-raise-syntax.patch b/0006-Python-3-use-new-raise-syntax.patch new file mode 100644 index 0000000..48acf44 --- /dev/null +++ b/0006-Python-3-use-new-raise-syntax.patch @@ -0,0 +1,61 @@ +From 1aacb4128b7d3ea9cc238b5df2c657b891fe610f Mon Sep 17 00:00:00 2001 +From: Nils Philippsen +Date: Thu, 26 Nov 2015 01:01:38 +0100 +Subject: [PATCH 6/6] Python 3: use new raise syntax + +--- + python/lib/aubio/midiconv.py | 19 +++++++++++-------- + 1 file changed, 11 insertions(+), 8 deletions(-) + +diff --git a/python/lib/aubio/midiconv.py b/python/lib/aubio/midiconv.py +index a859dec..f3e8e32 100644 +--- a/python/lib/aubio/midiconv.py ++++ b/python/lib/aubio/midiconv.py +@@ -6,9 +6,11 @@ def note2midi(note): + _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 'b': -1, u'♭': -1, u'\ufffd': -2} + _valid_octaves = range(-1, 10) + if type(note) not in (str, unicode): +- raise TypeError, "a string is required, got %s" % note ++ raise TypeError("a string is required, got %s" % note) + if not (1 < len(note) < 5): +- raise ValueError, "string of 2 to 4 characters expected, got %d (%s)" % (len(note), note) ++ raise ValueError( ++ "string of 2 to 4 characters expected, got %d (%s)" % ++ (len(note), note)) + notename, modifier, octave = [None]*3 + + if len(note) == 4: +@@ -26,23 +28,24 @@ def note2midi(note): + octave = int(octave) + + if notename not in _valid_notenames: +- raise ValueError, "%s is not a valid note name" % notename ++ raise ValueError("%s is not a valid note name" % notename) + if modifier not in _valid_modifiers: +- raise ValueError, "%s is not a valid modifier" % modifier ++ raise ValueError("%s is not a valid modifier" % modifier) + if octave not in _valid_octaves: +- raise ValueError, "%s is not a valid octave" % octave ++ raise ValueError("%s is not a valid octave" % octave) + + midi = 12 + octave * 12 + _valid_notenames[notename] + _valid_modifiers[modifier] + if midi > 127: +- raise ValueError, "%s is outside of the range C-2 to G8" % note ++ raise ValueError("%s is outside of the range C-2 to G8" % note) + return midi + + def midi2note(midi): + " convert midi note number to note name, e.g. [0, 127] -> [C-1, G9] " + if type(midi) != int: +- raise TypeError, "an integer is required, got %s" % midi ++ raise TypeError("an integer is required, got %s" % midi) + if not (-1 < midi < 128): +- raise ValueError, "an integer between 0 and 127 is excepted, got %d" % midi ++ raise ValueError( ++ "an integer between 0 and 127 is excepted, got %d" % midi) + midi = int(midi) + _valid_notenames = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'] + return _valid_notenames[midi % 12] + str( midi / 12 - 1) +-- +2.5.0 + diff --git a/aubio.spec b/aubio.spec index 1595129..baefb21 100644 --- a/aubio.spec +++ b/aubio.spec @@ -15,6 +15,12 @@ Group: System Environment/Libraries License: GPLv3+ URL: http://aubio.org/ Source0: http://aubio.org/pub/aubio-%{version}.tar.bz2 +Patch0: 0001-make-version-status-PEP440-compliant.patch +Patch1: 0002-Python-3-use-explicit-relative-import.patch +Patch2: 0003-Python-3-coerce-iterators-into-lists-where-necessary.patch +Patch3: 0004-Python-3-use-Py_TYPE-instead-of-ob_type-member.patch +Patch4: 0005-Python-3-raise-RuntimeErrors-not-generic-exceptions.patch +Patch5: 0006-Python-3-use-new-raise-syntax.patch BuildRequires: doxygen BuildRequires: fftw-devel @@ -150,6 +156,7 @@ popd - remove some old cruft - waf: build verbosely - rename python subpackage to python2, add python3 subpackage +- many Python fixes, especially for Python 3 * Wed Jun 17 2015 Fedora Release Engineering - 0.3.2-17 - Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild