%bcond_with dotests

%global __tar /opt/freeware/bin/tar

%global py_major 3.9
%global py_minor 16

%global python_major python%{py_major}

%global pkgname backports_tarfile

%global meta_package python3-backports_tarfile

%global python3_sitearch %(%{python_major} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(0))")
%global python3_sitearch64 %(%{python_major} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")

Name:           %{python_major}-%{pkgname}
Version:        1.2.0
Release:        1
Summary:        Backport of CPython tarfile module with compression support improvements
License:        MIT
URL:            https://pypi.org/project/backports.tarfile/
Source0:        https://files.pythonhosted.org/packages/source/b/%{pkgname}/%{pkgname}-%{version}.tar.gz
BuildArch:      noarch
Group:          Development/Libraries
Prefix:         %{_prefix}


BuildRequires:  %{python_major}-devel >= %{py_major}.%{py_minor}
BuildRequires:  %{python_major}-setuptools >= 65.2.0

Requires:       %{python_major} >= %{py_major}.%{py_minor}


%description
backports.tarfile is a backport of the CPython tarfile module that provides
improved compression support including the filter argument introduced in
Python 3.12 (PEP 706). It allows users on Python 3.8+ to benefit from the
latest tarfile security and feature improvements without upgrading Python.
This package is typically required by setuptools and other build tools as
a dependency.


%package -n %{meta_package}
Summary:        Meta-package for %{name}

Requires:       python3 >= %{py_major}.%{py_minor}
Requires:       %{name} = %{version}-%{release}

%description -n %{meta_package}
This is a Meta-package for %{name} package.


%prep
%autosetup -n %{pkgname}-%{version}


%build
#Nothing to build


%install
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}
%{python_major} -m pip install . --root %{buildroot} -I --no-deps


%check
%if %{with dotests}

%{python_major} -m venv python_venv
. ./python_venv/bin/activate
%{python_major} -m pip install pytest
ulimit -d unlimited
ulimit -n unlimited
ulimit -m unlimited
%{python_major} -m pytest -v || true
deactivate

%endif


%clean
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}


%files
%defattr(-,root,system,-)
%doc LICENSE README.rst
%{python3_sitearch}/*

%files -n %{meta_package}
%defattr(-,root,system,-)

%changelog
* Thu Jun 26 2025 Kushal Verma <kushal.verma1@ibm.com> - 1.2.0-1
- Initial port for AIX Toolbox
- backports.tarfile for python3.9
- Version 1.2.0 is the latest compatible with Python 3.9 (requires Python >= 3.8)
