## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 2;
    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 forgeurl https://github.com/platformio/platformio-core
%global pypi_name platformio
%global srcname platformio-core

# Tests require Internet access
%bcond tests 0

Name:           python-%{pypi_name}
Version:        6.1.17
Release:        %autorelease
Summary:        Professional collaborative platform for embedded development

License:        Apache-2.0
URL:            https://platformio.org
# PyPI is missing tests, so use the GitHub tarball instead
Source:         %{forgeurl}/archive/v%{version}/%{srcname}-%{version}.tar.gz
# Fedora: disable telemetry by default
Patch1:         platformio-default-telemetry-off.patch
# Fedora: neuter update logic for platformio itself
Patch2:         platformio-short-circuit-upgrades.patch
# Allow starlette versions through 0.46
# https://github.com/platformio/platformio-core/pull/5094
Patch3:         %{forgeurl}/pull/5094.patch

BuildArch:      noarch
BuildRequires:  python3-devel
BuildRequires:  systemd-rpm-macros

%global _description %{expand:
PlatformIO is a cross-platform, cross-architecture, multiple framework,
professional tool for embedded systems engineers and for software developers
who write applications for embedded products.}

%description %_description

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

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

%package -n     %{pypi_name}
Summary:        %{summary}
Requires:       python3-%{pypi_name} = %{version}-%{release}
Requires:       systemd-udev

%description -n %{pypi_name} %_description

This package contains the PlatformIO command-line utilites and udev rules.

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

%generate_buildrequires
%pyproject_buildrequires -t

%build
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files %{pypi_name}

# Replace duplicate binary with symlink
ln -sf platformio %{buildroot}%{_bindir}/pio

# Install udev rules
mkdir -p %{buildroot}%{_udevrulesdir}
ln -s %{python3_sitelib}/%{pypi_name}/assets/system/99-platformio-udev.rules \
  %{buildroot}%{_udevrulesdir}/

%check
%if %{with tests}
%tox -e testcore
%else
# Exclude modules that require platformio-managed dependencies
%pyproject_check_import -e 'platformio.builder.*' -e 'platformio.remote.*'
%endif

%files -n python3-%{pypi_name} -f %{pyproject_files}
%doc README.rst HISTORY.rst

%files -n %{pypi_name}
%{_bindir}/pio
%{_bindir}/piodebuggdb
%{_bindir}/platformio
%{_udevrulesdir}/99-platformio-udev.rules

%changelog
## START: Generated by rpmautospec
* Thu Feb 27 2025 Benjamin A. Beasley <code@musicinmybrain.net> - 6.1.17-2
- Allow starlette versions through 0.46

* Sat Feb 22 2025 Davide Cavalca <dcavalca@fedoraproject.org> - 6.1.17-1
- Update to 6.1.17; Fixes: RHBZ#2345545

* Sat Jan 18 2025 Fedora Release Engineering <releng@fedoraproject.org> - 6.1.16-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild

* Sun Dec 29 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 6.1.16-5
- Allow starlette versions through 0.45

* Thu Dec 19 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 6.1.16-4
- Allow Starlette 0.42.x

* Mon Oct 28 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 6.1.16-3
- Allow Starlette 0.41.x

* Tue Oct 15 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 6.1.16-2
- Allow Starlette 0.40.x (a security update)

* Fri Sep 27 2024 Carl George <carlwgeorge@fedoraproject.org> - 6.1.16-1
- Update to version 6.1.16 rhbz#2277120

* Tue Sep 24 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 6.1.14-6
- Use Bottle 0.13 instead of 0.12 on Fedora 42 and later

* Tue Sep 24 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 6.1.14-5
- Allow Starlette 0.39.x

* Tue Jul 23 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 6.1.14-4
- Allow Starlette 0.38.1

* Fri Jul 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 6.1.14-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Sun Jun 16 2024 Python Maint <python-maint@redhat.com> - 6.1.14-2
- Rebuilt for Python 3.13

* Sat Mar 23 2024 Davide Cavalca <dcavalca@fedoraproject.org> - 6.1.14-1
- Update to 6.1.4; Fixes: RHBZ#2270045, RHBZ#2270849

* Fri Feb 09 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 6.1.13-4
- Backport a commit to allow Starlette versions up to 0.37

* Fri Jan 26 2024 Fedora Release Engineering <releng@fedoraproject.org> - 6.1.13-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Mon Jan 22 2024 Fedora Release Engineering <releng@fedoraproject.org> - 6.1.13-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Fri Jan 12 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 6.1.13-1
- Update to 6.1.13 (close RHBZ#2257712)

* Tue Jan 09 2024 Davide Cavalca <dcavalca@fedoraproject.org> - 6.1.11-1
- Initial import; Fixes: RHBZ#2021751
## END: Generated by rpmautospec