Commit graph

29 commits

Author SHA1 Message Date
Steven Koo
396ed0c8af fixup! cmake: Replace distutils.sysconfig with sysconfig
The original commit incorrectly fails the build
uhd in the meta-ettus context. This uses prefix
instead to get the base path.

Signed-off-by: Steven Koo <steven.koo@ni.com>
2022-01-20 08:31:50 -06:00
Aaron Rossetto
87bc7c1bde cmake: Replace distutils.sysconfig with sysconfig
This commit replaces uses of distutils.sysconfig's get_python_lib()
function with sysconfig's near-equivalent get_path() function to get the
directory for site-specific, platform-specific files. Unfortunately,
get_path() does not have a way to easily modify or strip the prefix
applied to the path like get_python_lib() does, so the code must
manually modify the path to get the same effect:

- First, the platlib path is retrieved from the get_path() call.
- Next, the default base that is used to form the pathlib path is
queried via the get_config_var('base') call.
- Next, the portion of the platlib path that matches the default base is
stripped, and any leading path separator remaining is stripped. This
fundamentally replicates the behavior of get_python_lib() with an empty
prefix (i.e., the prefix positional parameter is specified as '').
- If a different prefix is desired, then the os.path.join() function is
used to combine the new prefix with the stripped pathlib path, ensuring
that the platform-specific path separator is used in crafting the path.
2022-01-14 14:36:39 -06:00
Aaron Rossetto
6d746fd296 cmake: Replace distutils with CMake for version checks
This commit replaces the use of distutils.version.LooseVersion() with
CMake's version comparison operator, which implements relational version
string checking in the same manner (i.e., comparing numeric components
of a version string numerically).
2022-01-14 14:36:39 -06:00
Martin Braun
09d94529e5 cmake: Replace CMAKE_{SOURCE,BINARY}_DIR with UHD_*_DIR
See the CMake 3.8 documentation on these two variables:
https://cmake.org/cmake/help/v3.8/variable/PROJECT-NAME_SOURCE_DIR.html
https://cmake.org/cmake/help/v3.8/variable/CMAKE_SOURCE_DIR.html

Under normal circumstances, these two are identical. For sub-projects
(i.e., when building UHD as part of something else that is also a CMake
project), only the former is useful. There is no discernible downside of
using UHD_SOURCE_DIR over CMAKE_SOURCE_DIR.

This was changed using sed:

$ sed -i "s/CMAKE_SOURCE_DIR/UHD_SOURCE_DIR/g" \
    `ag -l CMAKE_SOURCE_DIR **/{CMakeLists.txt,*.cmake}`
$ sed -i "s/CMAKE_BINARY_DIR/UHD_BINARY_DIR/g" \
    `ag -l CMAKE_BINARY_DIR **/{CMakeLists.txt,*.cmake}`

At the same time, we also replace the CMake variable UHD_HOST_ROOT (used
in MPM) with UHD_SOURCE_DIR. There's no reason to have two variables
with the same meaning and different names, but more importantly, this
means that UHD_SOURCE_DIR is defined even in those cases where MPM calls
into CMake files from UHD without any additional patches.

Shoutout to GitHub user marcobergamin for bringing this up.
2021-09-10 15:08:10 -05:00
Lars Amsel
73462501f0 mpm: add unit tests for EEPROM readers 2021-05-31 05:28:47 -07:00
Martin Braun
60fb5d5f13 python: Add find() to the Python API
This a mapping of uhd::device::find() into uhd.find() on the Python
side. The uhd::device is intentionally not mapped into Python (prefer
MultiUSRP or RfnocGraph instead), so the namespace is moved up one
level.

Example:
>>> import uhd
>>> # Now print the device args for all found B200s:
>>> for dev_args in uhd.find("type=b200")): print(dev_args.to_string())
2020-12-07 11:53:35 -08:00
Martin Braun
7ee106187e python: Add access to the property_tree from Python
Example:
>>> usrp = uhd.usrp.multi_usrp("")
>>> tree = usrp.get_tree()
>>> print(tree.access_int("/name").get())
2020-10-16 14:58:15 -05:00
Martin Braun
77511533a6 python: Move multi_usrp_python to its own module
This helps with recompilation times of UHD.
No functional changes.
2020-10-12 15:10:47 -05:00
Samuel O'Brien
f54a22c60a sim: Embed MPM into libpyuhd
When ENABLE_SIM and ENABLE_PYTHON_API are set, this commit embeds MPM
(Built with -DMPM_DEVICE=sim) into the pyuhd package.

Signed-off-by: Samuel O'Brien <sam.obrien@ni.com>
2020-10-07 15:29:19 -05:00
Aaron Rossetto
c68977cffa cmake: Use relative path to Python lib location for Windows installer 2020-08-28 14:34:32 -05:00
Martin Braun
1bba62a75a Remove remaining Python 2 references
This changes two things in all applicable files:
- Remove imports from __future__
- Change default shebangs from /usr/bin/env python to /usr/bin/env
  python3
2020-05-07 15:10:41 -05:00
Martin Braun
75b7991378 python: Fix RPATH for the Python library
On UNIX systems, CMake will set the RPATH of the Python library to the
build directory, which is very helpful because it allows unit and other
tests to be executed from within the build directory.
On installation, the RPATH is removed, but only if install(TARGETS) is
used, which we were not, thus resulting in incorrect RPATHs.

This would surface as a bug, too. Calling uhd.get_lib_path() would
always point to the build directory, thus resulting in no FPGA images
being found automatically, e.g. when running a B200 through the Python
API.

This change installs the Python .so file separately, using the correct
CMake mechanisms.
2020-05-07 10:30:58 -05:00
Martin Braun
932bab1eae 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.
2020-03-10 07:15:08 -05:00
Ryan Volz
2fab118bdc python: Set python module suffix to conform with PEP 3149.
This adds the python implementation, major and minor version numbers,
and any additional flags (debug, pymalloc, wide unicode) to the
extension module suffix as specified in PEP 3149.

Hat tip to @isuruf:
https://github.com/conda-forge/staged-recipes/pull/10076#discussion_r348721448
2020-02-07 09:12:15 -06:00
Ryan Volz
488a33cd9c python: Do not link against python lib for building an extension module.
This fixes a segmentation fault when trying to use the python module on
OSX when built with conda (unsure why it doesn't arise otherwise).
Instead of linking against the python library, it is proper to not link
against the library and, for OSX builds, add linker options for
"-undefined" and "dynamic_lookup". This is precisely what the CMake
FindPython module does for linking against the Python::Module target.

See https://blog.tim-smith.us/2015/09/python-extension-modules-os-x
and https://bugs.python.org/issue36721
2020-02-07 09:12:15 -06:00
Ryan Volz
ec96cc37a2 python: Fix internal library name (incl. suffix) to match filename.
Instead of renaming the library file, this sets the suffix in CMake so
that the filename turns out as desired and also linker references know
the correct name.
2020-02-07 09:12:15 -06:00
Brent Stapleton
400b00c343 rfnoc: adding RFNoC Python API
Adding Python bindings for the RFNoC API. This includes the
rfnoc_graph, noc_block_base, and several other supporting classes.

Templated functions are not currently supported. For example,
`rfnoc_graph::get_block` can only return the basic block controller.
2020-01-02 15:38:56 -08:00
Martin Braun
f83faf28b3 cmake: Remove ENABLE_PYTHON3 flag and simplify Python detection
- Makes use of more modern find_package(Python2/3) if available
- Moves almost all Python-related code to UHDPython.cmake
- ENABLE_PYTHON3 is no longer necessary
2019-05-24 14:17:13 -07:00
Martin Braun
422b55f2bf cmake: python: Remove stray message() 2019-05-21 09:40:05 -07:00
Brent Stapleton
f258d72e25 python: change CMake variable for library ext
Changing the CMake variable used in determining the extension of the 
Python API library for better cross-platform support.

Specifically, `CMAKE_SHARED_MODULE_SUFFIX` corresponds to .so for *nix
and MacOS, which is the extension Python expects.
2019-03-06 16:01:10 -08:00
Trung Tran
1dbc0229b7 python: cmake: Use native format for setup.py
setuptools isn't compatible with Unix style path on Windows 10
machines. We need to convert any path before running setuptools.

Signed-off-by: Trung Tran <trung.tran@ettus.com>
2019-02-25 15:20:47 -08:00
Martin Braun
692ddc71b1 python: Replace Boost.Python with PyBind11
This does not change the Python API itself, but it is still
a significant change. Most importantly, it removes the dependency on
Boost.Python.
2019-02-22 16:56:52 -08:00
Martin Braun
a69ab0c23a cmake: Update coding style to use lowercase commands
Also updates our coding style file.

Ancient CMake versions required upper-case commands.  Later command
names became case-insensitive.  Now the preferred style is lower-case.

Run the following shell code (with GNU compliant sed):

cmake --help-command-list | grep -v "cmake version" | while read c; do
  echo 's/\b'"$(echo $c | tr '[:lower:]' '[:upper:]')"'\(\s*\)(/'"$c"'\1(/g'
done > convert.sed \
&& git ls-files -z -- bootstrap '*.cmake' '*.cmake.in' \
'*CMakeLists.txt' | xargs -0 gsed -i -f convert.sed && rm convert.sed

(Make sure the backslashes don't get mangled!)
2018-11-14 14:10:09 -08:00
Marcus Müllr
89eac133ea python: Fixing Boost.Python initializer visibility
With Boost 1.64 to 1.65 (which, of course, Ubuntu LTS ships), the
`PyInit_Libraryname` are invisible when one sets the default visibility
to "hidden" (which is reasonable, and which we do).
2018-08-03 16:26:33 -07:00
Trung Tran
9805775200 uhd: python: CMakeLists.txt change dll to pyd
To support python api installer
2018-08-01 17:35:40 -07:00
Brent Stapleton
508023e0c7 python: Fixup for Python API install directory
The Python API should now be installed to
    `PREFIX/lib/pythonVER/dist-packages/uhd`
where the PREFIX is set by CMake and the Python version is determined
by the Python module `distutils`. This should match user expectations
much more than the previous behavior.

Behavior in Virtualenvs is unchanged.
2018-07-27 11:07:19 -07:00
Trung Tran
04987da515 cmake: add support to make python api installer on windows 2018-07-13 11:45:41 -07:00
Paul David
e74cf7635b python: Separating exposed Python data structures
- Separating exposed Python data structures into logical sections
- Exposes all of the multi_usrp API
- Adds a layer of Python for documentation and adding helper methods
- Adds improvements and fixes to the MultiUSRP object
- Includes additional exposed data structures (like time_spec_t, etc.)
- Add code to release the Python GIL during long C++ calls
2018-06-20 19:02:32 -05:00
Andrej Rode
22e24497a5 python: Initial commit of Python API
Initial commit of the Python API using Boost.Python. Bind the
MultiUSRP API for use in Python. Bindings intended to provide as
complete coverage as possible.
- Wrap most multi_usrp calls
- Adding multi channel send/recv examples in examples/python
- Adding setuptools support
- Initial attempt at binding the UHD types and filters
2018-06-20 19:02:32 -05:00