%global pkgvers 0
%global scdate0 20250311
%global schash0 79142965ce04763603919946a3090ce7c9c7dce9
%global branch0 develop
%global source0 https://github.com/platformio/platformio-core.git

%global sshort0 %{expand:%%{lua:print(('%{schash0}'):sub(1,8))}}

Name:           python-platformio
Version:        %(curl -s https://raw.githubusercontent.com/platformio/platformio-core/%{schash0}/platformio/__init__.py | grep ^VERSION | cut -d'(' -f2 | cut -d')' -f1 | sed 's|[ "]||g' | sed 's|,|.|g' | sed 's|[a-z,A-Z].*||')
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        Professional collaborative platform for embedded development
BuildArch:      noarch

License:        ASL 2.0

URL:            https://platformio.org

BuildRequires:  git python3 python3-devel python3-setuptools systemd-rpm-macros

%global _python_dist_allow_version_zero 1

%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.}

%global _python_dist_allow_version_zero 1

%description    %_description

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

%description -n python3-platformio %_description

%package -n     platformio
Summary:        %{summary}
Requires:       python3-platformio = %{version}-%{release}

%description -n platformio %_description
This package contains the PlatformIO command-line utilites and udev rules.


%prep
%setup -T -c -n %{name}
git clone --depth 1 -n -b %{branch0} %{source0} .
git fetch --depth 1 origin %{schash0}
git reset --hard %{schash0}
git log --format=fuller
%generate_buildrequires


%build
%py3_build


%install
%py3_install

# replace duplicate binary with symlink
ln -sf platformio %{buildroot}%{_bindir}/pio
# install udev rules
mkdir -p %{buildroot}%{_udevrulesdir}
ln -s %{python3_sitelib}/scripts/99-platformio-udev.rules \
      %{buildroot}%{_udevrulesdir}/
# trim dependency
sed -i '/^\[/!s/[<=>].*//g' %{buildroot}%{python3_sitelib}/*.egg-info/requires.txt
sed -i 's|Requires-Dist: ||g' %{buildroot}%{python3_sitearch}/*.egg-info/PKG-INFO || true
sed -i 's|Provides-Extra: ||g' %{buildroot}%{python3_sitearch}/*.egg-info/PKG-INFO || true



%files -n python3-platformio
%license LICENSE
%doc README.rst HISTORY.rst
%{python3_sitelib}/*

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


%changelog
%autochangelog