Modernize the specfile and run all tests

Use pyproject macros:

- Use `%pyproject_check_import` instead of manually calling `python -c`.

- The conditional setuptools_scm stuff can be removed.
  python-setuptools_scm is now part of RHEL.

Run all tests:

- Always run pytest unit tests
- Run all integration tests instead of just examples/hello-world.

Formatting:

- Two lines between specfile settings
- Make `%description`s DRY.
This commit is contained in:
Maxwell G 2023-06-12 02:16:58 +00:00
parent eb994eef50
commit 2b66248c7f
No known key found for this signature in database
GPG Key ID: F79E4E25E8C661F8

View File

@ -1,8 +1,10 @@
%if 0%{?rhel}
%bcond_with tests
%else
%bcond_without tests
%endif
# RHEL does not have packaged rust libraries
%bcond packaged_rust_libraries %{undefined rhel}
# The integration tests depend on the presence of these libraries
%bcond integration_tests %{with packaged_rust_libraries}
# Regex of integration tests to skip.
# * html-py-ever requires unpackaged rust crates
%global integration_tests_exc '^(html-py-ever)'
Name: python-setuptools-rust
Version: 1.7.0
@ -15,19 +17,24 @@ Source0: %{pypi_source setuptools-rust}
BuildArch: noarch
BuildRequires: python3-devel
BuildRequires: %{py3_dist pytest}
%if 0%{?fedora}
BuildRequires: rust-packaging
%else
# RHEL has rust-toolset and neither setuptools-scm nor wheel
BuildRequires: rust-toolset >= 1.45
%endif
%if %{with tests}
BuildRequires: rust-pyo3+default-devel
%if %{with integration_tests}
BuildRequires: %{py3_dist cffi}
%endif
%description
%global _description %{expand:
Setuptools helpers for Rust Python extensions. Compile and distribute Python
extensions written in Rust as easily as if they were written in C.
extensions written in Rust as easily as if they were written in C.}
%description %{_description}
%package -n python3-setuptools-rust
Summary: %{summary}
@ -37,44 +44,81 @@ Requires: rust-packaging
Requires: rust-toolset >= 1.45
%endif
%description -n python3-setuptools-rust
Setuptools helpers for Rust Python extensions. Compile and distribute Python
extensions written in Rust as easily as if they were written in C.
%description -n python3-setuptools-rust %{_description}
%prep
%autosetup -n setuptools-rust-%{version}
# Remove bundled egg-info
rm -rf setuptools-rust.egg-info
%if ! 0%{?fedora}
# RHEL doesn't have setuptools-scm, releases come with version.py
sed 's/"setuptools_scm"//' pyproject.toml
%cargo_prep
%if %{with integration_tests}
for example in $(ls examples/ | grep -vE %{integration_tests_exc}); do
cd "examples/${example}"
%cargo_prep
cd -
done
%endif
%generate_buildrequires
%pyproject_buildrequires
%if %{with integration_tests}
for example in $(ls examples/ | grep -vE %{integration_tests_exc}); do
cd "examples/${example}"
%cargo_generate_buildrequires
cd - >&2
done
%endif
%build
%pyproject_wheel
%install
%pyproject_install
%pyproject_save_files setuptools_rust
%check
PYTHONPATH=%{buildroot}%{python3_sitelib} \
%{__python3} -c "from setuptools_rust import RustExtension, version"
%if %{with tests}
cd examples/hello-world-setuppy
%cargo_prep
PYTHONPATH=%{buildroot}%{python3_sitelib} %{__python3} setup.py build
cd ../..
%check
%pyproject_check_import
# Disable tests that require internet access and/or test Windows functionality
%global test_ignores %{shrink:
not test_adjusted_local_rust_target_windows_msvc
and not test_get_lib_name_namespace_package
}
%if %{without packaged_rust_libraries}
%global test_ignores %{shrink:%{test_ignores}
and not test_metadata_contents
and not test_metadata_cargo_log
}
%endif
%pytest tests/ setuptools_rust/ --import-mode importlib -k '%{test_ignores}'
%if %{with integration_tests}
export PYTHONPATH=%{buildroot}%{python3_sitelib}
for example in $(ls examples/ | grep -vE %{integration_tests_exc}); do
cd "examples/${example}"
%{python3} -c 'from setuptools.build_meta import build_wheel; build_wheel("dist")'
if [ -d "tests/" ]; then
%{python3} -m venv venv --system-site-packages
. ./venv/bin/activate
pip install dist/*.whl
python -Pm pytest tests/
deactivate
fi
cd -
done
%endif
%files -n python3-setuptools-rust -f %{pyproject_files}
%doc README.md CHANGELOG.md
%license LICENSE
%changelog
%autochangelog