Skip to content

Commit 2a67457

Browse files
author
Release Manager
committed
gh-38201: Replace uses of `setup.py bdist_wheel` and direct uses of `python3 -m build` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> This is the next step in the modernization of our use of build front ends for Python SPKGs, after #35618. - New `sage-dist-helper` functions `sdh_build_wheel`, `sdh_build_and_store_wheel` (split out from #36730) - New option `--sdist-then-wheel` for `sdh_pip_install` (and the new `sdh_build*wheel` functions) By switching the packages `sagemath_environment` etc. from direct use of `python3 -m build` to the `sdh_build_and_store_wheel` script, it now falls back to `--no-build-isolation` when building with build isolation fails. - This fixes #38190 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #38201 Reported by: Matthias Köppe Reviewer(s):
2 parents b7dd28d + 0878cc2 commit 2a67457

File tree

8 files changed

+26
-58
lines changed

8 files changed

+26
-58
lines changed

build/bin/sage-dist-helpers

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,25 +205,16 @@ sdh_make_install() {
205205
sdh_die "Error installing $PKG_NAME"
206206
}
207207

208-
sdh_setup_bdist_wheel() {
209-
# Issue #32046: Most uses of this function can be replaced by sdh_pip_install
210-
mkdir -p dist
211-
rm -f dist/*.whl
212-
BDIST_DIR="$(mktemp -d)"
213-
python3 setup.py --no-user-cfg \
214-
bdist_wheel --bdist-dir "$BDIST_DIR" \
215-
"$@" || sdh_die "Error building a wheel for $PKG_NAME"
216-
}
217-
218-
sdh_pip_install() {
219-
echo "Installing $PKG_NAME"
208+
sdh_build_wheel() {
220209
mkdir -p dist
221210
rm -f dist/*.whl
222211
export PIP_NO_INDEX=1
223212
install_options=""
224213
build_options=""
225214
# pip has --no-build-isolation but no flag that turns the default back on...
226215
build_isolation_option=""
216+
# build has --wheel but no flag that turns the default (build sdist and then wheel) back on
217+
dist_option="--wheel"
227218
export PIP_FIND_LINKS="$SAGE_SPKG_WHEELS"
228219
unset PIP_NO_BINARY
229220
while [ $# -gt 0 ]; do
@@ -243,6 +234,9 @@ sdh_pip_install() {
243234
export PIP_NO_BINARY=:all:
244235
build_isolation_option="--no-isolation --skip-dependency-check"
245236
;;
237+
--sdist-then-wheel)
238+
dist_option=""
239+
;;
246240
--no-deps)
247241
install_options="$install_options $1"
248242
;;
@@ -258,20 +252,20 @@ sdh_pip_install() {
258252
esac
259253
shift
260254
done
261-
if python3 -m build --wheel --outdir=dist $build_isolation_option $build_options "$@"; then
255+
if python3 -m build $dist_option --outdir=dist $build_isolation_option $build_options "$@"; then
262256
: # successful
263257
else
264258
case $build_isolation_option in
265259
*--no-isolation*)
266260
sdh_die "Error building a wheel for $PKG_NAME"
267261
;;
268262
*)
269-
echo >&2 "Warning: building with \"python3 -m build --wheel --outdir=dist $build_isolation_option $build_options $@\" failed."
263+
echo >&2 "Warning: building with \"python3 -m build $dist_option --outdir=dist $build_isolation_option $build_options $@\" failed."
270264
unset PIP_FIND_LINKS
271265
export PIP_NO_BINARY=:all:
272266
build_isolation_option="--no-isolation --skip-dependency-check"
273-
echo >&2 "Retrying with \"python3 -m build --wheel --outdir=dist $build_isolation_option $build_options $@\"."
274-
if python3 -m build --wheel --outdir=dist $build_isolation_option $build_options "$@"; then
267+
echo >&2 "Retrying with \"python3 -m build $dist_option --outdir=dist $build_isolation_option $build_options $@\"."
268+
if python3 -m build $dist_option --outdir=dist $build_isolation_option $build_options "$@"; then
275269
echo >&2 "Warning: Wheel building needed to use \"$build_isolation_option\" to succeed. This means that a dependencies file in build/pkgs/ needs to be updated. Please report this to sage-devel@googlegroups.com, including the build log of this package."
276270
else
277271
sdh_die "Error building a wheel for $PKG_NAME"
@@ -282,6 +276,16 @@ sdh_pip_install() {
282276
unset PIP_FIND_LINKS
283277
unset PIP_NO_BINARY
284278
unset PIP_NO_INDEX
279+
}
280+
281+
sdh_build_and_store_wheel() {
282+
sdh_build_wheel "$@"
283+
sdh_store_wheel .
284+
}
285+
286+
sdh_pip_install() {
287+
echo "Installing $PKG_NAME"
288+
sdh_build_wheel "$@"
285289
sdh_store_and_pip_install_wheel $install_options .
286290
}
287291

build/pkgs/sage_conf/spkg-install.in

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../sage_setup/spkg-install.in

build/pkgs/sage_docbuild/spkg-install.in

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../sage_setup/spkg-install.in

build/pkgs/sage_setup/spkg-install.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cd src
22
if [ "$SAGE_EDITABLE" = yes ]; then
33
sdh_pip_editable_install .
44
if [ "$SAGE_WHEELS" = yes ]; then
5-
sdh_setup_bdist_wheel && sdh_store_wheel .
5+
sdh_build_and_store_wheel --no-isolation .
66
fi
77
else
88
sdh_pip_install .

build/pkgs/sage_sws2rst/spkg-install.in

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../sage_setup/spkg-install.in

build/pkgs/sagelib/spkg-install.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if [ "$SAGE_EDITABLE" = yes ]; then
5353

5454
if [ "$SAGE_WHEELS" = yes ]; then
5555
# Additionally build a wheel (for use in other venvs)
56-
cd $SAGE_PKGS/sagelib/src && time sdh_setup_bdist_wheel && sdh_store_wheel .
56+
cd $SAGE_PKGS/sagelib/src && time sdh_build_and_store_wheel --no-build-isolation .
5757
fi
5858
else
5959
# Now implied: "$SAGE_WHEELS" = yes

build/pkgs/sagemath_objects/spkg-install.in

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@ export PIP_FIND_LINKS="file://$SAGE_SPKG_WHEELS"
77
# https://pypa-build.readthedocs.io/en/latest/#python--m-build
88
# (Important because sagemath-objects uses MANIFEST.in for filtering.)
99
# Do not install the wheel.
10-
DIST_DIR="$(mktemp -d)"
11-
python3 -m build --outdir "$DIST_DIR"/dist . || sdh_die "Failure building sdist and wheel"
12-
13-
wheel=$(cd "$DIST_DIR" && sdh_store_wheel . >&2 && echo $wheel)
14-
ls -l "$wheel"
10+
sdh_build_and_store_wheel --sdist-then-wheel .

0 commit comments

Comments
 (0)