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

# PySide2 is broken with Python 3.12; do not support it on Fedora 39 and later.
#
# python-pyside2 fails to build with Python 3.12: error: use of undeclared
#     identifier 'PyUnicode_AS_UNICODE'
# https://bugzilla.redhat.com/show_bug.cgi?id=2155447
#
# python3-shiboken2-devel wants python < 3.11
# https://bugzilla.redhat.com/show_bug.cgi?id=2149820
#
# F39FailsToInstall: python3-pyside2, python3-shiboken2,
#     python3-shiboken2-devel
# https://bugzilla.redhat.com/show_bug.cgi?id=2220452
#
# Bug python-pyside2: FTBFS in Fedora rawhide/f39
# https://bugzilla.redhat.com/show_bug.cgi?id=2226300
%bcond pyside2 %{expr:0%{?fedora} < 39}

# Per the Web Assets guidelines, we really need to recompile at least .qss
# files (which are CSS) as part of the build (“It is not acceptable to include
# pre-compiled CSS in Fedora packages.”).
# 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

License:        MIT
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.
Source:         %{url}/archive/v.%{version}/QDarkStyleSheet-v.%{version}.tar.gz

# Downstream-only for now, in hopes that PySide2 being broken on Python 3.12
# can be fixed:
#
# Patch out the PySide2 dependency from the example
Patch100:       0001-Patch-out-the-PySide2-dependency-from-the-example.patch

BuildArch:      noarch
 
BuildRequires:  python3-devel

BuildRequires:  hardlink
# Convert setup.py from CRNL so we can patch it.
BuildRequires:  dos2unix

%if %{with recompile_assets}
BuildRequires:  xorg-x11-server-Xvfb
%endif

# TODO: The generated man pages are a bit messy, with less than ideal
# formatting and some text markup leaking through. Since the CLI doesn’t change
# much, it might be worth writing a set by hand.
BuildRequires:  help2man

# 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} -N
%autopatch -M 99 -p1
%if %{without pyside2}
dos2unix --keepdate setup.py
%autopatch -m 100 -p1
%endif

%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}
# The upstream default is to compile with pyside6, but it is not packaged. We
# can use pyqt6 instead; the result seems to work well enough on at least
# pyqt5. For 3.2.2, we follow upstream in compiling with pyqt5 instead.
xvfb-run -a env PYTHONPATH="${PWD}" %{python3} -m qdarkstyle.utils \
    --create 'pyqt5'
%endif
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files -l qdarkstyle

# Generating man pages in %%install rather than %%build is not ideal, but it
# allows us to use the installed entry points.
install -d '%{buildroot}%{_mandir}/man1'
(
  export PYTHONPATH='%{buildroot}%{python3_sitelib}'
  help2man --no-info --output='%{buildroot}%{_mandir}/man1/qdarkstyle.1' \
      '%{buildroot}%{_bindir}/qdarkstyle'
  for cmd in 'qdarkstyle.utils' 'qdarkstyle.example'
  do
    help2man --no-info --output="%{buildroot}%{_mandir}/man1/${cmd}.1" \
        --no-discard-stderr --version-string='%{version}' \
        "%{buildroot}%{_bindir}/${cmd}"

  done
)

# 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
* 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