%global pypi_name ruamel.yaml.clib
%global pname ruamel-yaml-clib

# This means version 0.2.2:
%global hash 82370c4dc5f436020567c5f1ef063d8c2ef8c7ae

Name:           python-%{pname}
Version:        0.2.2
Release:        1%{?dist}
Summary:        C version of reader, parser and emitter for ruamel.yaml derived from libyaml

License:        MIT
URL:            https://bitbucket.org/ruamel/yaml.clib
Source0:        https://sourceforge.net/code-snapshots/hg/r/ru/ruamel-yaml-clib/code/ruamel-yaml-clib-code-%{hash}.zip

BuildRequires:  gcc
BuildRequires:  libyaml-devel

%description
It is the C based reader/scanner and emitter for ruamel.yaml.

%package -n     python%{python3_pkgversion}-%{pname}
Summary:        %{summary}
BuildRequires:  python%{python3_pkgversion}-devel
BuildRequires:  python%{python3_pkgversion}-setuptools
BuildRequires:  python%{python3_pkgversion}-Cython

Requires:       python%{python3_pkgversion}-setuptools
Requires:       python%{python3_pkgversion}-ruamel-yaml

%description -n python%{python3_pkgversion}-%{pname}
It is the C based reader/scanner and emitter for ruamel.yaml.

%prep
%autosetup -n %{pname}-code-%{hash}
# Force regenerating C files from Cython sources
rm -v $(grep -rl '/\* Generated by Cython')

%build
# cython refuses to cythonize a file in a directory that cannot be a Python module ¯\_(ツ)_/¯
mkdir ruamel.yaml.clib
mv *.pyx ruamel.yaml.clib
export cython="$(which cythonize-%{python3_version} cythonize%{python3_version} cythonize)"
$cython ruamel.yaml.clib/*.pyx
mv ruamel.yaml.clib/* .
rmdir ruamel.yaml.clib

%py3_build

%install
%{__python3} setup.py install --single-version-externally-managed --skip-build --root $RPM_BUILD_ROOT

%files -n python%{python3_pkgversion}-%{pname}
%license LICENSE
%doc README.rst
%{python3_sitearch}/_ruamel_yaml.cpython-*
%{python3_sitearch}/%{pypi_name}-%{version}-py%{python3_version}.egg-info

%changelog
* Sun Apr 11 2021 Felix Kaechele <felix@kaechele.ca> - 0.2.2-1
- update to 0.2.2

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

* Thu Nov 12 2020 Miro Hrončok <mhroncok@redhat.com> - 0.1.2-5
- Force regenerating C files from Cython sources
- Require python3-ruamel-yaml

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

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

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

* Fri Aug 30 2019 Chandan Kumar <raukadah@gmail.com> - 0.1.2-1
- Initial package