## START: Set by rpmautospec
## (rpmautospec version 0.3.5)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 8;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%global pypi_name esphomeflasher

Name:           python-%{pypi_name}
Version:        1.4.0
Release:        %autorelease
Summary:        Simple GUI tool to flash ESPs over USB

License:        MIT
URL:            https://github.com/esphome/esphome-flasher
# PyPI is missing the latest version, so use the GitHub tarball instead
Source0:        %{url}/archive/%{version}/esphome-flasher-%{version}.tar.gz
Source1:        io.esphome.esphomeflasher.desktop
Source2:        io.esphome.esphomeflasher.metainfo.xml

BuildArch:      noarch

BuildRequires:  desktop-file-utils
BuildRequires:  libappstream-glib
BuildRequires:  libicns-utils
BuildRequires:  python3-devel
BuildRequires:  sed

%global _description %{expand:
ESPHome-Flasher is a utility app for the ESPHome framework and is designed to
make flashing ESPs with ESPHome as simple as possible.}

%description %_description

%package -n     %{pypi_name}
Summary:        %{summary}

%description -n %{pypi_name} %_description

%prep
%autosetup -p1 -n esphome-flasher-%{version}
# Relax dependencies
sed -i requirements.txt \
    -e 's:esptool.*:esptool>=3.2:' \
    -e 's:wxpython.*:wxpython<5:'
# Extract icons
icns2png -x icon.icns

%generate_buildrequires
%pyproject_buildrequires -r

%build
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files %{pypi_name}

desktop-file-install --dir=%{buildroot}%{_datadir}/applications %{SOURCE1}
install -Dpm0644 icon_512x512x32.png %{buildroot}%{_datadir}/pixmaps/%{pypi_name}.png
install -Dpm0644 -t %{buildroot}%{_metainfodir} %{SOURCE2}
appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/*.metainfo.xml

%check
%pyproject_check_import

%files -n %{pypi_name} -f %{pyproject_files}
%license LICENSE
%doc README.md
%{_bindir}/%{pypi_name}
%{_datadir}/applications/io.esphome.esphomeflasher.desktop
%{_datadir}/pixmaps/%{pypi_name}.png
%{_metainfodir}/io.esphome.esphomeflasher.metainfo.xml

%changelog
* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.4.0-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Mon Jun 19 2023 Python Maint <python-maint@redhat.com> - 1.4.0-7
- Rebuilt for Python 3.12

* Fri Jan 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.4.0-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Fri Jul 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 1.4.0-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Wed Jun 15 2022 Python Maint <python-maint@redhat.com> - 1.4.0-4
- Rebuilt for Python 3.11

* Tue May 03 2022 Davide Cavalca <dcavalca@fedoraproject.org> - 1.4.0-3
- Relax esptool dependency; Fixes: RHBZ#2078840

* Fri Jan 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 1.4.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Thu Nov 18 2021 Davide Cavalca <dcavalca@fedoraproject.org> - 1.4.0-1
- Initial import; Fixes: RHBZ#2022223