Skip to content

Commit

Permalink
Merge 2cb00ac into c8e5314
Browse files Browse the repository at this point in the history
  • Loading branch information
nocarryr committed Aug 1, 2023
2 parents c8e5314 + 2cb00ac commit cbc9ccb
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 28 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/dist-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ name: Test Distribution
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
allow_deploy:
Expand Down Expand Up @@ -39,7 +41,8 @@ jobs:
python-version: ["2.7", "3.8", "3.9", "3.10", "3.11"]
dist-type: [sdist, wheel]
fail-fast: false

env:
LD_LIBRARY_PATH: ''
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -48,6 +51,7 @@ jobs:
python-version: ${{ matrix.python-version }}
cache-build: true
- name: Build librtlsdr
if: ${{ matrix.python-version == 2.7 }}
run: |
sudo apt-get install -y libusb-1.0-0-dev
cd tools/ci
Expand All @@ -73,10 +77,14 @@ jobs:
- name: Install sdist
if: ${{ matrix.dist-type == 'sdist' }}
run: pip install dist/*.tar.gz
- name: Install pyrtlsdrlib
if: ${{ matrix.python-version != 2.7 }}
run: pip install pyrtlsdrlib
- name: Test distribution
run: |
LD_LIBRARY_PATH=${{ env.NEW_LD_LIBPATH }} py.test --cov-config .coveragerc --cov=rtlsdr
LD_LIBRARY_PATH=${{ env.NEW_LD_LIBPATH }} py.test --cov-append --cov-config .coveragerc --cov=rtlsdr --forked --no-overrides --pyargs tests/no_override*
py.test --cov-config .coveragerc --cov=rtlsdr
py.test --cov-append --cov-config .coveragerc --cov=rtlsdr --no-overrides --pyargs tests/no_override_client_mode.py
py.test --cov-append --cov-config .coveragerc --cov=rtlsdr --no-overrides --pyargs tests/no_override_dll_loader.py
deploy:
needs: test
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/lib-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test pyrtlsdrlib integration

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: MatteoH2O1999/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
cache-build: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -U pytest pytest-cov
pip install numpy
- name: Install pyrtlsdr with lib
run: pip install -e '.[lib]'
- name: Test with pytest
shell: bash
run: |
py.test --cov-config .coveragerc --cov=rtlsdr
py.test --cov-append --cov-config .coveragerc --cov=rtlsdr --no-overrides --pyargs tests/no_override_client_mode.py
py.test --cov-append --cov-config .coveragerc --cov=rtlsdr --no-overrides --pyargs tests/no_override_dll_loader.py
32 changes: 26 additions & 6 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ on:
jobs:
test:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["2.7", "3.8", "3.9", "3.10", "3.11"]
fail-fast: false
os: [ubuntu-latest, macos-latest, windows-latest]

exclude:
- os: macos-latest
python-version: "2.7"
- os: windows-latest
python-version: "2.7"

fail-fast: false
env:
LD_LIBRARY_PATH: ''
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -27,6 +36,7 @@ jobs:
python-version: ${{ matrix.python-version }}
cache-build: true
- name: Build librtlsdr
if: ${{ matrix.python-version == 2.7 }}
run: |
sudo apt-get install -y libusb-1.0-0-dev
cd tools/ci
Expand All @@ -36,13 +46,23 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -U pytest pytest-forked pytest-cov
pip install -U pytest pytest-cov
pip install numpy
pip install -e .
- name: Install pyrtlsdr with lib
if: ${{ matrix.python-version != 2.7 }}
run: pip install -e '.[lib]'
- name: Install pyrtlsdr
run: pip install -e .
if: ${{ matrix.python-version == 2.7 }}

- name: Test with pytest
shell: bash
run: |
LD_LIBRARY_PATH=${{ env.NEW_LD_LIBPATH }} py.test --cov-config .coveragerc --cov=rtlsdr
LD_LIBRARY_PATH=${{ env.NEW_LD_LIBPATH }} py.test --cov-append --cov-config .coveragerc --cov=rtlsdr --forked --no-overrides --pyargs tests/no_override*
py.test --cov-config .coveragerc --cov=rtlsdr
py.test --cov-append --cov-config .coveragerc --cov=rtlsdr --no-overrides --pyargs tests/no_override_client_mode.py
py.test --cov-append --cov-config .coveragerc --cov=rtlsdr --no-overrides --pyargs tests/no_override_dll_loader.py
env:
LD_LIBRARY_PATH: ${{ env.NEW_LD_LIBPATH }}
- name: Set up Python3 for coveralls
if: ${{ matrix.python-version == 2.7 }}
uses: actions/setup-python@v2
Expand Down
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,32 @@ and also provides a more Pythonic API.
* Releases for `librtlsdr`:
* https://github.com/librtlsdr/librtlsdr/releases

# Usage
# Installation

pyrtlsdr can be installed by downloading the source files and running `python setup.py install`, or using [pip](https://pip.pypa.io/en/stable/) and
`pip install pyrtlsdr`.

## Full installation (recommended)

**New in version 0.3.0**

On most platforms, the `librtlsdr` binaries may be also installed with the [pyrtlsdrlib](https://github.com/pyrtlsdr/pyrtlsdrlib) package. This new feature should *drastically* simplify the installation process (especially for Windows).

This can be done by installing `pyrtlsdrlib` separately (via pip) or for simplicity, both can be installed at once via:

```bash
pip install pyrtlsdr[lib]
```

If errors are encountered with the `pyrtlsdrlib` integration (during installation or package import),
you may want to ensure you have the latest versions of both:

```bash
pip install --upgrade pyrtlsdr[lib]
```

# Usage

All functions in librtlsdr are accessible via librtlsdr.py and a Pythonic interface is available in rtlsdr.py (recommended).
Some documentation can be found in docstrings in the latter file.

Expand Down Expand Up @@ -172,7 +193,11 @@ function you need to add support for, and please send a pull request if you'd li
* Some operating systems (Linux, OS X) seem to result in libusb buffer issues when performing small reads. Try reading 1024
(or higher powers of two) samples at a time if you have problems.

* If you're having librtlsdr import errors:
## librtlsdr import errors

First try upgrading `pyrtlsdr` and using the `pyrtlsdrlib` helper package described above.

* In cases where that isn't feasible:
* **Windows**: Make sure all the librtlsdr DLL files (librtlsdr.dll, libusb-1.0.dll) are in your system path, or the same folder
as this README file. Also make sure you have all of *their* dependencies (e.g. libgcc_s_dw2-1.dll or possibly the Visual Studio runtime files). If rtl_sdr.exe
works, then you should be okay. Also note that you can't mix the 64 bit version of Python with 32 bit builds of librtlsdr, and vice versa.
Expand Down
10 changes: 10 additions & 0 deletions rtlsdr/librtlsdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@
from ctypes import *
from ctypes.util import find_library

try:
import pyrtlsdrlib
except ImportError:
pyrtlsdrlib = None

def load_librtlsdr():
# If pyrtlsdrlib is intalled try its loader first
if pyrtlsdrlib is not None:
dll = pyrtlsdrlib.load_librtlsdr()
if dll is not None:
return dll
if sys.platform == "linux" and 'LD_LIBRARY_PATH' in os.environ.keys():
ld_library_paths = [local_path for local_path in os.environ['LD_LIBRARY_PATH'].split(':') if local_path.strip()]
driver_files = [local_path + '/librtlsdr.so' for local_path in ld_library_paths]
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ project_urls =
Source = https://github.com/pyrtlsdr/pyrtlsdr
long_description = file: README.md,
long_description_content_type = text/markdown

[options.extras_require]
lib = pyrtlsdrlib
22 changes: 5 additions & 17 deletions tests/no_override_dll_loader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ctypes

import pytest

@pytest.fixture(autouse=True)
Expand All @@ -6,21 +8,7 @@ def librtlsdr_override(request):
"""
return

@pytest.fixture(params=[True, False])
def librtlsdr_missing(request, monkeypatch):
class FakeCDLL(object):
def __init__(self, *args):
raise Exception()
if request.param:
monkeypatch.setattr('ctypes.CDLL', FakeCDLL)
return request.param

@pytest.mark.no_overrides
def test_dll_loader(librtlsdr_missing):
if librtlsdr_missing:
with pytest.raises(ImportError):
import rtlsdr
from rtlsdr import rtlsdr
print(rtlsdr.p_rtlsdr_dev)
else:
import rtlsdr
def test_dll_loader():
import rtlsdr
assert isinstance(rtlsdr.librtlsdr, ctypes.CDLL)

0 comments on commit cbc9ccb

Please sign in to comment.