# when bootstrapping, we cannot yet use sphinx and pytest # on RHEL, we don't need to build the documentation %bcond docs %{undefined rhel} %bcond tests 1 Name: python-pygments Version: 2.17.2 Release: %autorelease Summary: Syntax highlighting engine written in Python License: BSD-2-Clause URL: https://pygments.org/ Source0: %{pypi_source pygments} BuildArch: noarch BuildRequires: python%{python3_pkgversion}-devel BuildRequires: pyproject-rpm-macros %if %{with tests} BuildRequires: python%{python3_pkgversion}-pytest BuildRequires: python%{python3_pkgversion}-lxml %if %{undefined rhel} # this is only used in tests.contrast.test_contrasts # to avoid pulling this package into RHEL, the test is ignored in %%check BuildRequires: python%{python3_pkgversion}-wcag-contrast-ratio %endif %endif %if %{with docs} BuildRequires: make BuildRequires: python%{python3_pkgversion}-sphinx # the sphinx config imports tests.contrast.test_contrasts: BuildRequires: python%{python3_pkgversion}-wcag-contrast-ratio %endif %global _description %{expand: Pygments is a generic syntax highlighter suitable for use in code hosting, forums, wikis or other applications that need to prettify source code. Highlights are: * a wide range of over 500 languages and other text formats is supported * special attention is paid to details that increase highlighting quality * support for new languages and formats are added easily; most languages use a simple regex-based lexing mechanism * a number of output formats is available, among them HTML, RTF, LaTeX and ANSI sequences * it is usable as a command-line tool and as a library} %description %_description %package -n python%{python3_pkgversion}-pygments Summary: %{summary} Provides: pygmentize = %{?epoch:%{epoch}:}%{version}-%{release} Requires: alternatives >= 1.19.1-1 Requires(post): python%{python3_pkgversion} Requires(postun): python%{python3_pkgversion} %description -n python%{python3_pkgversion}-pygments %_description %prep %autosetup -p1 -n pygments-%{version} %generate_buildrequires %pyproject_buildrequires %build %pyproject_wheel %install %pyproject_install %pyproject_save_files pygments install doc/pygmentize.1 -Dt %{buildroot}%{_mandir}/man1/ chmod -x %{buildroot}%{_mandir}/man1/*.1 %if %{with docs} %make_build -C doc html rm doc/_build/html/.buildinfo rm -rf doc/_build/html/_sources %endif mv %{buildroot}%{_bindir}/pygmentize{,-%{python3_version}} mv %{buildroot}%{_mandir}/man1/pygmentize{,-%{python3_version}}.1 # All ghost files need to exist for the files check to succeed touch %{buildroot}%{_bindir}/pygmentize touch %{buildroot}%{_mandir}/man1/pygmentize.1.gz %if %{with tests} %check %pytest %{?rhel:--ignore tests/contrast/test_contrasts.py} %endif %post -n python%{python3_pkgversion}-pygments if [ -f %{_bindir}/pygmentize -a ! -h %{_bindir}/pygmentize ]; then sed -i 's/python3 /python3.9 /' %{_bindir}/pygmentize || : mv %{_bindir}/pygmentize{,-3.9} fi if [ -f %{_mandir}/man1/pygmentize.1.gz -a ! -h %{_mandir}/man1/pygmentize.1.gz ]; then mv %{_mandir}/man1/pygmentize{,-3.9}.1.gz fi for ver in 3.9 %{python3_version}; do alternatives --add-slave python3 %{_bindir}/python$ver \ %{_bindir}/pygmentize \ pygmentize \ %{_bindir}/pygmentize-$ver alternatives --add-slave python3 %{_bindir}/python$ver \ %{_mandir}/man1/pygmentize.1.gz \ pygmentize-man \ %{_mandir}/man1/pygmentize-$ver.1.gz done %postun -n python%{python3_pkgversion}-pygments # Do this only during uninstall process (not during update) if [ $1 -eq 0 ]; then for f in pygmentize{,-man}; do alternatives --keep-foreign --remove-slave \ python3 %{_bindir}/python%{python3_version} $f done fi %files -n python%{python3_pkgversion}-pygments -f %{pyproject_files} %doc AUTHORS CHANGES %{?with_docs:%doc doc/_build/html} %license LICENSE %{_bindir}/pygmentize-* %lang(en) %{_mandir}/man1/pygmentize-*.1* # Alternatives %ghost %{_bindir}/pygmentize %ghost %lang(en) %{_mandir}/man1/pygmentize.1* %changelog %autochangelog