File home-assistant.spec of Package home-assistant

#
# spec file for package python-sybil
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%global flavor @BUILD_FLAVOR@%{nil}
%if "%{flavor}" == "experimental"
%define pkgsuffix -experimental
%bcond_without experimental
%define eq_or_ge >=
%else
%define pkgsuffix %{nil}
%bcond_with experimental
%define eq_or_ge =
%endif


%{?!python_module:%define python_module() python-%{**} python311-%{**}}
%define skip_python2 1
# must be a single on or the rest of spec file won't work
%define pythons python313
# last time we used this, so try to pull in all the optional modules
%define oldpythons python312

%bcond_with     test

Name:           home-assistant%{pkgsuffix}
Version:        2024.03~beta
Release:        0
Summary:        Smart Home Management
License:        Apache-2.0
Group:          Development/Languages/Python
Url:            https://home-assistant.io/
Source:         home-assistant-%{version}.tar.xz
Source1:        home-assistant.service
Source2:        home-assistant.xml
Source3:        home-assistant-webhooks.xml
# downloading and executing code from remote is considered to be a backdoor
Patch2: disable-updater.patch
BuildRequires:  %{python_module aiohttp}
BuildRequires:  %{python_module astral}
BuildRequires:  %{python_module devel}
BuildRequires:  %{python_module Jinja2}
BuildRequires:  %{python_module MarkupSafe}
BuildRequires:  %{python_module PyYAML}
BuildRequires:  %{python_module pytz}
BuildRequires:  %{python_module requests}
BuildRequires:  %{python_module poetry-core}
BuildRequires:  %{python_module pip}
BuildRequires:  %{python_module typing}
BuildRequires:  %{python_module virtualenv}
BuildRequires:  %{python_module voluptuous}
BuildRequires:  %{python_module setuptools}
BuildRequires:  %{python_module wheel}
BuildRequires:  %{python_module PyDispatcher}

%if %{with test}
BuildRequires:  %{python_module pytest}
BuildRequires:  %{python_module requests_mock}
%endif

BuildRequires:  fdupes
BuildRequires:  python-rpm-macros

# homeassistant.components.ihc
# homeassistant.components.namecheapdns
# homeassistant.components.ohmconnect
# homeassistant.components.upc_connect
Recommends:  %pythons-defusedxml %{eq_or_ge} 0.6.0

# homeassistant.components.cloud
Recommends: %pythons-hass-nabucasa %{eq_or_ge} 0.34.7

# homeassistant.components.mobile_app
Recommends:  %pythons-emoji %{eq_or_ge} 0.5.4

# Assuming one is not using way slower sqlite
Recommends:  %pythons-mysqlclient

BuildRequires:  %pythons
Requires:  %pythons

# for useradd call
Requires(pre): shadow

# startup fails otherwise, but not part of core deps
Requires: %pythons-pyotp
Requires: %pythons-PyQRCode

# get all core requirements
# drop all deps to version 1000000000.0.0 because it should be part of core python
%( tar xf %{S:0} --wildcards \*/homeassistant/package_constraints.txt --wildcards \*/requirements.txt --to-command='grep -v ^# | grep -v ^$ | grep -v ^tuf\> | grep -v ";python_version<.3.13."  | sed -n -e "s,;python_version>=.3.13.,," -e "/^google-cloud-pubsub.*/d" -e '/!=/d' -e '/^pysnmplib=/d' -e "s,\[[^\]*],," -e "s,\(.*\)\(.=\)\(.*\),Requires: %pythons-\1 \2 \3,p" | sed -e "s,==,%{eq_or_ge}," -e "s,!=,>," -e /1000000000.0.0/d -e "s/.<[0-9.]*$//" -e "/audioop-lts/d" -e "s, ~= , == ,"' )

# Pull in python module in the version from all list, to enforce the right version,
# if package is installed for current or former python version
%( tar xf %{S:0} --wildcards \*/requirements_all.txt --to-command='grep -v ^# | grep -v ^$ | grep -v ^- | grep -v ";python_version<.3.13." | sed -e "s,\[[^\]*],," -e "s,;python_version<.3.13.,,"  -e "s,\(.*\)\(.=\)\(.*\),Requires: (%pythons-\1 \2 \3 if (%oldpythons-\1 or %pythons-\1)),"' )

%if %{with experimental}
Conflicts: home-assistant
%else
Conflicts: home-assistant-experimental
%endif

%systemd_requires

BuildArch:      noarch

%description
Open source home automation that puts local control and privacy first.
%if %{with experimental}

This experimental package differs from the non-experimental one in that
dependencies do not require exact versions but just minimum ones.
This allows to use Home Assistant with updated python packages but
also adds the possibility of having compatibility problems.
%endif

%prep
%setup -q -n home-assistant-%{version}
%patch -P2 -p1
%if %{with experimental}
sed -i -e "s/\"\([A-Za-z0-9_.-]\+\)==\([0-9]\+\.[0-9]\+\)/\"\1>=\2/" setup.py
sed -i -e "s/\"\([A-Za-z0-9_.-]\+\)==\([0-9]\+\.[0-9]\+\)/\"\1>=\2/g" homeassistant/components/*/manifest.json
sed -i -e "s/^\(REQUIREMENTS = .*\)\"\([A-Za-z0-9_.-]\+\)==\([0-9]\+\.[0-9]\+\)/\1\"\2>=\3/g" homeassistant/auth/mfa_modules/notify.py homeassistant/auth/mfa_modules/totp.py homeassistant/scripts/check_config.py
sed -i -e "s/^\(REQUIREMENTS = .*\)\"\([A-Za-z0-9_.-]\+\)==\([0-9]\+\.[0-9]\+\)/\1\"\2>=\3/g" homeassistant/auth/mfa_modules/totp.py
sed -i -e "s/^\([A-Za-z0-9_.-]\+\)==\([0-9]\+\.[0-9]\+\)/\1>=\2/" homeassistant/package_constraints.txt
sed -i -e "s/^\([A-Za-z0-9_.-]\+\)==\([0-9]\+\.[0-9]\+\)/\1>=\2/" requirements_all.txt
%endif

chmod -x homeassistant/components/lcn/services.yaml
chmod -x homeassistant/components/repetier/manifest.json
chmod -x homeassistant/components/dynalite/manifest.json

%build
%python_exec -m script.translations develop --all
%pyproject_wheel

%install
%pyproject_install
%python_expand %fdupes %{buildroot}%{$python_sitelib}

mkdir -p '%{buildroot}'%{_sbindir}
ln -sf service '%{buildroot}'%{_sbindir}/rchome-assistant
install -D -m 644 %{_sourcedir}/home-assistant.service '%{buildroot}'%{_unitdir}/home-assistant.service
# Create hass alias name
ln -s home-assistant.service '%{buildroot}'%{_unitdir}/hass.service

mkdir -p %{buildroot}/%{_prefix}/lib/firewalld/services/
install -D -m 644 %{SOURCE2} %{buildroot}/%{_prefix}/lib/firewalld/services/
install -D -m 644 %{SOURCE3} %{buildroot}/%{_prefix}/lib/firewalld/services/

%if %{with test}
%check
#sed -i -e "s/'coveralls'/'python-coveralls'/" setup.py
#%{python_expand virtualenv-%$python_bin_suffix --system-site-packages --no-download testvenv-%$python_bin_suffix
#testvenv-%$python_bin_suffix/bin/pip install -e .[test,build]
#export PYTHONPATH=$PWD/testvenv-%$python_bin_suffix/lib/python%$python_bin_suffix/site-packages/:$PWD
#testvenv-%$python_bin_suffix/bin/python -m pytest && rm -Rf testvenv-%$python_bin_suffix
#}

%python_exec -m pytest tests -k "not (TestTimeout and connect)"
%endif

%pre -n home-assistant%{pkgsuffix}
getent passwd hass >/dev/null || \
    /usr/sbin/useradd -r -m -s %{_sbindir}/nologin \
    -c "Home Assitant User" hass
%service_add_pre home-assistant.service
exit 0

%preun -n home-assistant%{pkgsuffix}
%service_del_preun home-assistant.service

%post -n home-assistant%{pkgsuffix}
%service_add_post home-assistant.service

%postun -n home-assistant%{pkgsuffix}
%service_del_postun home-assistant.service

%files
%doc README.rst
%license LICENSE.md
%_unitdir/hass.service
%_unitdir/home-assistant.service
%_bindir/hass
%_sbindir/rchome-assistant
%{python_sitelib}/*
%dir %{_prefix}/lib/firewalld
%dir %{_prefix}/lib/firewalld/services
%{_prefix}/lib/firewalld/services/home-assistant.xml
%{_prefix}/lib/firewalld/services/home-assistant-webhooks.xml

%changelog
openSUSE Build Service is sponsored by