## START: Set by rpmautospec
## (rpmautospec version 0.6.0)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 1;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%global pypi_name spdx-tools
%global github_name tools-python

Name:           python-%{pypi_name}
Version:        0.8.2
Release:        %autorelease
Summary:        Python library to parse, validate and create SPDX documents

License:        Apache-2.0
URL:            https://github.com/spdx/tools-python
Source:         %url/archive/v%{version}/%{github_name}-%{version}.tar.gz

BuildArch:      noarch
BuildRequires:  help2man
BuildRequires:  python3-devel
BuildRequires:  python3dist(pyshacl)
BuildRequires:  python3dist(pytest)

%global common_description %{expand:
Python library to parse, validate and create SPDX documents.

Features:

 - API to create and manipulate SPDX v2.2 and v2.3 documents
 - Parse, convert, create and validate SPDX files
 - supported formats: Tag/Value, RDF, JSON, YAML, XML
 - visualize the structure of a SPDX document by creating an AGraph. Note: This
   is an optional feature and requires additional installation of optional
   dependencies.
 - experimental support for the upcoming SPDX v3 specification. Note, however,
   that support is neither complete nor stable at this point, as the spec is
   still evolving. SPDX3-related code is contained in a separate subpackage
   "spdx3" and its use is optional. We do not recommend using it in production
   code yet.}

%description %{common_description}

%package -n python3-%{pypi_name}
Summary:        %{summary}

%description -n python3-%{pypi_name} %{common_description}

%prep
%autosetup -p1 -n %{github_name}-%{version}
sed -i '/\[tool\.setuptools_scm\]/a fallback_version = "%{version}"' pyproject.toml
for lib in $(find . -type f -iname "*.py"); do
 sed '1{\@^#!/usr/bin/env python@d}' $lib > $lib.new &&
 touch -r $lib $lib.new &&
 mv $lib.new $lib
done

%generate_buildrequires
%pyproject_buildrequires

%build
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files spdx_tools
mkdir -p %{buildroot}%{_mandir}/man1/
PYTHONPATH=%{buildroot}%{python3_sitelib} help2man --no-discard-stderr --version-string=%{version} -s 1 -N -o %{buildroot}%{_mandir}/man1/pyspdxtools.1 %{buildroot}%{_bindir}/pyspdxtools

%check
%pytest -k "not test_spdx2_convert_to_spdx3 and not test_json_writer and not test_write_tag_value"
rm -rfv %{buildroot}%{python3_sitelib}/spdx_tools/spdx/parser/tagvalue/parser.out \
        %{buildroot}%{python3_sitelib}/spdx_tools/spdx/parser/tagvalue/parsetab.py

%files -n python3-%{pypi_name} -f %{pyproject_files}
%doc CHANGELOG.md CONTRIBUTING.md README.md 
%doc examples/
%license LICENSE
%{_bindir}/pyspdxtools*
%{_mandir}/man1/pyspdxtools.1*

%changelog
## START: Generated by rpmautospec
* Wed Jun 19 2024 Robert-André Mauchin <zebob.m@gmail.com> - 0.8.2-1
- Update to 0.8.2

* Fri Jan 26 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Mon Jan 22 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Wed Nov 01 2023 Robert-André Mauchin <zebob.m@gmail.com> - 0.7.1-1
- Initial import
## END: Generated by rpmautospec