Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions debbuild-macros.spec
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Provides: debbuild-macros-python3
Provides: python-deb-macros
Provides: python2-deb-macros
Provides: python3-deb-macros
# Provides pyproject macros
Provides: debbuild-macros-pyproject
Provides: pyproject-deb-macros
# Provides perl macros
Provides: debbuild-macros-perl
Provides: perl-deb-macros
Expand Down Expand Up @@ -91,6 +94,7 @@ with Debian Policy.
mkdir -p %{buildroot}%{_debconfigdir}
cp -av gpgverify %{buildroot}%{_debconfigdir}
cp -av cmake/cmake-* %{buildroot}%{_debconfigdir}
cp -av pyproject/pyproject-* %{buildroot}%{_debconfigdir}
mkdir -p %{buildroot}%{_debmacrodir}
cp -av macros.* %{buildroot}%{_debmacrodir}

Expand All @@ -103,6 +107,7 @@ rm -fv %{buildroot}%{_debmacrodir}/macros.systemd
%license LICENSE*
%{_debconfigdir}/gpgverify
%{_debconfigdir}/cmake-*
%{_debconfigdir}/pyproject-*
%{_debmacrodir}/macros.*


Expand Down
118 changes: 118 additions & 0 deletions macros.pyproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# SPDX-License-Identifier: MIT

# This is a directory where wheels are stored and installed from, relative to PWD
%_pyproject_wheeldir pyproject-wheeldir

# 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
# See https://github.com/pypa/pip/issues/7555#issuecomment-595180864
#
# This will be used in debugsource package paths (applies to extension modules only)
# NB: pytest collects tests from here if not hidden
# https://docs.pytest.org/en/latest/reference.html#confval-norecursedirs
%_pyproject_builddir .pyproject-builddir

%pyproject_files %{_builddir}/pyproject-files
%pyproject_ghost_distinfo %{_builddir}/pyproject-ghost-distinfo
%pyproject_record %{_builddir}/pyproject-record

%pyproject_wheel() %{expand:\\\
export TMPDIR="${PWD}/%{_pyproject_builddir}"
mkdir -p "${TMPDIR}"
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}" \\\
%{__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:\\\
specifier=$(ls %{_pyproject_wheeldir}/*.whl | xargs basename --multiple | sed -E 's/([^-]+)-([^-]+)-.+\\\.whl/\\\1==\\\2/')
export 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
if [ -d %{buildroot}%{_bindir} ]; then
%py3_shebang_fix %{buildroot}%{_bindir}/*
rm -rfv %{buildroot}%{_bindir}/__pycache__
fi
rm -f %{pyproject_ghost_distinfo}
site_dirs=()
# Process %%{python3_sitelib} if exists
if [ -d %{buildroot}%{python3_sitelib} ]; then
site_dirs+=( "%{python3_sitelib}" )
fi
# Process %%{python3_sitearch} if exists and does not equal to %%{python3_sitelib}
if [ %{buildroot}%{python3_sitearch} != %{buildroot}%{python3_sitelib} ] && [ -d %{buildroot}%{python3_sitearch} ]; then
site_dirs+=( "%{python3_sitearch}" )
fi
# Process all *.dist-info dirs in sitelib/sitearch
for site_dir in ${site_dirs[@]}; do
for distinfo in %{buildroot}$site_dir/*.dist-info; do
echo "%ghost ${distinfo#%{buildroot}}" >> %{pyproject_ghost_distinfo}
sed -i 's/pip/rpm/' ${distinfo}/INSTALLER
PYTHONPATH=%{_rpmconfigdir}/redhat \\
%{__python3} -B %{_rpmconfigdir}/redhat/pyproject_preprocess_record.py \\
--buildroot %{buildroot} --record ${distinfo}/RECORD --output %{pyproject_record}
rm -fv ${distinfo}/RECORD
rm -fv ${distinfo}/REQUESTED
done
done
lines=$(wc -l %{pyproject_ghost_distinfo} | cut -f1 -d" ")
if [ $lines -ne 1 ]; then
echo -e "\\n\\nWARNING: %%%%pyproject_extras_subpkg won't work without explicit -i or -F, found $lines dist-info directories.\\n\\n" >/dev/stderr
rm %{pyproject_ghost_distinfo} # any attempt to use this will fail
fi
}


# 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
%pyproject_extras_subpkg(n:i:f:F) %{expand:%{?python_extras_subpkg:%{python_extras_subpkg%{?!-i:%{?!-f:%{?!-F: -f %{pyproject_ghost_distinfo}}}} %**}}}


%pyproject_save_files() %{expand:\\\
%{__python3} %{_rpmconfigdir}/redhat/pyproject_save_files.py \\
--output "%{pyproject_files}" \\
--buildroot "%{buildroot}" \\
--sitelib "%{python3_sitelib}" \\
--sitearch "%{python3_sitearch}" \\
--python-version "%{python3_version}" \\
--pyproject-record "%{pyproject_record}" \\
%{*}
}


%default_toxenv py%{python3_version_nodots}
%toxenv %{default_toxenv}


%pyproject_buildrequires(rxte:) %{expand:\\\
%{-e:%{expand:%global toxenv %(%{__python3} -s %{_rpmconfigdir}/redhat/pyproject_construct_toxenv.py %{?**})}}
echo 'python%{python3_pkgversion}-devel'
echo 'python%{python3_pkgversion}dist(pip) >= 19'
echo 'python%{python3_pkgversion}dist(packaging)'
if [ -f pyproject.toml ]; then
echo 'python%{python3_pkgversion}dist(toml)'
else
# Note: If the default requirements change, also change them in the script!
echo 'python%{python3_pkgversion}dist(setuptools) >= 40.8'
echo 'python%{python3_pkgversion}dist(wheel)'
fi
# Check if we can generate dependencies on Python extras
if [ "%{py_dist_name []}" == "[]" ]; then
extras_flag=%{?!_python_no_extras_requires:--generate-extras}
else
extras_flag=
fi
# setuptools assumes no pre-existing dist-info
rm -rfv *.dist-info/ >&2
if [ -f %{__python3} ]; then
RPM_TOXENV="%{toxenv}" HOSTNAME="rpmbuild" %{__python3} -s %{_rpmconfigdir}/redhat/pyproject_buildrequires.py $extras_flag --python3_pkgversion %{python3_pkgversion} %{?**}
fi
}


%tox(e:) %{expand:\\\
TOX_TESTENV_PASSENV="${TOX_TESTENV_PASSENV:-*}" \\
PYTHONDONTWRITEBYTECODE=1 \\
PATH="%{buildroot}%{_bindir}:$PATH" \\
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}" \\
HOSTNAME="rpmbuild" \\
%{__python3} -m tox --current-env -q --recreate -e "%{-e:%{-e*}}%{!-e:%{toxenv}}" %{?*}
}
27 changes: 27 additions & 0 deletions pyproject/pyproject-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# Shell wrapper for installing pyproject-based code
# SPDX-License-Identifier: MIT

# Collect arguments
__pyproject_pyinterp="$1"
__pyproject_builddir="$2"
__pyproject_wheeldir="$3"
__pyproject_sitearchdir="$4"
__pyproject_sitelibdir="$5"

specifier=$(ls ${__pyproject_wheeldir}/*.whl | xargs basename --multiple | sed -E 's/([^-]+)-([^-]+)-.+\\\.whl/\\\1==\\\2/')
export TMPDIR="${PWD}/${__pyproject_builddir}"
${__pyproject_pyinterp} -m pip install --root ${RPM_BUILD_ROOT} --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 ${RPM_BUILD_ROOT}/usr/bin ]; then
pathfix.py -pni "%{__python3}" -k -as ${RPM_BUILD_ROOT}/usr/bin/*
rm -rfv ${RPM_BUILD_ROOT}/usr/bin/__pycache__
fi
if [ -d ${RPM_BUILD_ROOT}${__pyproject_sitelibdir} ]; then
sed -i 's/pip/deb/' ${RPM_BUILD_ROOT}${__pyproject_sitelibdir}/*.dist-info/INSTALLER
fi
if [ -d ${RPM_BUILD_ROOT}${__pyproject_sitearchdir} ]; then
sed -i 's/pip/deb/' ${RPM_BUILD_ROOT}${__pyproject_sitearchdir}/*.dist-info/INSTALLER
fi


exit $?
16 changes: 16 additions & 0 deletions pyproject/pyproject-wheel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Shell wrapper for make wheels with pip
# SPDX-License-Identifier: MIT

# Collect arguments
__pyproject_pyinterp="$1"
__pyproject_builddir="$2"
__pyproject_wheeldir="$3"
__build_flags="${@:4}"

export TMPDIR="${PWD}/${__pyproject_builddir}"
mkdir -p "${TMPDIR}"
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}" \
${__pyproject_pyinterp} -m pip wheel --wheel-dir ${__pyproject_wheeldir} --no-deps --use-pep517 --no-build-isolation --disable-pip-version-check --no-clean --progress-bar off --verbose .

exit $?