Blob Blame History Raw
# Sphinx-generated HTML documentation is not suitable for packaging; see
# for discussion.
# We can generate PDF documentation as a lesser substitute.
%bcond_without doc_pdf

Name:           python-docx
Version:        0.8.11
Release:        %autorelease
Summary:        Create and modify Word documents with Python

License:        MIT
# We MUST use the PyPI tarball; the GitHub tarball includes material under ref/
# (PDFs of ISO/IEC standards) for which redistribution may be prohibited.
Source0:        %{pypi_source python-docx}

BuildArch:      noarch

BuildRequires:  python3-devel

BuildRequires:  dos2unix

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

%description %{common_description}

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

%description -n python3-docx %{common_description}

%package        doc
Summary:        Documentation for python-docx

Requires:       python3-docs

%description    doc %{common_description}


# We don’t want to package (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 -rf docs/_themes
sed -r -i 's@armstrong@alabaster@' docs/

# Use local inventories in intersphinx mappings.
sed -r -i 's@https?://{_docdir}/python3-docs/html@' \

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

%pyproject_buildrequires -t


%if %{with doc_pdf}
%make_build -C docs latex SPHINXOPTS='%{?_smp_mflags}'
%make_build -C docs/.build/latex

%pyproject_save_files docx


# 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}" ]
  cat <<EOF
Source included ISO/IEC standards documents, which should not have been

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

%files -n python3-docx -f %{pyproject_files}

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