Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/python_bindings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Build, test, and deploy Python bindings
name: Python bindings

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
container: tfcollins/libiio_ubuntu_22_04-ci:latest

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-pip python3-virtualenv python3-venv

- name: Install C library
run: |
mkdir build && cd build
cmake ..
make -j
sudo make install
sudo ldconfig
cd ..

- name: Build Python bindings
run: |
python3 -m venv venv
source venv/bin/activate
pip3 install build
cd bindings/python
python3 -m build
pip install dist/*.whl
cd ../..
shell: bash

- name: Test Python bindings
run: |
source venv/bin/activate
python3 -c "import iio"
shell: bash

- name: Archive Python bindings
uses: actions/upload-artifact@v4
with:
name: python-wheel
path: bindings/python/dist/*.whl
10 changes: 2 additions & 8 deletions CI/build_win.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ mkdir build-x64
cp .\libiio.iss.cmakein .\build-x64
cd build-x64

cmake -G "$COMPILER" -DPYTHON_EXECUTABLE:FILEPATH=$(python -c "import os, sys; print(os.path.dirname(sys.executable) + '\python.exe')") -DCMAKE_SYSTEM_PREFIX_PATH="C:" -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DENABLE_IPV6=ON -DWITH_USB_BACKEND=ON -DWITH_SERIAL_BACKEND=ON -DPYTHON_BINDINGS=ON -DCPP_BINDINGS=ON -DCSHARP_BINDINGS:BOOL=$USE_CSHARP -DLIBXML2_LIBRARIES="C:\\libs\\64\\libxml2.lib" -DLIBUSB_LIBRARIES="C:\\libs\\64\\libusb-1.0.lib" -DLIBSERIALPORT_LIBRARIES="C:\\libs\\64\\libserialport.dll.a" -DLIBUSB_INCLUDE_DIR="C:\\include\\libusb-1.0" -DLIBXML2_INCLUDE_DIR="C:\\include\\libxml2" -DLIBZSTD_INCLUDE_DIR="C:\\include" -DLIBZSTD_LIBRARIES="C:\\libs\\64\\libzstd.dll.a" ..
cmake -G "$COMPILER" -DCMAKE_SYSTEM_PREFIX_PATH="C:" -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DENABLE_IPV6=ON -DWITH_USB_BACKEND=ON -DWITH_SERIAL_BACKEND=ON -DCPP_BINDINGS=ON -DCSHARP_BINDINGS:BOOL=$USE_CSHARP -DLIBXML2_LIBRARIES="C:\\libs\\64\\libxml2.lib" -DLIBUSB_LIBRARIES="C:\\libs\\64\\libusb-1.0.lib" -DLIBSERIALPORT_LIBRARIES="C:\\libs\\64\\libserialport.dll.a" -DLIBUSB_INCLUDE_DIR="C:\\include\\libusb-1.0" -DLIBXML2_INCLUDE_DIR="C:\\include\\libxml2" -DLIBZSTD_INCLUDE_DIR="C:\\include" -DLIBZSTD_LIBRARIES="C:\\libs\\64\\libzstd.dll.a" ..

cmake --build . --config Release
if ( $LASTEXITCODE -ne 0 ) {
throw "[*] cmake build failure"
}
cp .\libiio.iss $env:BUILD_ARTIFACTSTAGINGDIRECTORY

cd bindings/python
python.exe setup.py sdist
Get-ChildItem dist\pylibiio-*.tar.gz | Rename-Item -NewName "libiio-py39-amd64.tar.gz"
mv .\dist\*.gz .
rm .\dist\*.gz
cp .\libiio.iss $env:BUILD_ARTIFACTSTAGINGDIRECTORY
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ set(CMAKE_HTML_DEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/html/v${VERSION}")

option(CPP_BINDINGS "Install C++ bindings" OFF)
option(CSHARP_BINDINGS "Install C# bindings" OFF)
option(PYTHON_BINDINGS "Install Python bindings" OFF)
add_subdirectory(bindings)

option(WITH_MAN "Generate on-line reference manuals (man pages)" OFF)
Expand Down
3 changes: 1 addition & 2 deletions README_BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Cmake Options | Default | Target | Description
`WITH_MODULES` | OFF | All | Build modular backends |
'COMPILE_WARNING_AS_ERROR' | OFF | All | Make all C warnings into errors |
`CPP_BINDINGS` | OFF | All | Install C++ bindings (C++17 required for examples) |
`PYTHON_BINDINGS` | OFF | All | Install PYTHON bindings |
`WITH_UTILS` | ON | All | Build the utility programs (iio-utils) |
`WITH_EXAMPLES` | OFF | All | Build the example programs |
`NO_THREADS` | OFF | All | Disable multi-threading support |
Expand Down Expand Up @@ -125,7 +124,7 @@ Cmake Options | Default | Description |
```shell
analog@precision:~/libiio$ mkdir build
analog@precision:~/libiio/build$ cd build
analog@precision:~/libiio/build$ cmake ../ -DCPP_BINDINGS=ON -DPYTHON_BINDINGS=ON
analog@precision:~/libiio/build$ cmake ../ -DCPP_BINDINGS=ON
analog@precision:~/libiio/build$ make -j$(nproc)
```

Expand Down
22 changes: 5 additions & 17 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ stages:
set -e
mkdir build && cd build
if [ "$ARTIFACTNAME" != "Linux-CentOS-7" ]; then
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DENABLE_PACKAGING=ON -DPYTHON_BINDINGS=ON -DCPP_BINDINGS=ON -DWITH_DOC=ON -DWITH_SERIAL_BACKEND=ON -DWITH_MAN=ON -DCPACK_SYSTEM_NAME=${ARTIFACTNAME}
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DENABLE_PACKAGING=ON -DCPP_BINDINGS=ON -DWITH_DOC=ON -DWITH_SERIAL_BACKEND=ON -DWITH_MAN=ON -DCPACK_SYSTEM_NAME=${ARTIFACTNAME}
else
# CentOS 7 does not have new enough kernel headers to support modern libusb, nor libserialport, nor stdatomics.h
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DENABLE_PACKAGING=ON -DPYTHON_BINDINGS=ON -DWITH_DOC=ON -DWITH_MAN=ON -DCPACK_SYSTEM_NAME=${ARTIFACTNAME} -DWITH_USB_BACKEND=OFF -DWITH_IIOD_USBD=OFF -DWITH_LOCAL_MMAP_API=OFF
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DENABLE_PACKAGING=ON -DWITH_DOC=ON -DWITH_MAN=ON -DCPACK_SYSTEM_NAME=${ARTIFACTNAME} -DWITH_USB_BACKEND=OFF -DWITH_IIOD_USBD=OFF -DWITH_LOCAL_MMAP_API=OFF
fi
make
make package
Expand Down Expand Up @@ -163,12 +163,6 @@ stages:
libiio.dll
libiio.dll.a
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: CopyFiles@2
displayName: 'Copy .tar.gz files'
inputs:
sourceFolder: '$(Agent.BuildDirectory)/s/build-x64/bindings/python'
contents: '*.gz'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PowerShell@2
displayName: 'Copy dependencies'
inputs:
Expand Down Expand Up @@ -243,12 +237,6 @@ stages:
sourceFolder: '$(Agent.BuildDirectory)/s/build-$(ARCH)/utils/Release'
contents: '*.exe'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: CopyFiles@2
displayName: 'Copy .tar.gz files'
inputs:
sourceFolder: '$(Agent.BuildDirectory)/s/build-x64/bindings/python'
contents: '*.gz'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: CopyFiles@2
displayName: 'Copy libiio-sharp.dll file'
inputs:
Expand Down Expand Up @@ -329,15 +317,15 @@ stages:
- script: |
set -e
mkdir build && cd build
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DOSX_PACKAGE=ON -DPYTHON_EXECUTABLE:FILEPATH=$(python -c "import os, sys; print(os.path.dirname(sys.executable) + '/python')") -DPYTHON_BINDINGS=ON -DWITH_EXAMPLES=ON -DWITH_SERIAL_BACKEND=ON
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DOSX_PACKAGE=ON -DWITH_EXAMPLES=ON -DWITH_SERIAL_BACKEND=ON
make
sudo make install
cd ..
displayName: 'Build'
- script: |
set -e
mkdir build_tar && cd build_tar
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DOSX_PACKAGE=OFF -DENABLE_PACKAGING=ON -DPYTHON_EXECUTABLE:FILEPATH=$(python -c "import os, sys; print(os.path.dirname(sys.executable) + '/python')") -DPYTHON_BINDINGS=ON -DWITH_SERIAL_BACKEND=ON -DCPACK_SYSTEM_NAME=${ARTIFACTNAME}
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DOSX_PACKAGE=OFF -DENABLE_PACKAGING=ON -DWITH_SERIAL_BACKEND=ON -DCPACK_SYSTEM_NAME=${ARTIFACTNAME}
make
make package
mv ../CI/azure/macos_tar_fixup.sh .
Expand All @@ -348,7 +336,7 @@ stages:
- script: |
set -e
cd build
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DPYTHON_BINDINGS=ON -DWITH_DOC=ON -DWITH_SERIAL_BACKEND=ON
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DWITH_DOC=ON -DWITH_SERIAL_BACKEND=ON
make
cd ..
displayName: 'Build With Doc'
Expand Down
5 changes: 0 additions & 5 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ if (CSHARP_BINDINGS)
add_subdirectory(csharp)
endif()

if (PYTHON_BINDINGS)
add_subdirectory(python)
endif()

toggle_iio_feature("${PYTHON_BINDINGS}" python-bindings)
toggle_iio_feature("${CSHARP_BINDINGS}" "c#-bindings")
toggle_iio_feature("${CPP_BINDINGS}" "c++-bindings")

Expand Down
68 changes: 0 additions & 68 deletions bindings/python/CMakeLists.txt

This file was deleted.

12 changes: 7 additions & 5 deletions bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ To install these bindings there are a few methods. If you already have the libra
(sudo) pip install pylibiio
```
If you do not want to use pip, then installation is dependent on your operating system.
#### Linux / macOS
For Linux and macOS the python bindings need to be installed through source if not using pip. For v0.20 and beyond this requires the `-DPYTHON_BINDINGS=ON` flag during the cmake configuration. Further documentation is located [here](https://github.com/analogdevicesinc/libiio/blob/master/README_BUILD.md).

#### Windows
Only pip installation is supported.
#### Install from source
To install from source, you will need to clone the repository and invoke pip within the python bindings directory:
```shell
git clone https://github.com/analogdevicesinc/libiio.git
cd libiio/bindings/python
pip install .
```

### Support
If you have a question about libiio or the python bindings and an Analog Devices IIO kernel driver please ask on : [![EngineerZone](https://img.shields.io/badge/chat-on%20EngineerZone-blue.svg)](https://ez.analog.com/linux-device-drivers/linux-software-drivers). If you have a question about a non-ADI devices, please ask it on [github](https://github.com/analogdevicesinc/libiio/issues).
Expand Down
20 changes: 15 additions & 5 deletions bindings/python/iio.py → bindings/python/iio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from ctypes.util import find_library
from enum import Enum
from os import strerror as _strerror
from os import path as _path
from platform import system as _system
import abc

Expand Down Expand Up @@ -295,12 +296,21 @@ class ChannelType(Enum):
_AttrPtr = _POINTER(_Attr)

if "Windows" in _system():
_iiolib = "libiio.dll"
_lib_loc = find_library("libiio1.dll")
else:
# Non-windows, possibly Posix system
_iiolib = "iio"

_lib = _cdll("libiio.so.1", use_errno=True, use_last_error=True)
_lib_loc = find_library("iio")
if _path.islink(_lib_loc):
_lib_loc = _path.realpath(_lib_loc)
if _lib_loc is not None:
filename = _path.basename(_lib_loc)
version = filename.split(".so.")[1]
if version[0] != "1":
raise OSError(2, f"libiio version 1.x required, found version {version}")

if _lib_loc is None:
raise OSError(2, "Could not find libiio C library")
_lib = _cdll(_lib_loc, use_errno=True, use_last_error=True)
_libc = _cdll(find_library("c"))

_get_backends_count = _lib.iio_get_builtin_backends_count
Expand Down Expand Up @@ -723,7 +733,7 @@ def iio_strerror(err, buf, length):

version = _get_lib_version()
backends = [_get_backend(b).decode("ascii") for b in range(0, _get_backends_count())]

bindings_version = "1.0"

class _IIO_Object(object):
def __init__(self, hdl, parent):
Expand Down
36 changes: 36 additions & 0 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[build-system]
requires = ["setuptools>=40.6.0"]
build-backend = "setuptools.build_meta"

[project]
name = "pylibiio"
dynamic = ["version", "readme"]
description = "Analog Devices python interfaces for hardware with Industrial I/O drivers"
license = { text = "LGPL-2-or-later" }
classifiers = [
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Libraries :: Python Modules",
]
requires-python = ">=3.7"
maintainers = [{ name = "Analog Devices, Inc" }]

[tool.setuptools.dynamic]
version = { attr = "iio.bindings_version" }
readme = { file = "README.md", content-type = "text/markdown" }

[tool.setuptools.packages.find]
where = ["."]
include = ["iio"]
exclude = ["doc", "examples"]

[project.urls]
homepage = "https://analogdevicesinc.github.io/libiio/"
documentation = "https://analogdevicesinc.github.io/libiio/"
repository = "https://github.com/analogdevicesinc/libiio"
Loading
Loading