Blame python-cmake-build-extension.spec

033ec30
%bcond test_example 1
b3d410f
b3d410f
Name:           python-cmake-build-extension
d825b77
Version:        0.5.1
b3d410f
Release:        %autorelease
b3d410f
Summary:        Setuptools extension to build and package CMake projects
b3d410f
dc0cc5b
# The entire source is MIT, except example/bindings_swig/numpy.i, which is
dc0cc5b
# BSD-3-Clause, and test_example/bindings_swig/numpy.i, which is also
dc0cc5b
# BSD-3-Clause but does not contribute to any of the binary RPMs.
dc0cc5b
License:        MIT AND BSD-3-Clause
b3d410f
URL:            https://github.com/diegoferigo/cmake-build-extension
4cd1b55
Source:         %{pypi_source cmake-build-extension}
b3d410f
b3d410f
BuildArch:      noarch
b3d410f
b3d410f
BuildRequires:  python3-devel
b3d410f
BuildRequires:  cmake
b3d410f
BuildRequires:  ninja-build
b3d410f
b3d410f
%if %{with test_example}
b3d410f
BuildRequires:  gcc
b3d410f
BuildRequires:  gcc-c++
b3d410f
b3d410f
BuildRequires:  swig
b3d410f
# Even though pybind11 and eigen3 are  header-only, we don’t need to BR:
b3d410f
# pybind11-static nor eigen3-static, because nothing we install is built with
b3d410f
# them; they are only used for test-building the example.
b3d410f
BuildRequires:  cmake(pybind11)
b3d410f
BuildRequires:  cmake(Eigen3)
b3d410f
b3d410f
BuildRequires:  python3dist(pytest)
b3d410f
%endif
b3d410f
de9f66e
%global common_description %{expand:
b3d410f
This project aims to simplify the integration of C++ projects based on CMake
b3d410f
with Python packaging tools. CMake provides out-of-the-box support to either
b3d410f
SWIG and pybind11, that are two among the most used projects to create Python
b3d410f
bindings from C++ sources.
b3d410f
b3d410f
If you have any experience with these hybrid projects, you know the challenges
b3d410f
to make packaging right! This project takes inspiration from pre-existing
b3d410f
examples (pybind/cmake_example, among many others) and provides a simple,
b3d410f
flexible, and reusable setuptools extension with the following features:
b3d410f
b3d410f
  • Bridge between CMake projects and Python packaging.
b3d410f
  • Configure and build the CMake project from setup.py.
b3d410f
  • Install the CMake project in the resulting Python package.
b3d410f
  • Allow passing custom CMake options.
b3d410f
  • Allow creating a top-level __init__.py.
b3d410f
  • Expose C++ executables to the Python environment.
b3d410f
  • Provide a context manager to import reliably CPython modules on all major
b3d410f
    OSs.
b3d410f
  • Disable the C++ extension in editable installations (requiring to manually
b3d410f
    call CMake to install the C++ project).}
b3d410f
de9f66e
%description %{common_description}
b3d410f
b3d410f
b3d410f
%package -n python3-cmake-build-extension
b3d410f
Summary:        %{summary}
b3d410f
b3d410f
# Since this subpackage does not contain the example project, it has no
dc0cc5b
# BSD-3-Clause licensed sources.
b3d410f
License:        MIT
b3d410f
b3d410f
Requires:       cmake
b3d410f
Requires:       ninja-build
b3d410f
de9f66e
%description -n python3-cmake-build-extension %{common_description}
b3d410f
b3d410f
b3d410f
%package -n python3-cmake-build-extension-doc
b3d410f
Summary:        Documentation and examples for cmake-build-extension
b3d410f
b3d410f
Requires:       python3-cmake-build-extension = %{version}-%{release}
b3d410f
de9f66e
%description -n python3-cmake-build-extension-doc %{common_description}
b3d410f
b3d410f
b3d410f
%prep
b3d410f
%autosetup -n cmake-build-extension-%{version} -p1
b3d410f
b3d410f
# We use the system cmake and ninja-build packages in lieu of the PyPI “cmake”
b3d410f
# and “ninja” distributions, respectively.
b3d410f
sed -r -i '/^[[:blank:]]*\b(cmake|ninja)\b[[:blank:]]*$/d' setup.cfg
b3d410f
b3d410f
%if %{with test_example}
b3d410f
# Keep the original example/ “clean” so we can install it as documentation;
b3d410f
# make a copy to test-build.
b3d410f
cp -rp example test_example
b3d410f
%endif
b3d410f
b3d410f
b3d410f
%generate_buildrequires
b3d410f
%pyproject_buildrequires
b3d410f
%if %{with test_example}
b3d410f
(
b3d410f
  cd test_example >/dev/null
b3d410f
  # For an unknown reason, “-x test” does not generate the appropriate BR’s
b3d410f
  # here. Furthermore, python3dist(pytest-icdiff) is not packaged, so we would
b3d410f
  # have to patch it out anyway. We just use manual BR’s for the example’s
b3d410f
  # tests instead.
b3d410f
  %pyproject_buildrequires
b3d410f
) | grep -Ev 'cmake-build-extension'
b3d410f
%endif
b3d410f
b3d410f
b3d410f
%build
b3d410f
%pyproject_wheel
b3d410f
b3d410f
b3d410f
%install
b3d410f
%pyproject_install
3bcc4d2
%pyproject_save_files -l cmake_build_extension
b3d410f
b3d410f
b3d410f
%check
b3d410f
# We choose to do an import “smoke test” even when we are test-building the
b3d410f
# example.
b3d410f
%pyproject_check_import
b3d410f
b3d410f
%if %{with test_example}
b3d410f
# Build the example project and run its tests (but do not install any compiled
b3d410f
# extensions as part of our RPM!)
b3d410f
pushd test_example >/dev/null
b3d410f
export PYTHONPATH='%{buildroot}%{python3_sitelib}'
b3d410f
%pyproject_wheel
b3d410f
6aa66e9
BLIB="${PWD}/build/lib.%{python3_platform}-cpython-%{python3_version_nodots}"
6aa66e9
export PYTHONPATH="${PYTHONPATH}:${BLIB}"
6aa66e9
export PATH="${PATH}:${BLIB}/mymath_pybind11/bin:${BLIB}/mymath_swig/bin"
b3d410f
%pytest
b3d410f
popd >/dev/null
b3d410f
%endif
b3d410f
b3d410f
b3d410f
%files -n python3-cmake-build-extension -f %{pyproject_files}
b3d410f
# pyproject_files handles LICENSE; verify with “rpm -qL -p …”
b3d410f
b3d410f
b3d410f
%files -n python3-cmake-build-extension-doc
b3d410f
%doc README.md
b3d410f
%doc example/
b3d410f
b3d410f
b3d410f
%changelog
b3d410f
%autochangelog