## START: Set by rpmautospec
## (rpmautospec version 0.6.0)
## 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-docx
Version:        1.1.2
Release:        %autorelease
Summary:        Create and modify Word documents with Python

# SPDX
License:        MIT
URL:            https://python-docx.readthedocs.io/en/latest/
# We MUST use the PyPI tarball; the GitHub tarball includes material under ref/
# (PDFs of ISO/IEC standards) for which redistribution may be prohibited.
Source:         %{pypi_source python_docx}

BuildArch:      noarch

BuildRequires:  python3-devel

BuildRequires:  dos2unix

# Extra dependencies for documentation
%if %{with doc}
BuildRequires:  make
BuildRequires:  python3dist(sphinx)
BuildRequires:  python3-sphinx-latex
BuildRequires:  latexmk
%endif
 
%global common_description %{expand:
A Python library for creating and updating Microsoft Word (.docx) files.}

%description %{common_description}


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

%description -n python3-docx %{common_description}


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

%description    doc %{common_description}
%endif


%prep
%autosetup -n python_docx-%{version}

# https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_linters
sed -r -i 's/^(pytest-coverage|ruff)\b/# &/' requirements-test.txt

# We don’t want to package https://github.com/armstrong/armstrong_sphinx (and
# shouldn’t use the bundled copy), so we just switch the documentation theme
# from “armstrong” to the built-in “alabaster”. The result seems similarly
# useful, without the bundling.
rm -rvf docs/_themes
sed -r -i 's/armstrong/alabaster/' docs/conf.py

# Drop intersphinx mappings, since we can’t download remote inventories and
# can’t easily produce working hyperlinks from inventories in local
# documentation packages.
echo 'intersphinx_mapping.clear()' >> docs/conf.py

# Fix a stray CRLF-terminated reStructuredText file:
dos2unix --keepdate docs/dev/analysis/features/table/cell-merge.rst

# While filterwarnings = ["error"] makes sense for upstream development and CI,
# it is too strict for distribution packaging.
sed -r -i 's/^([[:blank:]]*)("error",)$/\1# \2/' pyproject.toml


%generate_buildrequires
# Since we don’t use %%tox (see notes in %%check), we generate test
# dependencies directly from the requirements file rather than using -t.
%pyproject_buildrequires requirements-test.txt


%build
%pyproject_wheel

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


%install
%pyproject_install
%pyproject_save_files -l docx


%check
# Rather than using the %%tox macro, we run test commands from tox.ini manually
# so that we can pass extra arguments. We can’t reasonably ask upstream to add
# {posargs} to tox.ini because there are two different test executors (pytest
# and behave) that accept positional arguments.
#
# As long as we have control of the arguments, we choose more verbose output
# than outstream, and we choose not to halt on the first failing test.
%{pytest} -k "${k-}" -v
%{py3_test_envvars} %{python3} -m behave --format plain --tags=-wip

# Fail the build if the tarball accidentally included ISO/IEC standards
# documents that should not have been redistributed. Note that removing these
# in %%prep would not have been good enough.
banned="$(find . -type f -name 'ISO*.pdf')"
if [ -n "${banned}" ]
then
  cat <<EOF
Source included ISO/IEC standards documents, which should not have been
redistributed:

${banned}
EOF
  exit 1
fi
if [ -e 'ref' ]
then
  cat <<EOF
Source had ref/ subdirectory, which has historically included content that
should not be redistributed.
EOF
  exit 1
fi


%files -n python3-docx -f %{pyproject_files}
%if %{without doc}
%doc HISTORY.rst README.md
%endif


%if %{with doc}
%files doc
%license LICENSE
%doc HISTORY.rst README.md
%doc docs/.build/latex/python-docx.pdf
%endif


%changelog
## START: Generated by rpmautospec
* Sat Jun 08 2024 Python Maint <python-maint@redhat.com> - 1.1.2-2
- Rebuilt for Python 3.13

* Thu May 02 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.2-1
- Update to 1.1.2

* Tue Apr 30 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.1-1
- Update to 1.1.1 (close RHBZ#2277963)

* Fri Jan 26 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-7
- Revert "Report and skip a failing test in F40/Rawhide only"

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

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

* Sun Dec 17 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-4
- Assert that %%pyproject_files contains a license file

* Tue Nov 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-3
- Report and skip a failing test in F40/Rawhide only

* Tue Nov 21 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-2
- Don’t use tox; manually control pytest/behave options

* Sun Nov 05 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.1.0-1
- Update to 1.1.0 (close RHBZ#2248008)

* Fri Oct 13 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 1.0.1-1
- Update to 1.0.1 (close RHBZ#2243572)

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

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

* Tue Jul 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-20
- When PDF docs are disabled, omit the -doc subpackage

* Fri Jul 07 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-19
- Use new (rpm 4.17.1+) bcond style

* Thu Jun 15 2023 Python Maint <python-maint@redhat.com> - 0.8.11-18
- Rebuilt for Python 3.12

* Fri Mar 17 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-16
- Don’t assume %%_smp_mflags is -j%%_smp_build_ncpus

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

* Sat Oct 22 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-14
- Confirm License is SPDX MIT

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

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

* Fri Jan 07 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-11
- Drop stray %%%%py_provides

* Fri Jan 07 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-10
- Drop intersphinx mappings

* Sat Nov 27 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-9
- Tweak a spec file comment

* Fri Nov 26 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-8
- Reduce LaTeX PDF build verbosity

* Fri Oct 01 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-7
- Generate PDF instead of HTML Sphinx documentation.

* Mon Sep 13 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-6
- Let pyproject-rpm-macros handle the license file

* Sun Sep 12 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-5
- Reduce spec file macro indirection

* Sun Sep 12 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-4
- Drop BR on pyproject-rpm-macros, now implied by python3-devel

* Tue Aug 10 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-3
- Use the PyPI tarball to avoid redistributing ISO standard PDFs

* Fri Aug 06 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-2
- Clean up some leftover historical debris in the spec file

* Fri Aug 06 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.8.11-1
- Update to 0.8.11. (Fix CVE-2016-5851, fix RHBZ#1351082, fix RHBZ#1351083,
  fix RHBZ#1349211, fix RHBZ#1926209.)

* Tue Jul 27 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.8.5-26
- Second attempt - Rebuilt for
  https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

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

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

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

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

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

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

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

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

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

* Tue Aug 21 2018 Miro Hrončok <mhroncok@redhat.com> - 0.8.5-16
- Drop python2 subpackage

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

* Tue Jun 19 2018 Miro Hrončok <mhroncok@redhat.com> - 0.8.5-14
- Rebuilt for Python 3.7

* Tue Jun 19 2018 Miro Hrončok <mhroncok@redhat.com> - 0.8.5-13
- Rebuilt for Python 3.7

* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.8.5-12
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

* Tue Jan 30 2018 Iryna Shcherbina <ishcherb@redhat.com> - 0.8.5-11
- Update Python 2 dependency declarations to new packaging standards
  (See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3)
- Move python3-lxml form py2 to py3 subpkg
- Add python_provide to py3 subpackage

* Sat Aug 19 2017 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.8.5-10
- Python 2 binary package renamed to python2-docx
  See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3

* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.8.5-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild

* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.8.5-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Mon Dec 19 2016 Miro Hrončok <mhroncok@redhat.com> - 0.8.5-7
- Rebuild for Python 3.6

* Tue Jul 19 2016 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.8.5-6
- https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages

* Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 0.8.5-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Tue Nov 10 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.8.5-4
- Rebuilt for https://fedoraproject.org/wiki/Changes/python3.5

* Thu Jun 18 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.8.5-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild

* Fri Mar 13 2015 Kushal Khandelwal <kushal124@gmail.com> - 0.8.5-2
- Fix dependency requirement.

* Mon Mar 9 2015 Kushal Khandelwal <kushal124@gmail.com> - 0.8.5-1
- update to 0.8.5

* Fri Feb 20 2015 Kushal Khandelwal <kushal124@gmail.com> - 0.8.2-1
- Initial package.

## END: Generated by rpmautospec