Set %_pyproject_wheeldir and %_pyproject_builddir relative to the source tree, not $PWD

This allows users to do:

    %build
    cd somewhere
    %pyproject_wheel
    cd -
    cd somewhere_else
    %pyproject_wheel
    cd -

    %install
    %pyproject_install

Without a need to copy paste the wheels to a common location.

This is in fact a breaking change, I'll make sure to adapt the affected packages in Fedora.

Related: rhbz#1950291
This commit is contained in:
Miro Hrončok 2021-05-27 19:28:01 +00:00
parent 1cacdb2b62
commit 71f414ef2c
4 changed files with 14 additions and 9 deletions

View File

@ -60,7 +60,7 @@ And install the wheel in `%install` with `%pyproject_install`:
%install %install
%pyproject_install %pyproject_install
`%pyproject_install` installs all wheels in `$PWD/pyproject-wheeldir/`. `%pyproject_install` installs all wheels in `pyproject-wheeldir/` located in the root of the source tree.
Adding run-time and test-time dependencies Adding run-time and test-time dependencies

View File

@ -1,5 +1,5 @@
# This is a directory where wheels are stored and installed from, relative to PWD # This is a directory where wheels are stored and installed from, relative to PWD
%_pyproject_wheeldir pyproject-wheeldir %_pyproject_wheeldir %{_builddir}%{?buildsubdir:/%{buildsubdir}}/pyproject-wheeldir
# This is a directory used as TMPDIR, where pip copies sources to and builds from, relative to PWD # This is a directory used as TMPDIR, where pip copies sources to and builds from, relative to PWD
# For proper debugsource packages, we create TMPDIR within PWD # For proper debugsource packages, we create TMPDIR within PWD
@ -8,22 +8,22 @@
# This will be used in debugsource package paths (applies to extension modules only) # This will be used in debugsource package paths (applies to extension modules only)
# NB: pytest collects tests from here if not hidden # NB: pytest collects tests from here if not hidden
# https://docs.pytest.org/en/latest/reference.html#confval-norecursedirs # https://docs.pytest.org/en/latest/reference.html#confval-norecursedirs
%_pyproject_builddir .pyproject-builddir %_pyproject_builddir %{_builddir}%{?buildsubdir:/%{buildsubdir}}/.pyproject-builddir
%pyproject_files %{_builddir}/pyproject-files %pyproject_files %{_builddir}/pyproject-files
%pyproject_ghost_distinfo %{_builddir}/pyproject-ghost-distinfo %pyproject_ghost_distinfo %{_builddir}/pyproject-ghost-distinfo
%pyproject_record %{_builddir}/pyproject-record %pyproject_record %{_builddir}/pyproject-record
%pyproject_wheel() %{expand:\\\ %pyproject_wheel() %{expand:\\\
mkdir -p "${PWD}/%{_pyproject_builddir}" mkdir -p "%{_pyproject_builddir}"
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}" TMPDIR="${PWD}/%{_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 . %{__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 .
} }
%pyproject_install() %{expand:\\\ %pyproject_install() %{expand:\\\
specifier=$(ls %{_pyproject_wheeldir}/*.whl | xargs basename --multiple | sed -E 's/([^-]+)-([^-]+)-.+\\\.whl/\\\1==\\\2/') specifier=$(ls %{_pyproject_wheeldir}/*.whl | xargs basename --multiple | sed -E 's/([^-]+)-([^-]+)-.+\\\.whl/\\\1==\\\2/')
TMPDIR="${PWD}/%{_pyproject_builddir}" %{__python3} -m pip install --root %{buildroot} --no-deps --disable-pip-version-check --progress-bar off --verbose --ignore-installed --no-warn-script-location --no-index --no-cache-dir --find-links %{_pyproject_wheeldir} $specifier TMPDIR="%{_pyproject_builddir}" %{__python3} -m pip install --root %{buildroot} --no-deps --disable-pip-version-check --progress-bar off --verbose --ignore-installed --no-warn-script-location --no-index --no-cache-dir --find-links %{_pyproject_wheeldir} $specifier
if [ -d %{buildroot}%{_bindir} ]; then if [ -d %{buildroot}%{_bindir} ]; then
%py3_shebang_fix %{buildroot}%{_bindir}/* %py3_shebang_fix %{buildroot}%{_bindir}/*
rm -rfv %{buildroot}%{_bindir}/__pycache__ rm -rfv %{buildroot}%{_bindir}/__pycache__

View File

@ -112,6 +112,7 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856
%changelog %changelog
* Thu May 27 2021 Miro Hrončok <mhroncok@redhat.com> - 0-40 * Thu May 27 2021 Miro Hrončok <mhroncok@redhat.com> - 0-40
- Don't leak $TMPDIR outside of pyproject macros - Don't leak $TMPDIR outside of pyproject macros
- Set %%_pyproject_wheeldir and %%_pyproject_builddir relative to the source tree, not $PWD
* Thu Apr 22 2021 Miro Hrončok <mhroncok@redhat.com> - 0-39.2 * Thu Apr 22 2021 Miro Hrončok <mhroncok@redhat.com> - 0-39.2
- Handle tox provision (tox.requires / tox.minversion) - Handle tox provision (tox.requires / tox.minversion)

View File

@ -5,13 +5,14 @@ Summary: Distribution-building parts of Flit
License: BSD License: BSD
URL: https://pypi.org/project/flit-core/ URL: https://pypi.org/project/flit-core/
Source0: %{pypi_source flit_core} Source0: https://github.com/takluyver/flit/archive/%{version}/flit-%{version}.tar.gz
BuildArch: noarch BuildArch: noarch
BuildRequires: python3-devel BuildRequires: python3-devel
BuildRequires: pyproject-rpm-macros BuildRequires: pyproject-rpm-macros
%description %description
Test a wheel built from a subdirectory.
Test a build with pyproject.toml backend-path = . Test a build with pyproject.toml backend-path = .
flit-core builds with flit-core. flit-core builds with flit-core.
@ -24,15 +25,18 @@ Summary: %{summary}
%prep %prep
%autosetup -p1 -n flit_core-%{version} %autosetup -p1 -n flit-%{version}
%generate_buildrequires %generate_buildrequires
cd flit_core
%pyproject_buildrequires %pyproject_buildrequires
cd ..
%build %build
cd flit_core
%pyproject_wheel %pyproject_wheel
cd ..
%install %install