diff --git a/python/README.md b/python/README.md index fec7b73..c6e9978 100644 --- a/python/README.md +++ b/python/README.md @@ -16,6 +16,23 @@ pyoprf offers Python bindings for the liboprf library, allowing integration of O pip install pyoprf ``` +If you need optional transport dependencies: + +- `ble` installs `ble_serial` +- `usb` installs `pyudev` +- `all` installs both `ble_serial` and `pyudev` + +```bash +# Bluetooth support +pip install "pyoprf[ble]" + +# USB support +pip install "pyoprf[usb]" + +# All optional transports +pip install "pyoprf[all]" +``` + ### Installing from source ```bash diff --git a/python/pyoprf/multiplexer.py b/python/pyoprf/multiplexer.py index 92b8b57..46d76ac 100755 --- a/python/pyoprf/multiplexer.py +++ b/python/pyoprf/multiplexer.py @@ -110,6 +110,8 @@ def close(self): class BLEPeer: def __init__(self, name, addr, server_pk, client_sk, device="hci0", timeout=5): + if BLE_client is None: + raise ImportError("BLE support requires optional dependency 'ble_serial'. Install pyoprf with the 'ble' extra, e.g. 'pip install pyoprf[ble]'.") self.name = name self.address = addr # the MAC address of the device self.server_pk = server_pk @@ -278,6 +280,8 @@ async def read_raw(self,size): class USBPeer: def __init__(self, name, serno, server_pk, client_sk, timeout=5): + if pyudev is None: + raise ImportError("USB support requires optional dependency 'pyudev'. Install pyoprf with the 'usb' extra, e.g. 'pip install pyoprf[usb]'.") self.name = name self.serno = serno # the serial number of the usb device self.server_pk = server_pk diff --git a/python/setup.py b/python/setup.py index 912ff1b..b5d9ecd 100755 --- a/python/setup.py +++ b/python/setup.py @@ -20,11 +20,12 @@ def read(fname): license = "LGPLv3", author = 'Stefan Marsiske', author_email = 'toprf@ctrlc.hu', - url = 'https://github.com/stef/liboprf/python', + url = 'https://github.com/stef/liboprf/tree/master/python', long_description=read('README.md'), long_description_content_type="text/markdown", packages=find_packages(), - install_requires = ("pysodium", "SecureString", "pyserial", "pyudev", "ble_serial", "pyserial-asyncio"), + install_requires = ("pysodium", "SecureString", "pyserial", "pyserial-asyncio"), + extras_require = {"ble": ("ble_serial",), "usb": ("pyudev",), "all": ("ble_serial", "pyudev")}, classifiers = ["Development Status :: 4 - Beta", "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", "Topic :: Security :: Cryptography",