1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#!/usr/bin/env python
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# Copyright (C) 2021 Analog Devices, Inc.
# Author: Travis Collins <travis.collins@analog.com>
from setuptools import setup, find_packages
from setuptools.command.install import install
config = dict(long_description_content_type="text/markdown")
description = "Device specific library for AD936X transceivers"
try:
with open("${CMAKE_CURRENT_SOURCE_DIR}/README.md", "r") as fh:
long_description = fh.read()
except:
long_description = description
def find_recursive(folder, filename):
import os
for root, dirs, files in os.walk(folder):
for file in files:
if file == filename:
return os.path.join(root, file)
class InstallWrapper(install):
"""Before installing we check if the
libad9361 library is actually installed"""
def run(self):
self._check_libad9361_installed()
# Run the standard PyPi copy
install.run(self)
def _check_libad9361_installed(self):
lib_check = ("${LIB_CHECK_PYINSTALL}" == "OFF")
if lib_check:
# When cross-compiling or installing from git, we generally cannot
# dlopen the libad9361 shared lib from the build platform.
# Simply skip this check in that case.
return
from platform import system as _system
from ctypes import CDLL as _cdll
from ctypes.util import find_library
if "Windows" in _system():
_ad9361lib = "libad9361.dll"
else:
# Non-windows, possibly Posix system
_ad9361lib = "ad9361"
try:
import os
destdir = os.getenv("DESTDIR", "")
if destdir:
destdir = os.path.join("${CMAKE_BINARY_DIR}", destdir)
fulllibpath = find_recursive(destdir, "libad9361.so")
_lib = _cdll(fulllibpath, use_errno=True, use_last_error=True)
else:
_lib = _cdll(find_library(_ad9361lib), use_errno=True, use_last_error=True)
if not _lib._name:
raise OSError
except OSError:
msg = "The libad9361 library could not be found.\n\
libad9361 needs to be installed first before the python bindings.\n\
The latest release can be found on GitHub:\n\
https://github.com/analogdevicesinc/libad9361-iio/releases"
raise Exception(msg)
config.update(
dict(
name="pylibad9361",
version="${VERSION}",
maintainer="Analog Devices, Inc",
maintainer_email="travis.collins@analog.com",
description=description,
long_description=long_description,
url="https://github.com/analogdevicesinc/libad9361",
install_requires=["pylibiio==0.23.1"],
py_modules=["ad9361"],
packages=find_packages(exclude=["test*"]),
python_requires=">=3.6",
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)
|