summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/python/pmt
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-runtime/python/pmt')
-rw-r--r--gnuradio-runtime/python/pmt/CMakeLists.txt3
-rw-r--r--gnuradio-runtime/python/pmt/__init__.py11
-rw-r--r--gnuradio-runtime/python/pmt/pmt_to_python.py29
-rw-r--r--[-rwxr-xr-x]gnuradio-runtime/python/pmt/qa_pmt.py6
-rw-r--r--[-rwxr-xr-x]gnuradio-runtime/python/pmt/qa_pmt_to_python.py7
5 files changed, 32 insertions, 24 deletions
diff --git a/gnuradio-runtime/python/pmt/CMakeLists.txt b/gnuradio-runtime/python/pmt/CMakeLists.txt
index ca7a4f147d..e635663924 100644
--- a/gnuradio-runtime/python/pmt/CMakeLists.txt
+++ b/gnuradio-runtime/python/pmt/CMakeLists.txt
@@ -26,7 +26,6 @@ GR_PYTHON_INSTALL(FILES
__init__.py
pmt_to_python.py
DESTINATION ${GR_PYTHON_DIR}/pmt
- COMPONENT "runtime_python"
)
########################################################################
@@ -43,6 +42,6 @@ foreach(py_qa_test_file ${py_qa_test_files})
${CMAKE_BINARY_DIR}/gnuradio-blocks/swig
)
set(GR_TEST_TARGET_DEPS gnuradio-runtime)
- GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file})
+ GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} -B ${py_qa_test_file})
endforeach(py_qa_test_file)
endif(ENABLE_TESTING)
diff --git a/gnuradio-runtime/python/pmt/__init__.py b/gnuradio-runtime/python/pmt/__init__.py
index 399fae8701..89eb555823 100644
--- a/gnuradio-runtime/python/pmt/__init__.py
+++ b/gnuradio-runtime/python/pmt/__init__.py
@@ -39,14 +39,17 @@ bool, symbol (string), integer, real, complex, null, pair, list,
vector, dict, uniform_vector, any (boost::any cast)
'''
+from __future__ import absolute_import
+from __future__ import unicode_literals
+
import os
try:
- from pmt_swig import *
+ from .pmt_swig import *
except ImportError:
dirname, filename = os.path.split(os.path.abspath(__file__))
__path__.append(os.path.join(dirname, "..", "..", "swig"))
- from pmt_swig import *
+ from .pmt_swig import *
# due to changes in the PMT_NIL singleton for static builds, we force
# this into Python here.
@@ -55,5 +58,5 @@ PMT_T = get_PMT_T()
PMT_F = get_PMT_F()
PMT_EOF = get_PMT_EOF()
-from pmt_to_python import pmt_to_python as to_python
-from pmt_to_python import python_to_pmt as to_pmt
+from .pmt_to_python import pmt_to_python as to_python
+from .pmt_to_python import python_to_pmt as to_pmt
diff --git a/gnuradio-runtime/python/pmt/pmt_to_python.py b/gnuradio-runtime/python/pmt/pmt_to_python.py
index 2909c93c21..270a1dd9e9 100644
--- a/gnuradio-runtime/python/pmt/pmt_to_python.py
+++ b/gnuradio-runtime/python/pmt/pmt_to_python.py
@@ -17,8 +17,9 @@
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-try: import pmt_swig as pmt
-except: import pmt
+from __future__ import unicode_literals
+
+from . import pmt_swig as pmt
import numpy
# SWIG isn't taking in the #define PMT_NIL;
@@ -34,7 +35,7 @@ def pmt_to_tuple(p):
return tuple(elems)
def pmt_from_tuple(p):
- args = map(python_to_pmt, p)
+ args = list(map(python_to_pmt, p))
return pmt.make_tuple(*args)
def pmt_to_vector(p):
@@ -62,7 +63,7 @@ def pmt_to_dict(p):
def pmt_from_dict(p):
d = pmt.make_dict()
- for k, v in p.iteritems():
+ for k, v in list(p.items()):
#dict is immutable -> therefore pmt_dict_add returns the new dict
d = pmt.dict_add(d, python_to_pmt(k), python_to_pmt(v))
return d
@@ -88,27 +89,27 @@ uvector_mappings = dict([ (numpy_mappings[key][3], (numpy_mappings[key][2], key)
def numpy_to_uvector(numpy_array):
try:
mapping = numpy_mappings[numpy_array.dtype]
- pc = map(mapping[1], numpy.ravel(numpy_array))
+ pc = list(map(mapping[1], numpy.ravel(numpy_array)))
return mapping[0](numpy_array.size, pc)
except KeyError:
raise ValueError("unsupported numpy array dtype for conversion to pmt %s"%(numpy_array.dtype))
def uvector_to_numpy(uvector):
- match = None
- for test_func in uvector_mappings.keys():
- if test_func(uvector):
- match = uvector_mappings[test_func]
- return numpy.array(match[0](uvector), dtype = match[1])
- else:
- raise ValueError("unsupported uvector data type for conversion to numpy array %s"%(uvector))
+ match = None
+ for test_func in list(uvector_mappings.keys()):
+ if test_func(uvector):
+ match = uvector_mappings[test_func]
+ return numpy.array(match[0](uvector), dtype = match[1])
+ else:
+ raise ValueError("unsupported uvector data type for conversion to numpy array %s"%(uvector))
type_mappings = ( #python type, check pmt type, to python, from python
(None, pmt.is_null, lambda x: None, lambda x: PMT_NIL),
(bool, pmt.is_bool, pmt.to_bool, pmt.from_bool),
(str, pmt.is_symbol, pmt.symbol_to_string, pmt.string_to_symbol),
- (unicode, lambda x: False, None, lambda x: pmt.string_to_symbol(x.encode('utf-8'))),
+ (str, lambda x: False, None, lambda x: pmt.string_to_symbol(x.encode('utf-8'))),
(int, pmt.is_integer, pmt.to_long, pmt.from_long),
- (long, pmt.is_uint64, lambda x: long(pmt.to_uint64(x)), pmt.from_uint64),
+ (int, pmt.is_uint64, lambda x: int(pmt.to_uint64(x)), pmt.from_uint64),
(float, pmt.is_real, pmt.to_double, pmt.from_double),
(complex, pmt.is_complex, pmt.to_complex, pmt.from_complex),
(tuple, pmt.is_tuple, pmt_to_tuple, pmt_from_tuple),
diff --git a/gnuradio-runtime/python/pmt/qa_pmt.py b/gnuradio-runtime/python/pmt/qa_pmt.py
index 32cff62f44..b6df648029 100755..100644
--- a/gnuradio-runtime/python/pmt/qa_pmt.py
+++ b/gnuradio-runtime/python/pmt/qa_pmt.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2011,2018 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -20,6 +20,8 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import print_function
+
import unittest
import pmt
@@ -30,7 +32,7 @@ class test_pmt(unittest.TestCase):
b = pmt.from_double(123765)
d1 = pmt.make_dict()
d2 = pmt.dict_add(d1, a, b)
- print d2
+ print(d2)
def test02(self):
const = 123765
diff --git a/gnuradio-runtime/python/pmt/qa_pmt_to_python.py b/gnuradio-runtime/python/pmt/qa_pmt_to_python.py
index e63ade1843..18a8e2bcf5 100755..100644
--- a/gnuradio-runtime/python/pmt/qa_pmt_to_python.py
+++ b/gnuradio-runtime/python/pmt/qa_pmt_to_python.py
@@ -20,16 +20,19 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import absolute_import
+
+
import unittest
import pmt
-import pmt_to_python as pmt2py
+from pmt import pmt_to_python as pmt2py
class test_pmt_to_python(unittest.TestCase):
def test_pmt_from_double(self):
b = pmt.from_double(123765)
self.assertEqual(pmt.to_python(b), 123765)
- t = pmt.to_pmt(range(5))
+ t = pmt.to_pmt(list(range(5)))
def test_numpy_to_uvector_and_reverse(self):
import numpy as np