From 9c60342738d21a47ffa17b8405207facdfa75994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 28 Jun 2021 12:07:29 +0000 Subject: [PATCH] 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 --- macros.pyproject | 7 ++++ pyproject-rpm-macros.spec | 5 ++- tests/python-setuptools.spec | 79 ++++++++++++++++++++++++++++++++++++ tests/tests.yml | 3 ++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 tests/python-setuptools.spec diff --git a/macros.pyproject b/macros.pyproject index 7c72f6c..a5c39a3 100644 --- a/macros.pyproject +++ b/macros.pyproject @@ -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}}" %{?*} } diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index 29603a0..b700fea 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -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 - 0-41 +- Don't leak %%{_pyproject_builddir} to pytest collection + * Thu May 27 2021 Miro Hrončok - 0-40 - Don't leak $TMPDIR outside of pyproject macros - Set %%_pyproject_wheeldir and %%_pyproject_builddir relative to the source tree, not $PWD diff --git a/tests/python-setuptools.spec b/tests/python-setuptools.spec new file mode 100644 index 0000000..5970d05 --- /dev/null +++ b/tests/python-setuptools.spec @@ -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 diff --git a/tests/tests.yml b/tests/tests.yml index 70c6d70..f2a6f51 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -70,6 +70,9 @@ - poetry_core: dir: . run: ./mocktest.sh python-poetry-core + - setuptools: + dir: . + run: ./mocktest.sh python-setuptools required_packages: - mock - rpmdevtools