%global python_package_src command_line_assistant
%global binary_name c
%global daemon_binary_name clad

Name:           command-line-assistant
Version:        0.1.0
Release:        2.20241220131254813477.develop.17.g4e17eb6%{?dist}
Summary:        A simple wrapper to interact with RAG

License:        Apache-2.0
URL:            https://github.com/rhel-lightspeed/command-line-assistant
Source0:        command-line-assistant-0.1.0.tar.gz
# noarch because there is no extension module for this package.
BuildArch:      noarch

BuildRequires:  python3-devel
BuildRequires:  python3-setuptools
BuildRequires:  python3-wheel
BuildRequires:  python3-pip
BuildRequires:  systemd-units

Requires:       python3-dasbus
Requires:       python3-requests
Requires:       python3-colorama
Requires:       systemd

# Not needed after RHEL 10 as it is native in Python 3.11+
%if 0%{?rhel} && 0%{?rhel} < 10
BuildRequires:  python3-tomli
Requires:       python3-tomli
%endif

%description
A simple wrapper to interact with RAG

%prep
%autosetup -n command-line-assistant-0.1.0

%build
%py3_build_wheel

%install
%py3_install_wheel %{python_package_src}-%{version}-py3-none-any.whl

# Create sbin directory in buildroot
%{__install} -d %{buildroot}/%{_sbindir}
%{__install} -d %{buildroot}/%{_sysconfdir}/xdg/%{python_package_src}

# Move the daemon to /usr/sbin instead of /usr/bin
%{__install} -m 0755 %{buildroot}/%{_bindir}/%{daemon_binary_name} %{buildroot}/%{_sbindir}/%{daemon_binary_name}
%{__rm} %{buildroot}/%{_bindir}/%{daemon_binary_name}

# System units
%{__install} -D -m 0644 data/release/%{daemon_binary_name}.service %{buildroot}/%{_unitdir}/%{daemon_binary_name}.service
%{__install} -D -m 0644 data/release/com.redhat.lightspeed.conf %{buildroot}/%{_sysconfdir}/dbus-1/system.d/com.redhat.lightspeed.conf

# Config file
%{__install} -D -m 0644 data/release/config.toml %{buildroot}/%{_sysconfdir}/xdg/%{python_package_src}/config.toml

%files
%doc README.md
%license LICENSE
%{python3_sitelib}/%{python_package_src}/
%{python3_sitelib}/%{python_package_src}-%{version}.dist-info/

# Binaries
%{_bindir}/%{binary_name}
%{_sbindir}/%{daemon_binary_name}

# System units
%{_unitdir}/%{daemon_binary_name}.service

# Config file
%config %{_sysconfdir}/xdg/%{python_package_src}/config.toml
%config %{_sysconfdir}/dbus-1/system.d/com.redhat.lightspeed.conf

%preun
if [ "$1" -eq 0 ]; then
    systemctl stop %{daemon_binary_name}.service || :
    systemctl disable %{daemon_binary_name}.service || :
fi

%changelog
* Fri Dec 20 2024 Packit <hello@packit.dev> - 0.1.0-2.20241220131254813477.develop.17.g4e17eb6
- Add local history management and improve the command (#74) (Rodolfo Olivieri)
- The connect_signals was triggered the API request twice (#73) (Rodolfo Olivieri)
- Add schema for input/output queries and history (#70) (Rodolfo Olivieri)
- Switch to system bus instead of session bus (#69) (Rodolfo Olivieri)
- Split the query and history dbus implementations (#66) (Rodolfo Olivieri)
- Update specfile to include config from release dir (#68) (Rodolfo Olivieri)
- Enable copr builds in develop (#67) (Rodolfo Olivieri)
- [RSPEED-279] Add Command Line Assistant Daemon (#58) (Rodolfo Olivieri)
- Update dependency coverage to v7.6.9 (#60) (renovate[bot])
- Add an experimental rendering module for client (#62) (Rodolfo Olivieri)
- Refactor the CLI to be separate commands (#61) (Rodolfo Olivieri)
- Add Pull Request template to keep description orgainzed (#49) (Rodolfo Olivieri)
- Update dependency pytest to v8.3.4 (#57) (renovate[bot])
- Add CODEOWNERS file (#52) (Rodolfo Olivieri)
- Remove container testing from pipeline (#51) (Martin "kokesak" Litwora)
- Add more test cases to cover the recent features (#34) (Rodolfo Olivieri)
- Update dependency coverage to v7.6.8 (#48) (renovate[bot])

* Fri Dec 20 2024 Packit <hello@packit.dev> - 0.1.0-2
- latest upstream build