aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-03-09 14:43:10 -0700
committerAaron Rossetto <aaron.rossetto@ni.com>2020-03-10 07:15:08 -0500
commit932bab1eae69a96679eea7e20c2b602c4a9a52b9 (patch)
tree62e531209119d29014633079046e2c55d1a8a1b8
parent51d0fd0d0639e857e60e6fa10679d6baa46b0864 (diff)
downloaduhd-932bab1eae69a96679eea7e20c2b602c4a9a52b9.tar.gz
uhd-932bab1eae69a96679eea7e20c2b602c4a9a52b9.tar.bz2
uhd-932bab1eae69a96679eea7e20c2b602c4a9a52b9.zip
python: Arrange file in Python module into uhd/ subdirectory
This adds the host/python/uhd subdirectory, which will add all files that go into the actual Python module once installed. Before, all Python files were directly in host/python and got sorted into their appropriate destination folders during configuration and installation. This change doesn't change anything (Python modules will look the same as they do now), except that it makes the source tree a tad neater, but more importantly, it creates a consistent directory structure when adding submodules to the uhd module. Apart from the PyBind11-generated shared object file (which gets generated during build time), the uhd/ subdirectory in host/python exactly resembles the Python module once installed, so it's more obvious where to add new submodules and files.
-rw-r--r--host/python/CMakeLists.txt14
-rw-r--r--host/python/uhd/__init__.py (renamed from host/python/__init__.py)0
-rw-r--r--host/python/uhd/filters.py (renamed from host/python/filters.py)0
-rw-r--r--host/python/uhd/rfnoc.py (renamed from host/python/rfnoc.py)0
-rw-r--r--host/python/uhd/types.py (renamed from host/python/types.py)0
-rw-r--r--host/python/uhd/usrp/__init__.py17
-rw-r--r--host/python/uhd/usrp/libtypes.py29
-rw-r--r--host/python/uhd/usrp/multi_usrp.py (renamed from host/python/usrp.py)15
8 files changed, 54 insertions, 21 deletions
diff --git a/host/python/CMakeLists.txt b/host/python/CMakeLists.txt
index 9c5503881..a4929b977 100644
--- a/host/python/CMakeLists.txt
+++ b/host/python/CMakeLists.txt
@@ -65,12 +65,12 @@ endif(WIN32)
add_custom_command(TARGET pyuhd
POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pyuhd> ${CMAKE_CURRENT_BINARY_DIR}/uhd/$<TARGET_FILE_NAME:pyuhd>)
-set(PYUHD_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py
- ${CMAKE_CURRENT_SOURCE_DIR}/types.py
- ${CMAKE_CURRENT_SOURCE_DIR}/usrp.py
- ${CMAKE_CURRENT_SOURCE_DIR}/filters.py
- ${CMAKE_CURRENT_SOURCE_DIR}/rfnoc.py
+# List of Python files that are part of the module but don't get
+# generated during build time.
+# Note: When adding Python files into uhd/, they don't get added to the
+# dependency list until CMake is re-run.
+file(GLOB_RECURSE PYUHD_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/uhd/*.py
)
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in")
@@ -81,7 +81,7 @@ file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR} NATIVE_CURRENT_BINARY_DIR)
configure_file(${SETUP_PY_IN} ${SETUP_PY})
add_custom_command(OUTPUT ${TIMESTAMP_FILE}
- COMMAND ${CMAKE_COMMAND} -E copy ${PYUHD_FILES} ${CMAKE_CURRENT_BINARY_DIR}/uhd
+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/uhd ${CMAKE_CURRENT_BINARY_DIR}/uhd
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} -q build
COMMAND ${CMAKE_COMMAND} -E touch ${TIMESTAMP_FILE}
DEPENDS ${PYUHD_FILES})
diff --git a/host/python/__init__.py b/host/python/uhd/__init__.py
index bf37f5215..bf37f5215 100644
--- a/host/python/__init__.py
+++ b/host/python/uhd/__init__.py
diff --git a/host/python/filters.py b/host/python/uhd/filters.py
index 8479b56e1..8479b56e1 100644
--- a/host/python/filters.py
+++ b/host/python/uhd/filters.py
diff --git a/host/python/rfnoc.py b/host/python/uhd/rfnoc.py
index af8200998..af8200998 100644
--- a/host/python/rfnoc.py
+++ b/host/python/uhd/rfnoc.py
diff --git a/host/python/types.py b/host/python/uhd/types.py
index ad96076f3..ad96076f3 100644
--- a/host/python/types.py
+++ b/host/python/uhd/types.py
diff --git a/host/python/uhd/usrp/__init__.py b/host/python/uhd/usrp/__init__.py
new file mode 100644
index 000000000..c7a630258
--- /dev/null
+++ b/host/python/uhd/usrp/__init__.py
@@ -0,0 +1,17 @@
+#
+# Copyright 2020 Ettus Research, a National Instruments Brand
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+""" @package usrp
+Python UHD module containing the MultiUSRP and other objects
+"""
+
+from .multi_usrp import MultiUSRP
+# Disable PyLint because the entire libtypes modules is a list of renames. It is
+# thus less redundant to do a wildcard import, even if generally discouraged.
+# We could also paste the contents of libtypes.py into here, but by leaving it
+# separate we avoid importing the lib module in this __init__ file.
+# pylint: disable=wildcard-import
+from .libtypes import *
+# pylint: enable=wildcard-import
diff --git a/host/python/uhd/usrp/libtypes.py b/host/python/uhd/usrp/libtypes.py
new file mode 100644
index 000000000..2c3170387
--- /dev/null
+++ b/host/python/uhd/usrp/libtypes.py
@@ -0,0 +1,29 @@
+#
+# Copyright 2017-2018 Ettus Research, a National Instruments Company
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+""" @package usrp
+Python UHD module containing the MultiUSRP and other objects
+"""
+
+from .. import libpyuhd as lib
+
+# Disable PyLint because we want to make it look like the following classes are
+# defined in Python, but they're just renames of lib types. They therefore
+# follow name conventions for Python classes, not for global constants.
+# pylint: disable=invalid-name
+SubdevSpecPair = lib.usrp.subdev_spec_pair
+SubdevSpec = lib.usrp.subdev_spec
+GPIOAtrReg = lib.usrp.gpio_atr_reg
+GPIOAtrMode = lib.usrp.gpio_atr_mode
+Unit = lib.usrp.unit
+AuxDAC = lib.usrp.aux_dac
+AuxADC = lib.usrp.aux_adc
+SpecialProps = lib.usrp.special_props
+Sampling = lib.usrp.sampling
+FEConnection = lib.usrp.fe_connection
+StreamArgs = lib.usrp.stream_args
+RXStreamer = lib.usrp.rx_streamer
+TXStreamer = lib.usrp.tx_streamer
+# pylint: enable=invalid-name
diff --git a/host/python/usrp.py b/host/python/uhd/usrp/multi_usrp.py
index ce141d683..adb03d436 100644
--- a/host/python/usrp.py
+++ b/host/python/uhd/usrp/multi_usrp.py
@@ -8,7 +8,7 @@ Python UHD module containing the MultiUSRP and other objects
"""
import numpy as np
-from . import libpyuhd as lib
+from .. import libpyuhd as lib
class MultiUSRP(lib.usrp.multi_usrp):
@@ -126,16 +126,3 @@ class MultiUSRP(lib.usrp.multi_usrp):
return send_samps
-SubdevSpecPair = lib.usrp.subdev_spec_pair
-SubdevSpec = lib.usrp.subdev_spec
-GPIOAtrReg = lib.usrp.gpio_atr_reg
-GPIOAtrMode = lib.usrp.gpio_atr_mode
-Unit = lib.usrp.unit
-AuxDAC = lib.usrp.aux_dac
-AuxADC = lib.usrp.aux_adc
-SpecialProps = lib.usrp.special_props
-Sampling = lib.usrp.sampling
-FEConnection = lib.usrp.fe_connection
-StreamArgs = lib.usrp.stream_args
-RXStreamer = lib.usrp.rx_streamer
-TXStreamer = lib.usrp.tx_streamer