|
|
20b2b6 |
# This is a directory where wheels are stored and installed from, absolute
|
|
|
7ef706 |
%_pyproject_wheeldir %{_builddir}%{?buildsubdir:/%{buildsubdir}}/pyproject-wheeldir
|
|
|
7ef706 |
|
|
|
7ef706 |
# This is a directory used as TMPDIR, where pip copies sources to and builds from, relative to PWD
|
|
|
7ef706 |
# For proper debugsource packages, we create TMPDIR within PWD
|
|
|
7ef706 |
# See https://github.com/pypa/pip/issues/7555#issuecomment-595180864
|
|
|
7ef706 |
#
|
|
|
7ef706 |
# This will be used in debugsource package paths (applies to extension modules only)
|
|
|
7ef706 |
# NB: pytest collects tests from here if not hidden
|
|
|
7ef706 |
# https://docs.pytest.org/en/latest/reference.html#confval-norecursedirs
|
|
|
7ef706 |
%_pyproject_builddir %{_builddir}%{?buildsubdir:/%{buildsubdir}}/.pyproject-builddir
|
|
|
7ef706 |
|
|
|
20b2b6 |
# We prefix all created files with this value to make them unique
|
|
|
20b2b6 |
# Ideally, we would put them into %%{buildsubdir}, but that value changes during the spec
|
|
|
20b2b6 |
# The used value is similar to the one used to define the default %%buildroot
|
|
|
20b2b6 |
%_pyproject_files_prefix %{name}-%{version}-%{release}.%{_arch}
|
|
|
20b2b6 |
|
|
|
20b2b6 |
%pyproject_files %{_builddir}/%{_pyproject_files_prefix}-pyproject-files
|
|
|
20b2b6 |
%_pyproject_modules %{_builddir}/%{_pyproject_files_prefix}-pyproject-modules
|
|
|
20b2b6 |
%_pyproject_ghost_distinfo %{_builddir}/%{_pyproject_files_prefix}-pyproject-ghost-distinfo
|
|
|
20b2b6 |
%_pyproject_record %{_builddir}/%{_pyproject_files_prefix}-pyproject-record
|
|
|
7ef706 |
|
|
|
7ef706 |
# Avoid leaking %%{_pyproject_builddir} to pytest collection
|
|
|
7ef706 |
# https://bugzilla.redhat.com/show_bug.cgi?id=1935212
|
|
|
7ef706 |
# The value is read and used by the %%pytest and %%tox macros:
|
|
|
7ef706 |
%_set_pytest_addopts %global __pytest_addopts --ignore=%{_pyproject_builddir}
|
|
|
7ef706 |
|
|
|
7ef706 |
%pyproject_wheel() %{expand:\\\
|
|
|
7ef706 |
%_set_pytest_addopts
|
|
|
7ef706 |
mkdir -p "%{_pyproject_builddir}"
|
|
|
7ef706 |
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}" TMPDIR="%{_pyproject_builddir}" \\\
|
|
|
20b2b6 |
%{__python3} -Bs %{_rpmconfigdir}/redhat/pyproject_wheel.py %{_pyproject_wheeldir}
|
|
|
7ef706 |
}
|
|
|
7ef706 |
|
|
|
7ef706 |
|
|
|
7ef706 |
%pyproject_build_lib %{expand:\\\
|
|
|
7ef706 |
$(
|
|
|
7ef706 |
pyproject_build_lib=()
|
|
|
20b2b6 |
if [ -d build/lib.%{python3_platform}-cpython-%{python3_version_nodots} ]; then
|
|
|
20b2b6 |
pyproject_build_lib+=( "${PWD}/build/lib.%{python3_platform}-cpython-%{python3_version_nodots}" )
|
|
|
20b2b6 |
fi
|
|
|
7ef706 |
if [ -d build/lib.%{python3_platform}-%{python3_version} ]; then
|
|
|
7ef706 |
pyproject_build_lib+=( "${PWD}/build/lib.%{python3_platform}-%{python3_version}" )
|
|
|
7ef706 |
fi
|
|
|
7ef706 |
if [ -d build/lib ]; then
|
|
|
7ef706 |
pyproject_build_lib+=( "${PWD}/build/lib" )
|
|
|
7ef706 |
fi
|
|
|
7ef706 |
for directory in $(find "%{_pyproject_builddir}" -type d -wholename "%{_pyproject_builddir}/pip-req-build-*/build/lib.%{python3_platform}-%{python3_version}" 2>/dev/null); do
|
|
|
7ef706 |
pyproject_build_lib+=( "${directory}" )
|
|
|
7ef706 |
done
|
|
|
7ef706 |
for directory in $(find "%{_pyproject_builddir}" -type d -wholename "%{_pyproject_builddir}/pip-req-build-*/build/lib" 2>/dev/null); do
|
|
|
7ef706 |
pyproject_build_lib+=( "${directory}" )
|
|
|
7ef706 |
done
|
|
|
7ef706 |
echo $(IFS=:; echo "${pyproject_build_lib[*]}")
|
|
|
7ef706 |
)}
|
|
|
7ef706 |
|
|
|
7ef706 |
|
|
|
7ef706 |
%pyproject_install() %{expand:\\\
|
|
|
7ef706 |
specifier=$(ls %{_pyproject_wheeldir}/*.whl | xargs basename --multiple | sed -E 's/([^-]+)-([^-]+)-.+\\\.whl/\\\1==\\\2/')
|
|
|
20b2b6 |
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
|
|
|
7ef706 |
if [ -d %{buildroot}%{_bindir} ]; then
|
|
|
7ef706 |
%py3_shebang_fix %{buildroot}%{_bindir}/*
|
|
|
7ef706 |
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
|
|
7ef706 |
fi
|
|
|
7ef706 |
rm -f %{_pyproject_ghost_distinfo}
|
|
|
7ef706 |
site_dirs=()
|
|
|
7ef706 |
# Process %%{python3_sitelib} if exists
|
|
|
7ef706 |
if [ -d %{buildroot}%{python3_sitelib} ]; then
|
|
|
7ef706 |
site_dirs+=( "%{python3_sitelib}" )
|
|
|
7ef706 |
fi
|
|
|
7ef706 |
# Process %%{python3_sitearch} if exists and does not equal to %%{python3_sitelib}
|
|
|
7ef706 |
if [ %{buildroot}%{python3_sitearch} != %{buildroot}%{python3_sitelib} ] && [ -d %{buildroot}%{python3_sitearch} ]; then
|
|
|
7ef706 |
site_dirs+=( "%{python3_sitearch}" )
|
|
|
7ef706 |
fi
|
|
|
7ef706 |
# Process all *.dist-info dirs in sitelib/sitearch
|
|
|
7ef706 |
for site_dir in ${site_dirs[@]}; do
|
|
|
7ef706 |
for distinfo in %{buildroot}$site_dir/*.dist-info; do
|
|
|
7ef706 |
echo "%ghost ${distinfo#%{buildroot}}" >> %{_pyproject_ghost_distinfo}
|
|
|
7ef706 |
sed -i 's/pip/rpm/' ${distinfo}/INSTALLER
|
|
|
7ef706 |
PYTHONPATH=%{_rpmconfigdir}/redhat \\
|
|
|
7ef706 |
%{__python3} -B %{_rpmconfigdir}/redhat/pyproject_preprocess_record.py \\
|
|
|
7ef706 |
--buildroot %{buildroot} --record ${distinfo}/RECORD --output %{_pyproject_record}
|
|
|
7ef706 |
rm -fv ${distinfo}/RECORD
|
|
|
7ef706 |
rm -fv ${distinfo}/REQUESTED
|
|
|
7ef706 |
done
|
|
|
7ef706 |
done
|
|
|
7ef706 |
lines=$(wc -l %{_pyproject_ghost_distinfo} | cut -f1 -d" ")
|
|
|
7ef706 |
if [ $lines -ne 1 ]; then
|
|
|
7ef706 |
echo -e "\\n\\nWARNING: %%%%pyproject_extras_subpkg won't work without explicit -i or -F, found $lines dist-info directories.\\n\\n" >&2
|
|
|
7ef706 |
rm %{_pyproject_ghost_distinfo} # any attempt to use this will fail
|
|
|
7ef706 |
fi
|
|
|
7ef706 |
}
|
|
|
7ef706 |
|
|
|
7ef706 |
|
|
|
7ef706 |
# 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
|
|
|
7ef706 |
%pyproject_extras_subpkg(n:i:f:F) %{expand:%{?python_extras_subpkg:%{python_extras_subpkg%{?!-i:%{?!-f:%{?!-F: -f %{_pyproject_ghost_distinfo}}}} %**}}}
|
|
|
7ef706 |
|
|
|
7ef706 |
|
|
|
7ef706 |
%pyproject_save_files() %{expand:\\\
|
|
|
7ef706 |
%{__python3} %{_rpmconfigdir}/redhat/pyproject_save_files.py \\
|
|
|
7ef706 |
--output-files "%{pyproject_files}" \\
|
|
|
7ef706 |
--output-modules "%{_pyproject_modules}" \\
|
|
|
7ef706 |
--buildroot "%{buildroot}" \\
|
|
|
7ef706 |
--sitelib "%{python3_sitelib}" \\
|
|
|
7ef706 |
--sitearch "%{python3_sitearch}" \\
|
|
|
7ef706 |
--python-version "%{python3_version}" \\
|
|
|
7ef706 |
--pyproject-record "%{_pyproject_record}" \\
|
|
|
7ef706 |
--prefix "%{_prefix}" \\
|
|
|
7ef706 |
%{*}
|
|
|
7ef706 |
}
|
|
|
7ef706 |
|
|
|
7ef706 |
# -t - Process only top-level modules
|
|
|
7ef706 |
# -e - Exclude the module names matching given glob, may be used repeatedly
|
|
|
7ef706 |
%pyproject_check_import(e:t) %{expand:\\\
|
|
|
7ef706 |
if [ ! -f "%{_pyproject_modules}" ]; then
|
|
|
7ef706 |
echo 'ERROR: %%%%pyproject_check_import only works when %%%%pyproject_save_files is used' >&2
|
|
|
7ef706 |
exit 1
|
|
|
7ef706 |
fi
|
|
|
7ef706 |
%py3_check_import -f "%{_pyproject_modules}" %{?**}
|
|
|
7ef706 |
}
|
|
|
7ef706 |
|
|
|
7ef706 |
|
|
|
7ef706 |
%default_toxenv py%{python3_version_nodots}
|
|
|
7ef706 |
%toxenv %{default_toxenv}
|
|
|
7ef706 |
|
|
|
7ef706 |
|
|
|
5d3ed2 |
# Note: Keep the options in sync with this macro from macros.aaa-pyproject-srpm
|
|
|
20b2b6 |
%pyproject_buildrequires(rRxtNwe:) %{expand:\\\
|
|
|
20b2b6 |
%_set_pytest_addopts
|
|
|
20b2b6 |
# The _auto_set_build_flags feature does not do this in %%generate_buildrequires section,
|
|
|
20b2b6 |
# but we want to get an environment consistent with %%build:
|
|
|
20b2b6 |
%{?_auto_set_build_flags:%set_build_flags}
|
|
|
20b2b6 |
# The default flags expect the package note file to exist
|
|
|
20b2b6 |
# see https://bugzilla.redhat.com/show_bug.cgi?id=2097535
|
|
|
20b2b6 |
%{?_package_note_flags:%_generate_package_note_file}
|
|
|
20b2b6 |
%{-R:
|
|
|
20b2b6 |
%{-r:%{error:The -R and -r options are mutually exclusive}}
|
|
|
20b2b6 |
%{-w:%{error:The -R and -w options are mutually exclusive}}
|
|
|
20b2b6 |
}
|
|
|
7ef706 |
%{-N:
|
|
|
7ef706 |
%{-r:%{error:The -N and -r options are mutually exclusive}}
|
|
|
7ef706 |
%{-x:%{error:The -N and -x options are mutually exclusive}}
|
|
|
7ef706 |
%{-e:%{error:The -N and -e options are mutually exclusive}}
|
|
|
7ef706 |
%{-t:%{error:The -N and -t options are mutually exclusive}}
|
|
|
20b2b6 |
%{-w:%{error:The -N and -w options are mutually exclusive}}
|
|
|
7ef706 |
}
|
|
|
7ef706 |
%{-e:%{expand:%global toxenv %(%{__python3} -s %{_rpmconfigdir}/redhat/pyproject_construct_toxenv.py %{?**})}}
|
|
|
5d3ed2 |
echo 'pyproject-rpm-macros' # first stdout line matches the implementation in macros.aaa-pyproject-srpm
|
|
|
7ef706 |
echo 'python%{python3_pkgversion}-devel'
|
|
|
7ef706 |
echo 'python%{python3_pkgversion}dist(pip) >= 19'
|
|
|
7ef706 |
echo 'python%{python3_pkgversion}dist(packaging)'
|
|
|
7ef706 |
%{!-N:if [ -f pyproject.toml ]; then
|
|
|
20b2b6 |
%["%{python3_pkgversion}" == "3"
|
|
|
20b2b6 |
? "echo '(python%{python3_pkgversion}dist(toml) if python%{python3_pkgversion}-devel < 3.11)'"
|
|
|
20b2b6 |
: "%[v"%{python3_pkgversion}" < v"3.11"
|
|
|
20b2b6 |
? "echo 'python%{python3_pkgversion}dist(toml)'"
|
|
|
20b2b6 |
: "true # will use tomllib, echo nothing"
|
|
|
20b2b6 |
]"
|
|
|
20b2b6 |
]
|
|
|
7ef706 |
elif [ -f setup.py ]; then
|
|
|
7ef706 |
# Note: If the default requirements change, also change them in the script!
|
|
|
7ef706 |
echo 'python%{python3_pkgversion}dist(setuptools) >= 40.8'
|
|
|
7ef706 |
echo 'python%{python3_pkgversion}dist(wheel)'
|
|
|
7ef706 |
else
|
|
|
7ef706 |
echo 'ERROR: Neither pyproject.toml nor setup.py found, consider using %%%%pyproject_buildrequires -N <requirements-file> if this is not a Python package.' >&2
|
|
|
7ef706 |
exit 1
|
|
|
7ef706 |
fi}
|
|
|
7ef706 |
# setuptools assumes no pre-existing dist-info
|
|
|
7ef706 |
rm -rfv *.dist-info/ >&2
|
|
|
7ef706 |
if [ -f %{__python3} ]; then
|
|
|
20b2b6 |
mkdir -p "%{_pyproject_builddir}"
|
|
|
20b2b6 |
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}" TMPDIR="%{_pyproject_builddir}" \\\
|
|
|
20b2b6 |
RPM_TOXENV="%{toxenv}" HOSTNAME="rpmbuild" %{__python3} -Bs %{_rpmconfigdir}/redhat/pyproject_buildrequires.py %{?!_python_no_extras_requires:--generate-extras} --python3_pkgversion %{python3_pkgversion} --wheeldir %{_pyproject_wheeldir} %{?**}
|
|
|
7ef706 |
fi
|
|
|
7ef706 |
}
|
|
|
7ef706 |
|
|
|
7ef706 |
|
|
|
7ef706 |
%tox(e:) %{expand:\\\
|
|
|
7ef706 |
TOX_TESTENV_PASSENV="${TOX_TESTENV_PASSENV:-*}" \\
|
|
|
5d3ed2 |
%{?py3_test_envvars}%{?!py3_test_envvars:PYTHONDONTWRITEBYTECODE=1 \\
|
|
|
7ef706 |
PATH="%{buildroot}%{_bindir}:$PATH" \\
|
|
|
7ef706 |
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}" \\
|
|
|
5d3ed2 |
%{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"}} \\
|
|
|
7ef706 |
HOSTNAME="rpmbuild" \\
|
|
|
7ef706 |
%{__python3} -m tox --current-env -q --recreate -e "%{-e:%{-e*}}%{!-e:%{toxenv}}" %{?*}
|
|
|
7ef706 |
}
|