Blame macros.pyproject

1642d25
# This is a directory where wheels are stored and installed from, absolute
29157c1
%_pyproject_wheeldir %{_builddir}%{?buildsubdir:/%{buildsubdir}}/pyproject-wheeldir
95ba837
95ba837
# This is a directory used as TMPDIR, where pip copies sources to and builds from, relative to PWD
95ba837
# For proper debugsource packages, we create TMPDIR within PWD
95ba837
# See https://github.com/pypa/pip/issues/7555#issuecomment-595180864
95ba837
#
95ba837
# This will be used in debugsource package paths (applies to extension modules only)
95ba837
# NB: pytest collects tests from here if not hidden
95ba837
#     https://docs.pytest.org/en/latest/reference.html#confval-norecursedirs
29157c1
%_pyproject_builddir %{_builddir}%{?buildsubdir:/%{buildsubdir}}/.pyproject-builddir
49a323e
ae639fc
# We prefix all created files with this value to make them unique
ae639fc
# Ideally, we would put them into %%{buildsubdir}, but that value changes during the spec
ae639fc
# The used value is similar to the one used to define the default %%buildroot
ae639fc
%_pyproject_files_prefix %{name}-%{version}-%{release}.%{_arch}
ae639fc
ae639fc
%pyproject_files %{_builddir}/%{_pyproject_files_prefix}-pyproject-files
ae639fc
%_pyproject_modules %{_builddir}/%{_pyproject_files_prefix}-pyproject-modules
ae639fc
%_pyproject_ghost_distinfo %{_builddir}/%{_pyproject_files_prefix}-pyproject-ghost-distinfo
ae639fc
%_pyproject_record %{_builddir}/%{_pyproject_files_prefix}-pyproject-record
2800b49
5470f56
# Avoid leaking %%{_pyproject_builddir} to pytest collection
5470f56
# https://bugzilla.redhat.com/show_bug.cgi?id=1935212
5470f56
# The value is read and used by the %%pytest and %%tox macros:
5470f56
%_set_pytest_addopts %global __pytest_addopts --ignore=%{_pyproject_builddir}
5470f56
162b0ca
%pyproject_wheel() %{expand:\\\
5470f56
%_set_pytest_addopts
29157c1
mkdir -p "%{_pyproject_builddir}"
29157c1
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}" TMPDIR="%{_pyproject_builddir}" \\\
40f6765
%{__python3} -Bs %{_rpmconfigdir}/redhat/pyproject_wheel.py %{_pyproject_wheeldir}
162b0ca
}
162b0ca
162b0ca
a5e7a3c
%pyproject_build_lib %{!?__pyproject_build_lib_warned:%{warn:The %%{pyproject_build_lib} macro is deprecated.
a5e7a3c
It only works with setuptools and is not build-backend-agnostic.
a5e7a3c
The macro is not scheduled for removal, but there is a possibility of incompatibilities with future versions of setuptools.
a5e7a3c
As a replacement for the macro for the setuptools backend on Fedora 37+, you can use $PWD/build/lib for pure Python packages,
a5e7a3c
or $PWD/build/lib.%%{python3_platform}-cpython-%%{python3_version_nodots} for packages with extension modules.
a5e7a3c
Other build backends and older distributions may need different paths.
a5e7a3c
See https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/HMLOPAU3RZLXD4BOJHTIPKI3I4U6U7OE/ for details.
576ea5a
}%global __pyproject_build_lib_warned 1}%{expand:\\\
55905e4
$(
55905e4
pyproject_build_lib=()
1996e90
if [ -d build/lib.%{python3_platform}-cpython-%{python3_version_nodots} ]; then
1996e90
  pyproject_build_lib+=( "${PWD}/build/lib.%{python3_platform}-cpython-%{python3_version_nodots}" )
1996e90
fi
55905e4
if [ -d build/lib.%{python3_platform}-%{python3_version} ]; then
55905e4
  pyproject_build_lib+=( "${PWD}/build/lib.%{python3_platform}-%{python3_version}" )
55905e4
fi
55905e4
if [ -d build/lib ]; then
55905e4
  pyproject_build_lib+=( "${PWD}/build/lib" )
55905e4
fi
55905e4
for directory in $(find "%{_pyproject_builddir}" -type d -wholename "%{_pyproject_builddir}/pip-req-build-*/build/lib.%{python3_platform}-%{python3_version}" 2>/dev/null); do
55905e4
  pyproject_build_lib+=( "${directory}" )
55905e4
done
55905e4
for directory in $(find "%{_pyproject_builddir}" -type d -wholename "%{_pyproject_builddir}/pip-req-build-*/build/lib" 2>/dev/null); do
55905e4
  pyproject_build_lib+=( "${directory}" )
55905e4
done
55905e4
echo $(IFS=:; echo "${pyproject_build_lib[*]}")
55905e4
)}
55905e4
55905e4
162b0ca
%pyproject_install() %{expand:\\\
19f84b1
specifier=$(ls %{_pyproject_wheeldir}/*.whl | xargs basename --multiple | sed -E 's/([^-]+)-([^-]+)-.+\\\.whl/\\\1==\\\2/')
Owen W. Taylor 946c872
TMPDIR="%{_pyproject_builddir}" %{__python3} -m pip install --root %{buildroot} --prefix %{_prefix} --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
fdf5116
if [ -d %{buildroot}%{_bindir} ]; then
a506123
  %py3_shebang_fix %{buildroot}%{_bindir}/*
8cce1fa
  rm -rfv %{buildroot}%{_bindir}/__pycache__
162b0ca
fi
8588098
rm -f %{_pyproject_ghost_distinfo}
8d5b3ac
site_dirs=()
8d5b3ac
# Process %%{python3_sitelib} if exists
fdf5116
if [ -d %{buildroot}%{python3_sitelib} ]; then
8d5b3ac
  site_dirs+=( "%{python3_sitelib}" )
253976c
fi
8d5b3ac
# Process %%{python3_sitearch} if exists and does not equal to %%{python3_sitelib}
cb4e43c
if [ %{buildroot}%{python3_sitearch} != %{buildroot}%{python3_sitelib} ] && [ -d %{buildroot}%{python3_sitearch} ]; then
8d5b3ac
  site_dirs+=( "%{python3_sitearch}" )
8d5b3ac
fi
8d5b3ac
# Process all *.dist-info dirs in sitelib/sitearch
8d5b3ac
for site_dir in ${site_dirs[@]}; do
8d5b3ac
  for distinfo in %{buildroot}$site_dir/*.dist-info; do
8588098
    echo "%ghost ${distinfo#%{buildroot}}" >> %{_pyproject_ghost_distinfo}
cb4e43c
    sed -i 's/pip/rpm/' ${distinfo}/INSTALLER
8d5b3ac
    PYTHONPATH=%{_rpmconfigdir}/redhat \\
8d5b3ac
      %{__python3} -B %{_rpmconfigdir}/redhat/pyproject_preprocess_record.py \\
8588098
      --buildroot %{buildroot} --record ${distinfo}/RECORD --output %{_pyproject_record}
c5d2f62
    rm -fv ${distinfo}/RECORD
c5d2f62
    rm -fv ${distinfo}/REQUESTED
cb4e43c
  done
8d5b3ac
done
8588098
lines=$(wc -l %{_pyproject_ghost_distinfo} | cut -f1 -d" ")
cb4e43c
if [ $lines -ne 1 ]; then
3309d2d
  echo -e "\\n\\nWARNING: %%%%pyproject_extras_subpkg won't work without explicit -i or -F, found $lines dist-info directories.\\n\\n" >&2
8588098
  rm %{_pyproject_ghost_distinfo}  # any attempt to use this will fail
fdf5116
fi
fdf5116
}
fdf5116
2800b49
7e5adc9
# Note: the three times nested questionmarked -i -f -F pattern means: If none of those options was used -- in that case, we inject our own -f
8588098
%pyproject_extras_subpkg(n:i:f:F) %{expand:%{?python_extras_subpkg:%{python_extras_subpkg%{?!-i:%{?!-f:%{?!-F: -f %{_pyproject_ghost_distinfo}}}} %**}}}
cb4e43c
cb4e43c
2800b49
%pyproject_save_files() %{expand:\\\
2800b49
%{__python3} %{_rpmconfigdir}/redhat/pyproject_save_files.py \\
c1baa53
  --output-files "%{pyproject_files}" \\
c1baa53
  --output-modules "%{_pyproject_modules}" \\
2800b49
  --buildroot "%{buildroot}" \\
2800b49
  --sitelib "%{python3_sitelib}" \\
2800b49
  --sitearch "%{python3_sitearch}" \\
2800b49
  --python-version "%{python3_version}" \\
8588098
  --pyproject-record "%{_pyproject_record}" \\
c3a20e9
  --prefix "%{_prefix}" \\
2800b49
  %{*}
2800b49
}
2800b49
c1baa53
# -t - Process only top-level modules
c1baa53
# -e - Exclude the module names matching given glob, may be used repeatedly
c1baa53
%pyproject_check_import(e:t) %{expand:\\\
c1baa53
if [ ! -f "%{_pyproject_modules}" ]; then
c1baa53
  echo 'ERROR: %%%%pyproject_check_import only works when %%%%pyproject_save_files is used' >&2
c1baa53
  exit 1
c1baa53
fi
c1baa53
%py3_check_import -f "%{_pyproject_modules}" %{?**}
c1baa53
}
c1baa53
2800b49