Blob Blame History Raw
%global srcname pyrsistent

# 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 lesser substitute.
%bcond_without doc_pdf

Name:           python-%{srcname}
Summary:        Persistent/Functional/Immutable data structures
Version:        0.16.1
Release:        2%{?dist}

# The entire source is MIT, except pyrsistent/_toolz.py which is BSD.
License:        MIT and BSD
URL:            https://github.com/tobgu/pyrsistent/
Source0:        %{url}/archive/v%{version}/%{srcname}-%{version}.tar.gz

BuildRequires:  python2-devel
BuildRequires:  python%{python3_pkgversion}-devel

# Setuptools is BR’d below

BuildRequires:  gcc

# For Sphinx documentation
%if %{with doc_pdf}
BuildRequires:  make
BuildRequires:  latexmk
# No python3-sphinx-latex on EPEL7; list dependencies manually. This list may
# not be strictly minimal, but it is sufficient.
BuildRequires:  texlive-collection-fontsrecommended
BuildRequires:  texlive-collection-latex
BuildRequires:  texlive-dvipng
BuildRequires:  tex(amsmath.sty)
BuildRequires:  tex(amsthm.sty)
BuildRequires:  tex(article.cls)
BuildRequires:  tex(cmap.sty)
BuildRequires:  tex(color.sty)
BuildRequires:  tex(ecrm1000.tfm)
BuildRequires:  tex(fancybox.sty)
BuildRequires:  tex(fancyhdr.sty)
BuildRequires:  tex(fancyvrb.sty)
BuildRequires:  tex(fncychap.sty)
BuildRequires:  tex(footnote.sty)
BuildRequires:  tex(framed.sty)
BuildRequires:  tex(geometry.sty)
BuildRequires:  tex(hyperref.sty)
BuildRequires:  tex(kvoptions.sty)
BuildRequires:  tex(multirow.sty)
BuildRequires:  tex(parskip.sty)
BuildRequires:  tex(polyglossia.sty)
BuildRequires:  tex(threeparttable.sty)
BuildRequires:  tex(titlesec.sty)
BuildRequires:  tex(upquote.sty)
BuildRequires:  tex(utf8x.def)
BuildRequires:  tex(wrapfig.sty)
%endif

# ============================================================================
# From requirements.txt:

# Sphinx
BuildRequires:  python2-sphinx
BuildRequires:  python%{python3_pkgversion}-sphinx

# pytest < 5
BuildRequires:  python2-pytest < 5.0
BuildRequires:  python%{python3_pkgversion}-pytest < 5.0

# sphinx-rtd-theme==0.1.5
BuildRequires:  python2-sphinx_rtd_theme
BuildRequires:  python%{python3_pkgversion}-sphinx_rtd_theme

# ----------------------------------------------------------------------------
# We do not need these, since we are not running the memorytest* environment
# from tox.ini.
# ----------------------------------------------------------------------------
# memory-profiler==0.31
# psutil==2.1.0

# ----------------------------------------------------------------------------
# We do not need this, since we are not using tox to run the tests.
# ----------------------------------------------------------------------------
# tox

BuildRequires:  python2-six
BuildRequires:  python%{python3_pkgversion}-six

# ----------------------------------------------------------------------------
# We do not need this, since we are not running the benchmarks from
# performance_suites/.
# ----------------------------------------------------------------------------
# pyperform

# hypothesis < 5
BuildRequires:  python2-hypothesis < 5.0
BuildRequires:  python%{python3_pkgversion}-hypothesis < 5.0

# setuptools>=0.16.1
# It seems we can get away with an older setuptools on Python 2 in practice.
BuildRequires:  python2-setuptools
BuildRequires:  python%{python3_pkgversion}-setuptools >= 0.16.1

# ----------------------------------------------------------------------------
# We do not need these for the RPM build either.
# ----------------------------------------------------------------------------
# twine>=3.2
# pip>=20.2.3

# ============================================================================
# From setup_requires in setup.py, when tests are to be executed:
BuildRequires:  python2-pytest-runner
BuildRequires:  python%{python3_pkgversion}-pytest-runner

# Note that pyrsistent/_toolz.py contains a bit of code ported from toolz, but
# not enough to constitute a bundled dependency.

%global common_description %{expand:
Pyrsistent is a number of persistent collections (by some referred to as
functional data structures). Persistent in the sense that they are
immutable.

All methods on a data structure that would normally mutate it instead
return a new copy of the structure containing the requested updates. The
original structure is left untouched.}

%description %{common_description}


%package -n     python2-%{srcname}
Summary:        %{summary}
Requires:       python2-six
%{?python_provide:%python_provide python2-%{srcname}}

%description -n python2-%{srcname} %{common_description}


%package -n     python%{python3_pkgversion}-%{srcname}
Summary:        %{summary}
Requires:       python%{python3_pkgversion}-six
%{?python_provide:%python_provide python%{python3_pkgversion}-%{srcname}}

%description -n python%{python3_pkgversion}-%{srcname} %{common_description}


%package        doc
Summary:        Documentation for %{srcname}

BuildArch:      noarch

%description doc %{common_description}


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


%build
%py2_build
%py3_build

# Default SPHINXOPTS are '-W -n', but -W turns warnings into errors and there
# are some warnings. We want to build the documentation as best we can anyway.
# We do not parallelize Sphinx itself with %%_smp_mflags because, on EPEL7, it
# sometimes hangs waiting for the workers.
%if %{with doc_pdf}
PYTHONPATH="${PWD}" %make_build -C docs latex \
    SPHINXBUILD='sphinx-build-%{python3_version}' SPHINXOPTS='-n'
%make_build -C docs/build/latex
rm -f docs/build/html/.buildinfo
%endif


%install
%py2_install
%py3_install


%check
# tests/field_test.py fails to collect due to some apparent Python version
# incompatibility in the pytest(-runner)? machinery—it does not look like a
# problem with the actual package
env PYTHONPATH=%{python2_sitearch} \
    PYTHONDONTWRITEBYTECODE=1 \
    %{__python2} -m pytest --ignore=tests/field_test.py
# These expect {} style set representation instead of set([]) style
k='not pyrsistent._helpers.thaw'
# From tox.ini:
#   Need to disable the random hashing or all docs printing a map with more
#   than one item in it will be flaky.
# This is the justification for PYTHONHASHSEED=0; but setting it does not help
# on Python 2, so we must skip the affected tests.
k="${k} and not pyrsistent._pmap.PMap"
k="${k} and not pyrsistent._pmap.PMap.evolver"
k="${k} and not pyrsistent._pmap.PMap.set"
k="${k} and not pyrsistent._pmap.PMap.update"
k="${k} and not pyrsistent._pmap.PMap.update_with"
k="${k} and not pyrsistent._pmap.m"
k="${k} and not pyrsistent._pmap.pmap"
# After skipping the tests that would fail, we get:
#   INTERNALERROR> Traceback (most recent call last):
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/main.py", line 84, in wrap_session
#   INTERNALERROR>     doit(config, session)
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/main.py", line 121, in _main
#   INTERNALERROR>     config.hook.pytest_collection(session=session)
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
#   INTERNALERROR>     return self._docall(self.methods, kwargs)
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
#   INTERNALERROR>     firstresult=self.firstresult).execute()
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
#   INTERNALERROR>     res = method(*args)
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/main.py", line 125, in pytest_collection
#   INTERNALERROR>     return session.perform_collect()
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/main.py", line 552, in perform_collect
#   INTERNALERROR>     config=self.config, items=items)
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
#   INTERNALERROR>     return self._docall(self.methods, kwargs)
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
#   INTERNALERROR>     firstresult=self.firstresult).execute()
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
#   INTERNALERROR>     res = method(*args)
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/mark.py", line 77, in pytest_collection_modifyitems
#   INTERNALERROR>     if keywordexpr and not matchkeyword(colitem, keywordexpr):
#   INTERNALERROR>   File "/usr/lib/python2.7/site-packages/_pytest/mark.py", line 158, in matchkeyword
#   INTERNALERROR>     return eval(keywordexpr, {}, mapping)
#   INTERNALERROR>   File "<string>", line 1, in <module>
#   INTERNALERROR> AttributeError: 'bool' object has no attribute '_helpers'
# It’s not clear that there is any workaround for this, so we end up not
# running the doctests on Python 2.
#   env PYTHONPATH=%%{python2_sitearch} \
#       PYTHONDONTWRITEBYTECODE=1 \
#       PYTHONHASHSEED=0 \
#       %%{__python2} -m pytest --doctest-modules %{srcname}

# tests/field_test.py fails to collect due to some apparent Python version
# incompatibility in the pytest(-runner)? machinery—it does not look like a
# problem with the actual package
env PYTHONPATH=%{python3_sitearch} \
    PYTHONDONTWRITEBYTECODE=1 \
    %{__python3} -m pytest --ignore=tests/field_test.py
env PYTHONPATH=%{python3_sitearch} \
    PYTHONDONTWRITEBYTECODE=1 \
    PYTHONHASHSEED=0 \
    %{__python3} -m pytest --doctest-modules %{srcname}


%files -n python2-%{srcname}
%license LICENCE.mit
%{python2_sitearch}/%{srcname}
%{python2_sitearch}/_%{srcname}_version.py
%{python2_sitearch}/_%{srcname}_version.py?
%{python2_sitearch}/pvectorc*.so
%{python2_sitearch}/%{srcname}-%{version}-py%{python2_version}.egg-info


%files -n python%{python3_pkgversion}-%{srcname}
%license LICENCE.mit
%{python3_sitearch}/%{srcname}
%{python3_sitearch}/_%{srcname}_version.py
%{python3_sitearch}/__pycache__/_%{srcname}_version.*.pyc
%{python3_sitearch}/pvectorc*.so
%{python3_sitearch}/%{srcname}-%{version}-py%{python3_version}.egg-info


%files doc
%license LICENCE.mit
%doc CHANGES.txt
%doc README.rst
%if %{with doc_pdf}
%doc docs/build/latex/Pyrsistent.pdf
%endif


%changelog
* Thu Sep 30 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.16.1-2
- Build PDF documentation instead of HTML

* Mon Jun 21 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.16.1-1
- Initial package for EPEL7
- Spec file substantially rewritten from the Fedora package, and reverted to an
  older version for Python 2 support, so the EPEL7 branch gets a fresh
  changelog.