#
# spec file for package python-suse-edge-components-versions
#
# Copyright (c) 2025 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 mod_name suse-edge-components-versions
%global pythons %{primary_python}
%if 0%{?suse_version} == 1500
%sle15_python_module_pythons
%endif

Name:           python-suse-edge-components-versions
Version:        0.2.2
Release:        0%{?dist}
Summary:        A tool to gather and display component versions for SUSE Edge products.
License:        Apache-2.0
URL:            https://github.com/suse-edge/support-tools/tree/main/components-versions
#!RemoteAsset: https://github.com/suse-edge/support-tools/archive/refs/tags/components-versions-v%{version}.tar.gz
Source:         components-versions-v%{version}.tar.gz
BuildArch:      noarch

BuildRequires:  python-rpm-macros
BuildRequires:  %{python_module pip}
BuildRequires:  %{python_module setuptools}
BuildRequires:  %{python_module setuptools_scm}
BuildRequires:  %{python_module wheel}

# Requires:
Requires:       %{python_module kubernetes}
Requires:       %{python_module pyhelm3}
Requires:       %{python_module tabulate}
Requires:       %{python_module pydantic >= 2.0}
Requires:       helm

# This macro automatically creates subpackages for each Python version
# (e.g., python311-suse-edge-components-versions, python312-suse-edge-components-versions).
%python_subpackages

%description
This tool provides functionality to gather and display component versions
for various SUSE Edge products. It helps in understanding the exact versions
of software components used in different product releases and ensures
consistency across deployments.

%prep
# Unpack the source tarball.
# The tarball extracts into 'support-tools-components-versions-v%{version}'.
%setup -q -n support-tools-components-versions-v%{version}

%build

# The actual Python project (containing pyproject.toml and the source code)
# is nested inside the 'components-versions' directory within the extracted tarball.
# We need to change into this directory before building.
cd components-versions
%pyproject_wheel .
cd ..

%install
cd components-versions
%pyproject_install
# Rename the main executable from 'components-versions' to 'suse-edge-components-versions'
mv %{buildroot}%{_bindir}/components-versions %{buildroot}%{_bindir}/suse-edge-components-versions
%python_clone -a %{buildroot}%{_bindir}/suse-edge-components-versions
cd ..
# Move the yaml files to /usr/share/suse-edge-components-versions instead
mkdir -p %{buildroot}/usr/share/suse-edge-components-versions/
mv %{buildroot}%{python_sitelib}/components_versions/data/*.yaml %{buildroot}/usr/share/suse-edge-components-versions/
rmdir %{buildroot}%{python_sitelib}/components_versions/data/

%post
%python_install_alternative suse-edge-components-versions

%postun
%python_uninstall_alternative suse-edge-components-versions

%files %{python_files}
%license LICENSE
%{python_sitelib}/components_versions
# Include the Python package metadata (e.g., .dist-info or .egg-info).
# The .dist-info name is based on the 'name' field in pyproject.toml.
%{python_sitelib}/suse_edge_components_versions-%{version}*.dist-info
# Include the main executable with its new name.
%python_alternative %{_bindir}/suse-edge-components-versions
# Include the yaml files
/usr/share/suse-edge-components-versions/

%changelog
