File python-comfyui.spec of Package python-comfyui

#
# spec file for package python-hatch
#
# Copyright (c) 2024 SUSE LLC
#
# 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 https://bugs.opensuse.org/
#

%global flavor @BUILD_FLAVOR@%{nil}
%if "%{flavor}" == "test"
%define psuffix -test
%bcond_without test
%else
%define psuffix %{nil}
%bcond_with test
%endif

%{?sle15_python_module_pythons}
%define pythons python311
Name:           python-comfyui%{?psuffix}
Version:        0.3.5.post0
Release:        0
Summary:        The most powerful and modular diffusion model GUI and backend
License:        MIT
URL:            https://www.comfy.org/
Source0:        https://github.com/comfyanonymous/ComfyUI/archive/refs/tags/v%{version}.tar.gz#/comfyui-%{version}.tar.gz
Source1:        comfyui.service
Source2:        comfyui-user.conf

BuildRequires:  %{python_module base >= 3.8}
BuildRequires:  %{python_module hatch-vcs >= 0.3}
BuildRequires:  %{python_module hatchling >= 1.19}
BuildRequires:  %{python_module pip}
BuildRequires:  fdupes
BuildRequires:  python-rpm-macros
BuildRequires:  sysuser-tools

Requires:       python-pytorch
Requires:       python-torchsde
Requires:       python-torchvision
Recommends:     python-torchaudio
Requires:       python-einops
Requires:       python-transformers >= 4.28.1
Requires:       python-tokenizers >= 0.13.3
Requires:       python-sentencepiece
Requires:       python-safetensors >= 0.4.2
Requires:       python-aiohttp
Requires:       python-PyYAML
Requires:       python-Pillow
Requires:       python-scipy
Requires:       python-tqdm
Requires:       python-psutil

Requires(post): update-alternatives
Requires(postun): update-alternatives
Requires:       comfyui-shared

Recommends:     python-kornia >= 0.7.1
Recommends:     python-spandrel
Recommends:     python-soundfile
%if %{with test}
BuildRequires:  %{python_module comfyui = %{version}}
BuildRequires:  %{python_module pytest-aiohttp}
BuildRequires:  %{python_module pytest-asyncio}
BuildRequires:  %{python_module pytest >= 7.8.0}
%else
BuildArch:      noarch
%endif
%python_subpackages

%description
%summary

%package     -n comfyui-shared
Summary:        %summary
%sysusers_requires

%description -n comfyui-shared
This package contains shared data files and systemd configuration files for ComfyUI.

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

%build
%if !%{with test}
%sysusers_generate_pre %{SOURCE2} comfyui comfyui-user.conf

%pyproject_wheel
%endif

%install
%if !%{with test}
%pyproject_install
%{__mkdir_p} %{buildroot}%{_localstatedir}/lib/
%{__mv} %{buildroot}%{_datadir}/comfyui %{buildroot}%{_localstatedir}/lib/comfyui
install -D -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/comfyui.service
install -D -m 0644 %{SOURCE2} %{buildroot}%{_sysusersdir}/comfyui-user.conf
%python_clone -a %{buildroot}%{_bindir}/comfyui
%python_expand %fdupes %{buildroot}%{$python_sitelib}
%endif

%check
%if %{with test}
export LANG=en_US.UTF-8
%pytest -v tests-unit
%endif

%post
%python_install_alternative comfyui
%end

%postun
%python_uninstall_alternative comfyui
%end

# systemd configuration
%pre -n comfyui-shared -f comfyui.pre
%service_add_pre comfyui.service
%end

%post -n comfyui-shared
%service_add_post comfyui.service
%end

%preun -n comfyui-shared
%service_del_preun comfyui.service
%end

%postun -n comfyui-shared
%service_del_postun comfyui.service
%end

%if !%{with test}
%files %{python_files}
%python_alternative %{_bindir}/comfyui
%{python_sitelib}/comfyui
%{python_sitelib}/comfyui-%{version}.dist-info

%files -n comfyui-shared
%doc README.md
%license LICENSE
%{_unitdir}/comfyui.service
%{_sysusersdir}/comfyui-user.conf
%attr(-, comfyui, comfyui) %{_localstatedir}/lib/comfyui
%endif

%changelog
openSUSE Build Service is sponsored by