Avoid leaking %{_pyproject_builddir} to pytest collection

Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1935212

Requires a %pytest change: https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/102

Related: rhbz#1950291
This commit is contained in:
Miro Hrončok 2021-06-28 12:07:29 +00:00
parent a8147ee22b
commit 9c60342738
4 changed files with 93 additions and 1 deletions

View File

@ -14,7 +14,13 @@
%pyproject_ghost_distinfo %{_builddir}/pyproject-ghost-distinfo
%pyproject_record %{_builddir}/pyproject-record
# Avoid leaking %%{_pyproject_builddir} to pytest collection
# https://bugzilla.redhat.com/show_bug.cgi?id=1935212
# The value is read and used by the %%pytest and %%tox macros:
%_set_pytest_addopts %global __pytest_addopts --ignore=%{_pyproject_builddir}
%pyproject_wheel() %{expand:\\\
%_set_pytest_addopts
mkdir -p "%{_pyproject_builddir}"
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}" TMPDIR="%{_pyproject_builddir}" \\\
%{__python3} -m pip wheel --wheel-dir %{_pyproject_wheeldir} --no-deps --use-pep517 --no-build-isolation --disable-pip-version-check --no-clean --progress-bar off --verbose .
@ -109,6 +115,7 @@ TOX_TESTENV_PASSENV="${TOX_TESTENV_PASSENV:-*}" \\
PYTHONDONTWRITEBYTECODE=1 \\
PATH="%{buildroot}%{_bindir}:$PATH" \\
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}" \\
%{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"} \\
HOSTNAME="rpmbuild" \\
%{__python3} -m tox --current-env -q --recreate -e "%{-e:%{-e*}}%{!-e:%{toxenv}}" %{?*}
}

View File

@ -12,7 +12,7 @@ License: MIT
# In other cases, such as backports, increment the point
# release.
Version: 0
Release: 40%{?dist}
Release: 41%{?dist}
# Macro files
Source001: macros.pyproject
@ -110,6 +110,9 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856
%license LICENSE
%changelog
* Mon Jun 28 2021 Miro Hrončok <mhroncok@redhat.com> - 0-41
- Don't leak %%{_pyproject_builddir} to pytest collection
* Thu May 27 2021 Miro Hrončok <mhroncok@redhat.com> - 0-40
- Don't leak $TMPDIR outside of pyproject macros
- Set %%_pyproject_wheeldir and %%_pyproject_builddir relative to the source tree, not $PWD

View File

@ -0,0 +1,79 @@
Name: python-setuptools
Version: 57.0.0
Release: 0%{?dist}
Summary: Easily build and distribute Python packages
# see the real Fedora package for explanation:
License: MIT and (BSD or ASL 2.0)
URL: https://pypi.python.org/pypi/setuptools
Source0: %{pypi_source setuptools %{version}}
BuildArch: noarch
BuildRequires: python3-devel
BuildRequires: pyproject-rpm-macros
BuildRequires: gcc
%description
This package tests 2 things:
- %%{_pyproject_builddir} does not leak to pytest collection (rhzb#1935212)
- TODO %%{pyproject_files} has escaped spaces (rhzb#1976363)
%package -n python3-setuptools
Summary: %{summary}
# For users who might see ModuleNotFoundError: No module named 'pkg_resoureces'
%py_provides python3-pkg_resources
%py_provides python3-pkg-resources
%description -n python3-setuptools
...
%prep
%autosetup -p1 -n setuptools-%{version}
# The following test deps are optional and either not desired or not available in Fedora:
sed -Ei setup.cfg -e '/\bpytest-(checkdocs|black|cov|mypy|enabler)\b/d' \
-e '/\bflake8\b/d' \
-e '/\bpaver\b/d'
# Strip pytest options from the above
sed -i pytest.ini -e 's/ --flake8//' \
-e 's/ --cov//'
%generate_buildrequires
%pyproject_buildrequires -r -x testing
%build
%pyproject_wheel
%install
%pyproject_install
%pyproject_save_files setuptools pkg_resources _distutils_hack
# https://github.com/pypa/setuptools/issues/2709
rm -rf %{buildroot}%{python3_sitelib}/pkg_resources/tests/
sed -i '/tests/d' %{pyproject_files}
# Paths with spaces are not properly protected by %%pyproject_save_files
# https://bugzilla.redhat.com/show_bug.cgi?id=1976363
# This workaround will most likely break once fixed
sed -Ei 's|/(.+) (.+)|"/\1 \2"|' %{pyproject_files}
%check
# https://github.com/pypa/setuptools/discussions/2607
rm pyproject.toml
# We only run a subset of tests to speed things up and be less fragile
PYTHONPATH=$(pwd) %pytest --ignore=pavement.py -k "sdist"
%files -n python3-setuptools -f %{pyproject_files}
%license LICENSE
%doc docs/* CHANGES.rst README.rst
%{python3_sitelib}/distutils-precedence.pth

View File

@ -70,6 +70,9 @@
- poetry_core:
dir: .
run: ./mocktest.sh python-poetry-core
- setuptools:
dir: .
run: ./mocktest.sh python-setuptools
required_packages:
- mock
- rpmdevtools