File python-solar.spec of Package python-solar

# If they aren't provided by a system installed macro, define them
%{!?_defaultdocdir: %global _defaultdocdir %{_datadir}/doc}

%if 0%{?suse_version} && 0%{?suse_version} < 1600
%global __python3 /usr/bin/python3.11
%global python3_pkgversion 311
%else
%{!?__python3: %global __python3 /usr/bin/python3}
%{!?python3_pkgversion:%global python3_pkgversion 3}
%endif

%if %{undefined python3_sitelib}
%if "%{_vendor}" == "debbuild"
%global python3_sitelib %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
%else
%global python3_sitelib %(%{__python3} -c "import sysconfig; print(sysconfig.get_path('platlib'))")
%endif
%endif

%if %{undefined python3_version}
%global python3_version %(%{__python3} -Esc "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))")
%endif

%if %{undefined python3_version_nodots}
%global python3_version_nodots %(%{__python3} -Esc "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")
%endif

%if 0%{?debian} || 0%{?ubuntu}
%global is_deb 1
%global pygroup python
%global sysgroup admin
%global develsuffix dev
%else
%global pygroup Development/Languages/Python
%global sysgroup System/Management
%global develsuffix devel
%endif

Name:           python-solar
Version:        0.0.1
Release:        0
Summary:        solar - zero power
License:        GPL-3.0-or-later
%if "%{_vendor}" == "debbuild"
# Needed to set Maintainer in output debs
Packager:       Marcus Schaefer <marcus.schaefer@gmail.com>
%endif
Group:          %{pygroup}
Source0:        %{name}.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?fedora} || 0%{?suse_version}
BuildRequires:  fdupes
%endif
BuildRequires:  python%{python3_pkgversion}-%{develsuffix} >= 3.9
BuildRequires:  python%{python3_pkgversion}-build
BuildRequires:  python%{python3_pkgversion}-installer
BuildRequires:  python%{python3_pkgversion}-poetry-core >= 1.2.0
BuildRequires:  python%{python3_pkgversion}-wheel
BuildRequires:  python%{python3_pkgversion}-typer
BuildRequires:  python%{python3_pkgversion}-requests
%if 0%{?debian} || 0%{?ubuntu}
# only because of debbuild
BuildRequires:  python%{python3_pkgversion}-setuptools
%endif

%description
Home Solar system to control inverter for zero power injection

# python3-solar
%package -n python%{python3_pkgversion}-solar
Summary:        solar - zero power
Group:          %{pygroup}
%if 0%{?suse_version}
Provides:       python%{python3_version_nodots}-solar = %{version}-%{release}
%else
Provides:       python%{python3_version}-solar = %{version}-%{release}
%endif
Requires:       python%{python3_pkgversion} >= 3.9
Requires:       python%{python3_pkgversion}-typer
Requires:       python%{python3_pkgversion}-requests

%description -n python%{python3_pkgversion}-solar
Home Solar system to control inverter for zero power injection

%prep
%setup -q -n solar-%{version}

# Build application wheel
%{__python3} -m build --no-isolation --wheel

%install
# Install service file
install -d -m 755 %{buildroot}/usr/lib/systemd/system
install -m 644 systemd/solar.service \
    %{buildroot}/usr/lib/systemd/system/solar.service
# Install application
%{__python3} -m installer --destdir %{buildroot} %{?is_deb:--no-compile-bytecode} dist/*.whl

%if 0%{?is_deb}
# Fix where files were installed
mv %{buildroot}%{_prefix}/local/* %{buildroot}%{_prefix}
mv %{buildroot}%{_prefix}/lib/python3* %{buildroot}%{_prefix}/lib/python3
%endif

# Install documentation LICENSE
make buildroot=%{buildroot}/ docdir=%{_defaultdocdir}/ python=%{__python3} install_package_docs

%files -n python%{python3_pkgversion}-solar
%dir %{_defaultdocdir}/python-solar
%{_bindir}/solar
%{python3_sitelib}/solar*
%{_defaultdocdir}/python-solar/LICENSE
%config %{_usr}/lib/systemd/system/solar.service

%changelog
openSUSE Build Service is sponsored by