Blob Blame History Raw
%if 0%{?fedora} || 0%{?rhel} >= 8
%global with_python3 1
%endif

%global srcname pybtex

Name:           python-%{srcname}
Version:        0.21
Release:        2%{?dist}
Summary:        BibTeX-compatible bibliography processor written in Python

License:        MIT
URL:            http://pybtex.org/
Source0:        https://files.pythonhosted.org/packages/source/p/%{srcname}/%{srcname}-%{version}.tar.gz
# Fix syntax that became invalid with python 3.6
Patch0:         %{name}-python36.patch
BuildArch:      noarch

BuildRequires:  python2-devel
BuildRequires:  python2-latexcodec
BuildRequires:  python2-nose
BuildRequires:  python-pyglet
BuildRequires:  python2-setuptools
BuildRequires:  python2-sphinx
BuildRequires:  python2-yaml

%if 0%{?with_python3}
BuildRequires:  python3-devel
BuildRequires:  python3-latexcodec
BuildRequires:  python3-nose
BuildRequires:  python3-pyglet
BuildRequires:  python3-setuptools
BuildRequires:  python3-sphinx
BuildRequires:  python3-yaml
%endif

%global common_desc \
Pybtex is a BibTeX-compatible bibliography processor written in Python.\
Pybtex aims to be 100% compatible with BibTeX.  It accepts the same\
command line options, fully supports BibTeX’s .bst styles and produces\
byte-identical output.\
\
Additionally:\
- Pybtex is Unicode-aware.\
- Pybtex supports bibliography formats other than BibTeX.\
- It is possible to write formatting styles in Python.\
- As a bonus, Pythonic styles can produce HTML, Markdown and other\
  markup besides the usual LaTeX.\
Pybtex also includes a Python API for managing bibliographies from Python.

%description
%common_desc

%package -n python2-%{srcname}
Summary:        BibTeX-compatible bibliography processor written in Python
Requires:       python2-latexcodec
Requires:       python-pyglet
Requires:       python2-yaml

Provides:       bundled(jquery)
Provides:       bundled(js-underscore)
%{?python_provide:%python_provide python2-%{srcname}}

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

%if 0%{?with_python3}
%package -n python3-%{srcname}
Summary:        BibTeX-compatible bibliography processor written in Python
Requires:       python3-latexcodec
Requires:       python3-pyglet
Requires:       python3-yaml

Provides:       bundled(jquery)
Provides:       bundled(js-underscore)
%{?python_provide:%python_provide python3-%{srcname}}

%description -n python3-%{srcname}
%common_desc
%endif

%package doc
Summary:        Documentation for python-%{srcname}

%description doc
Documentation for python-%{srcname}.

%prep
%setup -q -c

# Remove useless shebang
sed -i '\@/usr/bin/env python@d' %{srcname}-%{version}/pybtex/cmdline.py

# Prepare for python3 build
cp -a %{srcname}-%{version} python3-%{srcname}-%{version}

# Fix the python2 shebangs to not use env
pushd %{srcname}-%{version}
for fil in pybtex/charwidths/make_charwidths.py \
           pybtex/database/{convert,format}/__main__.py pybtex/__main__.py; do
  sed -i 's/env python/python2/' $fil
done
popd

%if 0%{?with_python3}
# Fix the python3 shebangs to not use env
pushd python3-%{srcname}-%{version}
%patch0
for fil in pybtex/charwidths/make_charwidths.py \
           pybtex/database/{convert,format}/__main__.py pybtex/__main__.py; do
  sed -i 's/env python/python3/' $fil
done
popd
%endif

%build
# Python 2 build
pushd %{srcname}-%{version}
%py2_build
popd

%if 0%{?with_python3}
# Python 3 build
pushd python3-%{srcname}-%{version}
%py3_build
popd
%endif

# Build documentation
%if 0%{?with_python3}
pushd python3-%{srcname}-%{version}
PYTHONPATH=$PWD:$PWD/build/lib make -C docs html \
  SPHINXBUILD=%{_bindir}/sphinx-build-%{python3_version}
%else
pushd %{srcname}-%{version}
PYTHONPATH=$PWD:$PWD/build/lib make -C docs html \
  SPHINXBUILD=%{_bindir}/sphinx-build-%{python2_version}
%endif
rm -f docs/build/html/.buildinfo
popd

%install
# Python 2 install
pushd %{srcname}-%{version}
%py2_install
mkdir -p %{buildroot}%{_mandir}
cp -a docs/man1 %{buildroot}%{_mandir}
popd
pushd %{buildroot}%{python2_sitelib}
rm -fr custom_fixers pybtex/tests
chmod a+x pybtex/charwidths/make_charwidths.py \
      pybtex/database/{convert,format}/__main__.py pybtex/__main__.py
popd

%if 0%{?with_python3}
# Python 3 install
pushd python3-%{srcname}-%{version}
%py3_install
popd
pushd %{buildroot}%{python3_sitelib}
rm -fr custom_fixers pybtex/tests
chmod a+x pybtex/charwidths/make_charwidths.py \
      pybtex/database/{convert,format}/__main__.py pybtex/__main__.py
popd
%endif

%check
# Test the python 2 build
pushd %{srcname}-%{version}
PYTHONPATH=$PWD:$PWD/build/lib nosetests-%{python2_version} -v
popd

%if 0%{?with_python3}
# Python 3 install
pushd python3-%{srcname}-%{version}
# Overwrite the original python 2 sources with the fixed python 3 versions
pushd build/lib; tar cBf - pybtex | (popd; tar xBf -)
popd
PYTHONPATH=$PWD:$PWD/build/lib nosetests-%{python3_version} -v
popd
%endif

%files -n python2-%{srcname}
%doc %{srcname}-%{version}/README
%license %{srcname}-%{version}/COPYING
%{python2_sitelib}/%{srcname}*

%if 0%{?with_python3}
%files -n python3-%{srcname}
%doc python3-%{srcname}-%{version}/README
%license python3-%{srcname}-%{version}/COPYING
%{python3_sitelib}/%{srcname}*
%endif

%{_bindir}/pybtex*
%{_mandir}/man1/pybtex*

%files doc
%if 0%{?with_python3}
%doc python3-%{srcname}-%{version}/{CHANGES,docs/build/html}
%else
%doc %{srcname}-%{version}/{CHANGES,docs/build/html}
%endif

%changelog
* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.21-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Sat Jan 21 2017 Jerry James <loganjerry@gmail.com> - 0.21-1
- New upstream version

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

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

* Fri Mar 18 2016 Jerry James <loganjerry@gmail.com> - 0.20.1-1
- New upstream version

* Thu Mar 10 2016 Jerry James <loganjerry@gmail.com> - 0.20-1
- New upstream version

* Wed Mar  2 2016 Jerry James <loganjerry@gmail.com> - 0.19-2
- Don't preserve timestamps of modified files
- Fix nosetests invocation
- Simplify files section

* Thu Feb 25 2016 Jerry James <loganjerry@gmail.com> - 0.19-1
- Initial RPM