%global srcname streamdeck
%global modname StreamDeck

Name:           python-%{srcname}
Version:        0.8.2
Release:        1%{?dist}
Summary:        Python Elgato Stream Deck Library

License:        MIT
URL:            https://pypi.org/project/streamdeck
Source0:        %{pypi_source}
Patch0:         streamdeck-udev-rules.patch

BuildArch:      noarch

%global _description %{expand:
This is an open source Python 3 library to control an Elgato Stream Deck
directly, without the official software. This can allow you to create your own
custom front-ends, such as a custom control front-end for home automation
software.}

%description %_description

%package -n python3-%{srcname}
Summary:        %{summary}
BuildRequires:  python3-devel
BuildRequires:  python3-setuptools

Requires:       python3-pillow hidapi

%description -n python3-%{srcname} %_description

%prep
%autosetup -n %{srcname}-%{version} -p1

%build
%py3_build

%install
%py3_install
mkdir -p %{buildroot}/etc/udev/rules.d
cp 99-streamdeck.rules %{buildroot}/etc/udev/rules.d

%check
%{python3} setup.py test

%post
udevadm control --reload-rules

%postun
if [ $1 == 0 ]; then
    udevadm control --reload-rules
fi

# Note that there is no %%files section for the unversioned python module
%files -n python3-%{srcname}
%license LICENSE
%doc README.md
%{python3_sitelib}/%{srcname}-*.egg-info/
%{python3_sitelib}/%{modname}/
/etc/udev/rules.d/99-streamdeck.rules