## START: Set by rpmautospec
## (rpmautospec version 0.3.5)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 2;
    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

# Sphinx-generated HTML documentation is not suitable for packaging; see
# https://bugzilla.redhat.com/show_bug.cgi?id=2006555 for discussion.
#
# We can generate PDF documentation as a substitute.
%bcond doc 1

Name:           python-libsass
Version:        0.22.0
Release:        %autorelease
Summary:        Sass for Python: A straightforward binding of libsass for Python

# SPDX
License:        MIT
URL:            https://github.com/dahlia/libsass-python
Source:         %{url}/archive/%{version}/libsass-python-%{version}.tar.gz

# 0.22.0: documentation seems is not ready for sphinx 6.1.3
# https://github.com/sass/libsass-python/issues/424
#
# doc: support sphinx 6.0 ext.extlinks
# https://github.com/sass/libsass-python/pull/433
Patch:          %{url}/pull/433.patch
# Add a missing word “to” in the description
# https://github.com/sass/libsass-python/pull/442
Patch:          %{url}/pull/442.patch
# Replace deprecated license_file with license_files in setup.cfg
# https://github.com/sass/libsass-python/pull/441
Patch:          %{url}/pull/441.patch

BuildRequires:  python3-devel

# Selected test dependencies from requirements-dev.txt; most entries in that
# file are for linters, code coverage, etc.
BuildRequires:  %{py3_dist pytest}
BuildRequires:  (%{py3_dist werkzeug} with %{py3_dist werkzeug} >= 0.9)

BuildRequires:  make
BuildRequires:  gcc-c++

BuildRequires:  libsass-devel >= 3.6.5

BuildRequires:  help2man
%if %{with doc}
BuildRequires:  %{py3_dist sphinx}
BuildRequires:  python3-sphinx-latex
BuildRequires:  latexmk
%endif

%global common_description %{expand:
This package provides a simple Python extension module sass which is binding
LibSass (written in C/C++ by Hampton Catlin and Aaron Leung). It’s very
straightforward and there isn’t any headache related to Python
distribution/deployment. That means you can add just libsass into your
setup.py’s install_requires list or requirements.txt file. No need for Ruby nor
Node.js.}

%description %{common_description}


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

# https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/
#   #_provides_for_importable_modules
# This package is messy; it occupies quite a few top-level names.
%py_provides python3-sass
%py_provides python3-pysassc
%py_provides python3-sasstests
%py_provides python3-sassutils

%description -n python3-libsass %{common_description}


%if %{with doc}
%package        doc
Summary:        Documentation for python-libsass

%description    doc %{common_description}
%endif


%prep
%autosetup -n libsass-python-%{version} -p1

# While upstream has the executable bit set, we will install this in
# site-packages without executable permissions; therefore, the shebang becomes
# useless, and we should remove it downstream.
sed -r -i '1{/^#!/d}' pysassc.py


%generate_buildrequires
export SYSTEM_SASS='1'
%pyproject_buildrequires


%build
export SYSTEM_SASS='1'
%pyproject_wheel

%if %{with doc}
LIB='lib.%{python3_platform}-cpython-%{python3_version_nodots}'
PYTHONPATH="${PWD}/build/${LIB}" %make_build -C docs latex \
    SPHINXOPTS='-j%{?_smp_build_ncpus}'
%make_build -C docs/_build/latex LATEXMKOPTS='-quiet'
%endif


%install
export SYSTEM_SASS='1'
%pyproject_install
%pyproject_save_files sass pysassc sasstests sassutils _sass

# We build the man page in %%install rather than %%build because we need to use
# the entry point in %%{buildroot}/%%{_bindir}.
install -d '%{buildroot}%{_mandir}/man1'
PYTHONPATH='%{buildroot}%{python3_sitearch}' \
    help2man --no-info --output='%{buildroot}%{_mandir}/man1/pysassc.1' \
    '%{buildroot}%{_bindir}/pysassc'


%check
%pytest -v sasstests.py


%files -n python3-libsass -f %{pyproject_files}
%if %{without doc}
%doc README.rst
%doc docs/changes.rst
%endif
%{_bindir}/pysassc
%{_mandir}/man1/pysassc.1*


%if %{with doc_pdf}
%files doc
%license LICENSE
%doc README.rst
%doc docs/changes.rst
%doc docs/_build/latex/libsass.pdf
%endif


%changelog
* Wed Sep 20 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.22.0-2
- Improve the source URL and archive name

* Thu Sep 14 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.22.0-1
- Update to 0.22.0 (close RHBZ#1873395)
- The “sassc” module is removed upstream; we already did not install
  /usr/bin/sassc due to conflicts with libsass.

* Wed Sep 13 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.21.0-2
- Build man page with help2man instead of Sphinx

* Wed Sep 13 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.21.0-1
- Update to 0.21.0

* Tue Sep 12 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.20.0-26
- Package the changelog as a text file, not only as part of the manual

* Tue Sep 12 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.20.0-25
- Package the manual in a -doc subpackage

* Mon Sep 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.20.0-23
- Confirm License is SPDX MIT

* Mon Sep 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.20.0-22
- Add py_provides for importable modules

* Mon Sep 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.20.0-21
- Replace deprecated license_file with license_files in setup.cfg

* Mon Sep 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.20.0-20
- Add a missing word “to” in the description

* Mon Sep 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.20.0-19
- Use the autopatch macro

* Mon Sep 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.20.0-18
- Fix useless shebang in pysassc.py.

* Mon Sep 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.20.0-17
- Port to pyproject-rpm-macros

* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.20.0-13
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Fri Jul 14 2023 Mamoru TASAKA <mtasaka@fedoraproject.org> - 0.20.0-12
- Patch for sphinx 6.0 some deprecated items removal
- Backport upstream patch for testsuite to support sasl 3.6.5

* Fri Jun 16 2023 Python Maint <python-maint@redhat.com> - 0.20.0-11
- Rebuilt for Python 3.12

* Fri Jan 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.20.0-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Fri Jul 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.20.0-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Wed Jun 22 2022 Charalampos Stratakis <cstratak@redhat.com> - 0.20.0-8
- Fix FTBFS with setuptools >= 62.1
Resolves: rhbz#2097098

* Tue Jun 14 2022 Python Maint <python-maint@redhat.com> - 0.20.0-7
- Rebuilt for Python 3.11

* Fri Jan 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.20.0-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Fri Jul 23 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.20.0-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Fri Jun 04 2021 Python Maint <python-maint@redhat.com> - 0.20.0-4
- Rebuilt for Python 3.10

* Wed Jan 27 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.20.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild

* Wed Jul 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.20.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

* Fri Jul 17 2020 Marcel Plch <marcel.plch@protonmail.com> - 0.20.0-1
- Update to v0.20.0

* Tue May 26 2020 Miro Hrončok <mhroncok@redhat.com> - 0.19.4-3
- Rebuilt for Python 3.9

* Thu Jan 30 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.19.4-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

* Tue Jan 14 2020 Marcel Plch <mplch@redhat.com> - 0.19.4-1
- Update to 0.19.4

* Thu Oct 03 2019 Miro Hrončok <mhroncok@redhat.com> - 0.18.0-4
- Rebuilt for Python 3.8.0rc1 (#1748018)

* Mon Aug 19 2019 Miro Hrončok <mhroncok@redhat.com> - 0.18.0-3
- Rebuilt for Python 3.8

* Fri Jul 26 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.18.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

* Tue Jun 18 2019 Marcel Plch <mplch@redhat.com> - 0.18.0-1
- Update to 0.18.0

* Sat Feb 02 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.14.5-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Mon Jul 16 2018 Marcel Plch <mplch@redhat.com> - 0.14.5-3
- Add a needed BuildRequire

* Sat Jul 14 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.14.5-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

* Mon Jul 09 2018 Marcel Plch <mplch@redhat.com> - 0.14.5-1
- Initial version of the package