File python3-recommonmark.spec of Package python3-recommonmark

#
# spec file for package python3-CommonMark
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           python3-recommonmark
Version:        0.4.0
Release:        0
Summary:        Python docutils-compatibility bridge to CommonMark
License:        MIT
Group:          Development/Languages/Python
Url:            https://github.com/rtfd/recommonmark
Source0:        https://files.pythonhosted.org/packages/source/r/recommonmark/recommonmark-%{version}.tar.gz
Source1:        https://raw.githubusercontent.com/rtfd/recommonmark/master/license.md
Source2:        https://raw.githubusercontent.com/rtfd/recommonmark/master/README.md
BuildRequires:  fdupes
BuildRequires:  python3
BuildRequires:  python3-devel
BuildRequires:  python3-setuptools
BuildRequires:  python3-docutils
BuildRequires:  python3-CommonMark
Requires:       python3-docutils
Requires:       python3-CommonMark
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch
Provides:       python3-reCommonMark = %{version}
Obsoletes:      python3-reCommonMark < %{version}

%description
A python docutils-compatibility bridge to CommonMark.

This allows you to write CommonMark inside of Docutils & Sphinx projects.

Documentation is available on Read the Docs:
http://recommonmark.readthedocs.org

%prep
%setup -q -n recommonmark-%{version}
# Remove upstream's egg-info
rm -rf %{pypi_name}.egg-info
#Add missing license and readme
cp -a %{SOURCE1} .
cp -a %{SOURCE2} .
# find and remove unneeded shebangs
find recommonmark -name "*.py" | xargs sed -i '1 {/^#!/ d}'
# correct shebang
sed -i 's@^#!/usr/bin/python2@#!/usr/bin/python3@' recommonmark/scripts.py

%build
python3 setup.py build

%install
python3 setup.py install --prefix=%{_prefix} --root=%{buildroot}
%fdupes %{buildroot}%{_prefix}

# Prepare for update-alternatives usage
mkdir -p %{buildroot}%{_sysconfdir}/alternatives
for B in cm2html cm2latex cm2man cm2pseudoxml cm2xetex cm2xml; do
    mv %{buildroot}%{_bindir}/${B} %{buildroot}%{_bindir}/${B}-%{py3_ver}
    ln -s -f %{_sysconfdir}/alternatives/${B} %{buildroot}%{_bindir}/${B}
    # create a dummy target for /etc/alternatives/${B}
    touch %{buildroot}%{_sysconfdir}/alternatives/${B}
done

%post
%_sbindir/update-alternatives \
   --install %{_bindir}/cm2man cm2man %{_bindir}/cm2man-%{py3_ver} 30 \
   --slave %{_bindir}/cm2latex cm2latex %{_bindir}/cm2latex-%{py3_ver}  \
   --slave %{_bindir}/cm2xetex cm2xetex %{_bindir}/cm2xetex-%{py3_ver}  \
   --slave %{_bindir}/cm2pseudoxml cm2pseudoxml %{_bindir}/cm2pseudoxml-%{py3_ver}  \
   --slave %{_bindir}/cm2html cm2html %{_bindir}/cm2html-%{py3_ver}  \
   --slave %{_bindir}/cm2xml cm2xml %{_bindir}/cm2xml-%{py3_ver}

%postun
if [ $1 -eq 0 ] ; then
    "%_sbindir/update-alternatives" --remove cm2man %{_bindir}/cm2man-%{py3_ver}
fi

%files
%defattr(-,root,root,-)
%doc README.md license.md
%{_bindir}/cm2html
%{_bindir}/cm2latex
%{_bindir}/cm2man
%{_bindir}/cm2pseudoxml
%{_bindir}/cm2xetex
%{_bindir}/cm2xml
%{_bindir}/cm2html-%{py3_ver}
%{_bindir}/cm2latex-%{py3_ver}
%{_bindir}/cm2man-%{py3_ver}
%{_bindir}/cm2pseudoxml-%{py3_ver}
%{_bindir}/cm2xetex-%{py3_ver}
%{_bindir}/cm2xml-%{py3_ver}
%ghost %{_sysconfdir}/alternatives/cm2html
%ghost %{_sysconfdir}/alternatives/cm2latex
%ghost %{_sysconfdir}/alternatives/cm2man
%ghost %{_sysconfdir}/alternatives/cm2pseudoxml
%ghost %{_sysconfdir}/alternatives/cm2xetex
%ghost %{_sysconfdir}/alternatives/cm2xml
%{python3_sitelib}/recommonmark/
%{python3_sitelib}/recommonmark-%{version}-py*.egg-info

%changelog
openSUSE Build Service is sponsored by