From 21023a538b125dee966bf496dcad019ee20967bd Mon Sep 17 00:00:00 2001 From: Travis Collins Date: Fri, 17 Jan 2020 19:51:38 -0500 Subject: [PATCH 1/4] Update python bindings installer for pypi packaging. Installer has been updated to support python2 and python3, and will check to see if libiio installed before actually installing the bindings. This is primarily useful for pip users. Signed-off-by: Travis F. Collins --- .travis.yml | 1 + bindings/python/setup.py.cmakein | 82 ++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5b3c5e62b..e78684243 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: c sudo: required +python: "3.6" env: global: diff --git a/bindings/python/setup.py.cmakein b/bindings/python/setup.py.cmakein index 9d93a66cb..56747ceb7 100644 --- a/bindings/python/setup.py.cmakein +++ b/bindings/python/setup.py.cmakein @@ -13,11 +13,77 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. -from distutils.core import setup - -setup(name='libiio', - version='${VERSION}', - description='Library to use the Industrial IO devices', - url='https://github.com/analogdevicesinc/libiio', - py_modules=['iio'], - ) +import sys + +if sys.version_info[0] < 3: + from distutils.core import setup + from distutils.command.install import install + + config = dict() +else: + from setuptools import setup + from setuptools.command.install import install + + config = dict(long_description_content_type="text/markdown") + +description = "Library for interfacing with Linux IIO devices" + +try: + with open("${CMAKE_SOURCE_DIR}/README.md", "r") as fh: + long_description = fh.read() +except: + long_description = description + + +class InstallWrapper(install): + """Before installing we check if the + libiio library is actually installed""" + + def run(self): + self._check_libiio_installed() + # Run the standard PyPi copy + install.run(self) + + def _check_libiio_installed(self): + from platform import system as _system + from ctypes import CDLL as _cdll + from ctypes.util import find_library + + if "Windows" in _system(): + _iiolib = "libiio.dll" + else: + # Non-windows, possibly Posix system + _iiolib = "iio" + try: + _lib = _cdll(find_library(_iiolib), use_errno=True, use_last_error=True) + if not _lib._name: + raise OSError + except OSError: + msg = "The libiio library could not be found.\n\ + libiio needs to be installed first before the python bindings.\n\ + The latest release can be found on GitHub:\n\ + https://github.com/analogdevicesinc/libiio/releases" + raise Exception(msg) + + +config.update( + dict( + name="libiio", + version="${VERSION}", + maintainer="Analog Devices, Inc", + maintainer_email="travis.collins@analog.com", + description=description, + long_description=long_description, + url="https://github.com/analogdevicesinc/libiio", + py_modules=["iio"], + cmdclass={"install": InstallWrapper}, + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)", + "Operating System :: OS Independent", + ], + ) +) + + +setup(**config) From 71cc9cbfe1b7330ef3685f78bf2e24318b15f04a Mon Sep 17 00:00:00 2001 From: "Travis F. Collins" Date: Wed, 29 Jan 2020 16:40:33 -0800 Subject: [PATCH 2/4] Add pypi to travis-ci providers for python bindings. Only the first x86 Linux build will push to pypi on tagged commits. Signed-off-by: Travis F. Collins --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.travis.yml b/.travis.yml index e78684243..baf9ddbc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,7 @@ matrix: # TODO do `check` or `check_hw` here too, not just `check_sw` (as part of `coverage`) - CHECK_RULE=coverage GCOV=1 - PKG_RULE=gzip + - PYPI=yes - COVERITY_SCAN_PROJECT_NAME="$TRAVIS_REPO_SLUG" - COVERITY_SCAN_BRANCH_PATTERN="master" - COVERITY_SCAN_NOTIFICATION_EMAIL="robin.getz@analog.com" @@ -114,6 +115,7 @@ before_deploy: - eval "$(ssh-agent -s)" - chmod 600 /tmp/deploy.rsa - ssh-add /tmp/deploy.rsa + - if [[ "$PYPI" == "yes" ]]; then cd "build/bindings/python"; fi deploy: - provider: releases api_key: @@ -152,6 +154,16 @@ deploy: on: condition: "$TRAVIS_OS_NAME = osx" all_branches: true + - provider: pypi + if: tag IS present + skip_cleanup: true + on: + tags: true + condition: "$PYPI = yes" + username: __token__ + password: + secure: KfORvnPyLlMANLpcwJjcO44Kt6meP614omJk2GloD+B51SuV64O6N31VDOTi2xqioEk9Cajq7tmNte5YoHVUjL9iWFsBblpzxZoXcy40dn4pFN0kMiE8scszxckbDwuBZhokUVZ2fhfLKf/8xORcwjS3vKqSj5HwQKKvVgukSbQ= + distributions: sdist after_deploy: - ${TRAVIS_BUILD_DIR}/CI/travis/after_deploy From 3ed4840e49fdb1771efe9d8eff1d3d72d54aa189 Mon Sep 17 00:00:00 2001 From: "Travis F. Collins" Date: Fri, 14 Feb 2020 15:50:06 -0800 Subject: [PATCH 3/4] Update appveyor build to use sdist build instead of bdist_wininst Signed-off-by: Travis F. Collins --- appveyor.yml | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 021e6787e..aa6c847d2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -90,16 +90,15 @@ build_script: - cmake --build . --config %configuration% - cd bindings/python - - python.exe setup.py bdist_wininst - - ps: Get-ChildItem dist\libiio-*.exe | Rename-Item -NewName "libiio-py37-win32.exe" - - ps: cp dist\*.exe . - - ps: rm dist\*.exe + - python.exe setup.py sdist + - ps: Get-ChildItem dist\libiio-*.tar.gz | Rename-Item -NewName "libiio-py37-win32.tar.gz" + - ps: cp dist\*.tar.gz . + - ps: rm dist\*.tar.gz - set PATH=C:\\Python36;C:\\Python36\\libs;%PATH% - - python.exe setup.py bdist_wininst - - ls dist - - ps: Get-ChildItem dist\libiio-*.exe | Rename-Item -NewName "libiio-py36-win32.exe" - - ps: cp dist\*.exe . - - ps: rm dist\*.exe + - python.exe setup.py sdist + - ps: Get-ChildItem dist\libiio-*.tar.gz | Rename-Item -NewName "libiio-py36-win32.tar.gz" + - ps: cp dist\*.tar.gz . + - ps: rm dist\*.tar.gz #MSVC 64 bit - set PATH=C:\Python37-x64;C:\\Python37-x64\\libs;%PATH% @@ -111,15 +110,15 @@ build_script: - cmake --build . --config %configuration% - cd bindings/python - - python.exe setup.py bdist_wininst - - ps: Get-ChildItem dist\libiio-*.exe | Rename-Item -NewName "libiio-py37-amd64.exe" - - ps: cp dist\*.exe . - - ps: rm dist\*.exe + - python.exe setup.py sdist + - ps: Get-ChildItem dist\libiio-*.tar.gz | Rename-Item -NewName "libiio-py37-amd64.tar.gz" + - ps: cp dist\*.tar.gz . + - ps: rm dist\*.tar.gz - set PATH=C:\Python36-x64;C:\\Python36-x64\\libs;%PATH% - - python.exe setup.py bdist_wininst - - ps: Get-ChildItem dist\libiio-*.exe | Rename-Item -NewName "libiio-py36-amd64.exe" - - ps: cp dist\*.exe . - - ps: rm dist\*.exe + - python.exe setup.py sdist + - ps: Get-ChildItem dist\libiio-*.tar.gz | Rename-Item -NewName "libiio-py36-amd64.tar.gz" + - ps: cp dist\*.tar.gz . + - ps: rm dist\*.tar.gz - cd c:\projects\libiio\build-win64 #Create the installer @@ -138,8 +137,8 @@ build_script: - copy build-win64\Release\libiio.* c:\%ARCHIVE_NAME%\MS64 - copy build-win32\bindings\csharp\libiio-sharp.dll c:\%ARCHIVE_NAME%\MS32 - copy build-win64\bindings\csharp\libiio-sharp.dll c:\%ARCHIVE_NAME%\MS64 - - copy build-win32\bindings\python\*.exe c:\%ARCHIVE_NAME%\MS32 - - copy build-win64\bindings\python\*.exe c:\%ARCHIVE_NAME%\MS64 + - copy build-win32\bindings\python\*.tar.gz c:\%ARCHIVE_NAME%\MS32 + - copy build-win64\bindings\python\*.tar.gz c:\%ARCHIVE_NAME%\MS64 - copy build-mingw-win32\Release\libiio.* c:\%ARCHIVE_NAME%\MinGW32 - copy build-mingw-win64\Release\libiio.* c:\%ARCHIVE_NAME%\MinGW64 - del c:\%ARCHIVE_NAME%\MinGW32\libiio.iss From 1725e420c301798b1b856b6ba9377b2db64fbd19 Mon Sep 17 00:00:00 2001 From: "Travis F. Collins" Date: Fri, 14 Feb 2020 16:39:32 -0800 Subject: [PATCH 4/4] Remove python bindings from windows installer. Pip will be used instead for all platforms Signed-off-by: Travis F. Collins --- libiio.iss.cmakein | 9 --------- 1 file changed, 9 deletions(-) diff --git a/libiio.iss.cmakein b/libiio.iss.cmakein index 73ff5df7e..cfd9d1a77 100644 --- a/libiio.iss.cmakein +++ b/libiio.iss.cmakein @@ -44,9 +44,6 @@ Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl" Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl" [Files] -Source: "C:\projects\libiio\build-win32\bindings\python\libiio-py37-win32.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall; -Source: "C:\projects\libiio\build-win64\bindings\python\libiio-py37-amd64.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall; - Source: "C:\projects\libiio\build-win32\Release\libiio.dll"; DestDir: "{sys}"; Flags: 32bit Source: "C:\projects\libiio\build-win64\Release\libiio.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode @@ -71,9 +68,3 @@ Source: "C:\projects\libiio\build-win32\bindings\csharp\libiio-sharp.dll"; DestD Source: "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\x86\Microsoft.VC120.CRT\msvcr120.dll"; DestDir: "{sys}"; Flags: onlyifdoesntexist 32bit Source: "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\x64\Microsoft.VC120.CRT\msvcr120.dll"; DestDir: "{sys}"; Check: Is64BitInstallMode; Flags: onlyifdoesntexist -[Tasks] -Name: "install_python_bindings"; Description: "Install libiio Python 3.7 bindings" - -[Run] -Filename: "{tmp}\libiio-py37-amd64.exe"; StatusMsg: "Installing Python bindings"; Check: Is64BitInstallMode; Tasks: install_python_bindings; Flags: skipifsilent -Filename: "{tmp}\libiio-py37-win32.exe"; StatusMsg: "Installing Python bindings"; Check: not Is64BitInstallMode; Tasks: install_python_bindings; Flags: skipifsilent