File searx.spec of Package searx

#
# spec file for package searx
#
# Copyright (c) 2022 Samu Voutilainen
#
# 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 real_name searx
%define pythons python3

Name:           python-searx
Version:        1.0.0
Release:        0
Summary:        Privacy-respecting, hackable metasearch engine
License:        AGPL-3.0
Group:          Productivity/Networking/Web/Utilities
URL:            https://github.com/searx/searx
#Source0:        %%{URL}/releases/download/%%{version}/searx-%%{version}.tar.gz
Source0:        searx-%{version}.tar.xz
BuildRequires:  %{python_module setuptools}
BuildRequires:  fdupes
BuildRequires:  python-rpm-macros
# For tests
#BuildRequires:  ca-certificates
BuildArch:      noarch

%python_subpackages

%description
Searx is a free internet metasearch engine which aggregates results from
more than 70 search services. Users are neither tracked nor profiled.

Additionally, searx can be used over Tor for online anonymity.

%package lang
Summary:        Translations for package %{name}
Group:          System/Localization
Requires:       %{name} = %{version}
Provides:       %{name}-lang-all = %{version}
Supplements:    %{name}
BuildArch:      noarch

%description lang
Provides translations for the "%{name}" package.

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

%build
%python_build

%install
%python_install

%{python_expand # the structure is not compatible with (python_)find_lang. Roll our own.
find %{buildroot}%{$python_sitelib}/searx/translations -type f -o -type l | grep -v '__init__' > lang-files
sed -E '
    s:%{buildroot}::
    s:(.*/searx/translations/)([^/_]+)(.*(mo|po|json)$):%lang(\2) \1\2\3:
' > %{$python_prefix}-%{real_name}.lang < lang-files
sed -E '
    s:%{buildroot}::
    s:(.*/searx/translations/)([^/_]+)(.*(mo|po|json)$):%exclude \1\2\3:
' > %{$python_prefix}-%{real_name}.lang-exclude < lang-files
find %{buildroot}%{$python_sitelib}/searx/translations -type d -mindepth 1 | grep -v '__pycache__' > lang-dirs
sed -E '
    s:%{buildroot}::
    s:(.*):%dir \1:
' >> %{$python_prefix}-%{real_name}.lang < lang-dirs
sed -E '
    s:%{buildroot}::
    s:(.*):%exclude %dir \1:
' >> %{$python_prefix}-%{real_name}.lang-exclude < lang-dirs
}

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

%check
#make run
# Tests are failing to ssl certificate errors, not dealing with it now.
#make test

%files %{python_files} -f %{python_prefix}-%{real_name}.lang-exclude
%doc CHANGELOG* README*
%license LICENSE
%{python_sitelib}/*
%{_bindir}/%{real_name}-checker
%{_bindir}/%{real_name}-run

%files %{python_files lang} -f %{python_prefix}-%{real_name}.lang
%license LICENSE

%changelog