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

# Per the Web Assets guidelines, we should try to recompile at least .qss files
# (which are CSS) as part of the build. Historically, this was absolutely
# required (“It is not acceptable to include pre-compiled CSS in Fedora
# packages.”), but even though the requirement has been relaxed
# (https://pagure.io/fesco/issue/3269), recompiling is still best practice
# where it is feasible.
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Web_Assets/#_css
%bcond recompile_assets 1

Name:           python-qdarkstyle
Version:        3.2.3
Release:        %autorelease
Summary:        The most complete dark/light style sheet for C++/Python and Qt applications

# From README.rst:
#   This project is licensed under the MIT license. Images contained in this
#   project is licensed under CC-BY license.
# Therefore, the entire source is (SPDX) MIT except for those files with .png
# or .svg extensions, which are CC-BY-4.0.
License:        MIT AND CC-BY-4.0
URL:            https://github.com/ColinDuquesnoy/QDarkStyleSheet
# The PyPI sdist does not have all of the files (such as SVG files) needed to
# rebuild the generated assets.
Source0:        %{url}/archive/v.%{version}/QDarkStyleSheet-v.%{version}.tar.gz
# Man pages hand-written for Fedora in groff_man(7) format based on --help.
Source10:       qdarkstyle.1
Source11:       qdarkstyle.example.1
Source12:       qdarkstyle.utils.1

# Drop PySide2 dependency from the example in Python 3.12+
# https://github.com/ColinDuquesnoy/QDarkStyleSheet/pull/355
Patch:          %{url}/pull/355.patch
# Improvements to example description
# https://github.com/ColinDuquesnoy/QDarkStyleSheet/pull/356
Patch:          %{url}/pull/356.patch

BuildArch:      noarch
 
BuildRequires:  python3-devel

BuildRequires:  hardlink

# This is required for the error-reporting option in the CLI. We have it as a
# weak dependency, so we make it a BR to ensure we don’t end up with an
# uninstallable package.
BuildRequires:  %{py3_dist helpdev}

# Selected dependencies from req-test.txt (which is mostly unwanted linters,
# coverage tools, etc.)
BuildRequires:  %{py3_dist pytest}

%global common_description %{expand:
The most complete dark/light style sheet for Qt applications (Qt4, Qt5, PySide,
PySide2, PyQt4, PyQt5, QtPy, PyQtGraph, Qt.Py) for Python and C++.}

%description %{common_description}


%package -n python3-qdarkstyle
Summary:        %{summary}
 
Recommends:     python3-qdarkstyle+develop = %{version}-%{release}
Recommends:     %{py3_dist helpdev}

%description -n python3-qdarkstyle %{common_description}


%pyproject_extras_subpkg -n python3-qdarkstyle example
%{_bindir}/qdarkstyle.example
%{_mandir}/man1/qdarkstyle.example.1*


%pyproject_extras_subpkg -n python3-qdarkstyle develop
%{_bindir}/qdarkstyle.utils
%{_mandir}/man1/qdarkstyle.utils.1*


%prep
%autosetup -n QDarkStyleSheet-v.%{version} -p1

%if %{with recompile_assets}
rm -vf qdarkstyle/*/*style.{qrc,qss} qdarkstyle/*/_variables.scss
%endif

# We helped upstream clean up shebangs in
# https://github.com/ColinDuquesnoy/QDarkStyleSheet/pull/333, but upstream
# seems to prefer to have some executables (with shebang lines) inside the
# qdarkstyle package directory. Since executable permissions will be removed
# when installing into site-packages, we should remove the shebangs too; they
# won’t make sense anymore.
#
# The find-then-modify pattern preserves mtimes on sources that did not need to
# be modified.
find 'qdarkstyle' -type f -name '*.py' \
    -exec gawk '/^#!/ { print FILENAME }; { nextfile }' '{}' '+' |
  xargs -r -t sed -r -i '1{/^#!/d}'


%generate_buildrequires
%pyproject_buildrequires -x develop,example


%build
%if %{with recompile_assets}
# QT_QPA_PLATFORM=offscreen keeps us from needing something like xvfb-run,
# xwfb-run, or wlheadless-run.
# The upstream default for this script is to compile with pyside6, but since
# 3.2.2, upstream has recompiled with pyqt5 instead in practice.
QT_QPA_PLATFORM=offscreen PYTHONPATH="${PWD}" %{python3} -m qdarkstyle.utils \
    --create 'pyqt5'
%endif
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files -l qdarkstyle

install -t '%{buildroot}%{_mandir}/man1' -D -p -m 0644 \
    '%{SOURCE10}' '%{SOURCE11}' '%{SOURCE12}'

# Some files, particularly icons, are duplicated across themes and can be
# hardlinked to save space.
hardlink -c -v '%{buildroot}%{python3_sitelib}/qdarkstyle/'


%check
# Let’s do this in addition to running the tests, just to be sure.
%pyproject_check_import

%pytest


%files -n python3-qdarkstyle -f %{pyproject_files}
%doc CHANGES.rst
%doc README.rst
%{_bindir}/qdarkstyle
%{_mandir}/man1/qdarkstyle.1*


%changelog
## START: Generated by rpmautospec
* Fri Oct 11 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.3-16
- Correct the SPDX License expression

* Mon Sep 23 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.3-14
- Set QT_QPA_PLATFORM=offscreen to recompile assets without xvfb-run

* Fri Jul 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 3.2.3-13
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Wed Jun 19 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.3-12
- Replace the generated man pages with simple hand-written ones

* Wed Jun 19 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.3-11
- Improve the example’s description text

* Wed Jun 19 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.3-9
- Upstream the PySide2 patch
- Use of pyside2 is now conditionalized in the patch rather than via a
  build conditional

* Fri Jun 07 2024 Python Maint <python-maint@redhat.com> - 3.2.3-8
- Rebuilt for Python 3.13

* Tue Apr 02 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.3-7
- Hardlink duplicate files to save a little space

* Tue Apr 02 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.3-5
- Remove duplicate AUTHORS.rst file (already packaged in .dist-info as a
  license file)

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

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

* Mon Dec 18 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.3-2
- Assert that %%pyproject_files contains a license file

* Tue Nov 28 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.3-1
- Update to 3.2.3

* Tue Nov 28 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.2-1
- Update to 3.2.2 (close RHBZ#2251817)
- Compile assets with PyQt5 instead of PyQt6 to match upstream

* Sat Nov 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.2.1-1
- Update to 3.2.1 (close RHBZ#2246224)

* Thu Oct 12 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.1-2
- Enable the tests

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

* Wed Sep 27 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.3-5
- Keep timestamps when converting text file line endings

* Sun Sep 17 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.3-4
- Add help2man-generated man pages

* Sun Sep 17 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.3-3
- Don’t install files with pointless or broken shebangs

* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.3-2
- Recompile web assets as part of the package build

* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.3-1
- Update to 3.0.3

* Fri Sep 15 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.2-20
- Add support for recompiling assets

* Thu Sep 14 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.2-19
- Package README.rst, but not CONTRIBUTING.rst

* Thu Sep 14 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.2-17
- Port to pyproject-rpm-macros
- Add metapackages for the “develop” and “example” extras

* Thu Sep 14 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.2-13
- Update summary and description from upstream

* Thu Sep 14 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.0.2-10
- F39+: Drop PySide2 support (fix RHBZ#2220472)
- PySide2 is broken on Python 3.12

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

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

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

* Fri Jul 01 2022 Python Maint <python-maint@redhat.com> - 3.0.2-5
- Rebuilt for Python 3.11

* Thu May 12 2022 Miro Hrončok <mhroncok@redhat.com> - 3.0.2-4
- Drop build time requires from runtime
- Fixes: rhbz#2064905

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

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

* Sat Jun 05 2021 Mukundan Ragavan <nonamedotc@fedoraproject.org> - 3.0.2-1
- Update to 3.0.2

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

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

* Sat Nov 28 2020 Mukundan Ragavan <nonamedotc@fedoraproject.org> - 2.8.1-1
- Update to 2.8.1

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

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

* Mon Mar 16 2020 Mukundan Ragavan <nonamedotc@fedoraproject.org> - 2.8-1
- Update to 2.8
- uses pyside2

* Sat Dec 21 2019 Mukundan Ragavan <nonamedotc@gmail.com> - 2.7-1
- Initial package.

## END: Generated by rpmautospec