summaryrefslogtreecommitdiff
path: root/gr-uhd/python/uhd
diff options
context:
space:
mode:
authorJosh Morman <jmorman@gnuradio.org>2021-11-24 12:41:17 -0500
committermormj <34754695+mormj@users.noreply.github.com>2021-11-24 14:41:53 -0500
commit1bfc6b439dbcdc467bbbed43a9fd71b49524c348 (patch)
tree92701a454c32e87295ba69796efa858e51eb76ff /gr-uhd/python/uhd
parentde184bd22f98b714bc2f383d59126cd2510374fe (diff)
uhd: pep8 formatting
Signed-off-by: Josh Morman <jmorman@gnuradio.org>
Diffstat (limited to 'gr-uhd/python/uhd')
-rw-r--r--gr-uhd/python/uhd/__init__.py47
-rw-r--r--gr-uhd/python/uhd/qa_uhd.py1
2 files changed, 31 insertions, 17 deletions
diff --git a/gr-uhd/python/uhd/__init__.py b/gr-uhd/python/uhd/__init__.py
index 7c0f23dde1..1ffa94e821 100644
--- a/gr-uhd/python/uhd/__init__.py
+++ b/gr-uhd/python/uhd/__init__.py
@@ -16,6 +16,8 @@ line.
########################################################################
# Prepare uhd swig module to make it more pythonic
########################################################################
+
+
def _prepare_uhd_python():
try:
from . import uhd_python
@@ -25,45 +27,56 @@ def _prepare_uhd_python():
__path__.append(os.path.join(dirname, "bindings"))
from . import uhd_python
- #some useful typedefs for the user
+ # some useful typedefs for the user
setattr(uhd_python, 'freq_range_t', uhd_python.meta_range_t)
setattr(uhd_python, 'gain_range_t', uhd_python.meta_range_t)
- #Make the python tune request object inherit from float
- #so that it can be passed in GRC as a frequency parameter.
- #The type checking in GRC will accept the tune request.
- #Also use kwargs to construct individual struct elements.
+ # Make the python tune request object inherit from float
+ # so that it can be passed in GRC as a frequency parameter.
+ # The type checking in GRC will accept the tune request.
+ # Also use kwargs to construct individual struct elements.
class tune_request_t(uhd_python.tune_request_t):
# def __new__(self, *args, **kwargs): return float.__new__(self)
def __float__(self): return self.target_freq
+
def __init__(self, *args, **kwargs):
super().__init__(*args)
- for key, val in list(kwargs.items()): setattr(self, key, val)
+ for key, val in list(kwargs.items()):
+ setattr(self, key, val)
setattr(uhd_python, 'tune_request_t', tune_request_t)
- #handle general things on all uhd_python attributes
- #Install the __str__ and __repr__ handlers if applicable
- #Create aliases for uhd swig attributes to avoid the "_t"
+ # handle general things on all uhd_python attributes
+ # Install the __str__ and __repr__ handlers if applicable
+ # Create aliases for uhd swig attributes to avoid the "_t"
for attr in dir(uhd_python):
myobj = getattr(uhd_python, attr)
- if hasattr(myobj, 'to_string'): myobj.__repr__ = lambda o: o.to_string().strip()
- if hasattr(myobj, 'to_pp_string'): myobj.__str__ = lambda o: o.to_pp_string().strip()
- if hasattr(myobj, 'to_bool'): myobj.__nonzero__ = lambda o: o.to_bool()
- if hasattr(myobj, 'to_int'): myobj.__int__ = lambda o: o.to_int()
- if hasattr(myobj, 'to_real'): myobj.__float__ = lambda o: o.to_real()
- if attr.endswith('_t'): setattr(uhd_python, attr[:-2], myobj)
+ if hasattr(myobj, 'to_string'):
+ myobj.__repr__ = lambda o: o.to_string().strip()
+ if hasattr(myobj, 'to_pp_string'):
+ myobj.__str__ = lambda o: o.to_pp_string().strip()
+ if hasattr(myobj, 'to_bool'):
+ myobj.__nonzero__ = lambda o: o.to_bool()
+ if hasattr(myobj, 'to_int'):
+ myobj.__int__ = lambda o: o.to_int()
+ if hasattr(myobj, 'to_real'):
+ myobj.__float__ = lambda o: o.to_real()
+ if attr.endswith('_t'):
+ setattr(uhd_python, attr[:-2], myobj)
- #make a new find devices that casts everything with the pythonized device_addr_t which has __str__
+ # make a new find devices that casts everything with the pythonized device_addr_t which has __str__
def find_devices(*args, **kwargs):
def to_pythonized_dev_addr(dev_addr):
new_dev_addr = uhd_python.device_addr_t()
- for key in list(dev_addr.keys()): new_dev_addr[key] = dev_addr.get(key)
+ for key in list(dev_addr.keys()):
+ new_dev_addr[key] = dev_addr.get(key)
return new_dev_addr
return __builtins__['map'](to_pythonized_dev_addr, uhd_python.find_devices_raw(*args, **kwargs))
setattr(uhd_python, 'find_devices', find_devices)
+
########################################################################
# Initialize this module with the contents of uhd pybind
########################################################################
_prepare_uhd_python()
+
from .uhd_python import *
diff --git a/gr-uhd/python/uhd/qa_uhd.py b/gr-uhd/python/uhd/qa_uhd.py
index 65b50d794b..c8fb65c144 100644
--- a/gr-uhd/python/uhd/qa_uhd.py
+++ b/gr-uhd/python/uhd/qa_uhd.py
@@ -12,6 +12,7 @@ gr-uhd sanity checking
from gnuradio import gr, gr_unittest, uhd
+
class test_uhd(gr_unittest.TestCase):
def setUp(self):