Skip to content

Commit

Permalink
sagemathgh-36452: make sagemath_categories-check, `make pypi-wheels…
Browse files Browse the repository at this point in the history
…-check`

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

We add `make` targets for testing wheel-building script packages that
have already been installed. For example:
```
$ make SAGE_WHEELS=yes sagemath_categories  # builds and stores (but
does not install) a wheel
$ make sagemath_categories-check            # tests the wheel using tox
```
The target `make pypi-wheels-check` calls all of them. We restructure
the Build & Test CI so that all tests are run after build has been
completed. Later, as a follow up of this and sagemath#36446, we can store the
result of Build as a container image and then parallelize the various
tests on top of it.

This is implemented on top of an improvement of how we record
information on our wheels.
```
$ cat venv/var/lib/sage/scripts/sagemath_categories/spkg-
requirements.txt
sagemath_categories @ file:///Users/mkoeppe/s/sage/sage-
rebasing/worktree-algebraic-2018-spring/local/var/lib/sage/venv-python3.
11/var/lib/sage/wheels/sagemath_categories-10.2b6-cp311-cp311-
macosx_13_0_x86_64.whl
```
Previously, this information was only known during the execution of the
`spkg-install` script.

In a follow-up, we can address sagemath#30956 by delaying the wheel installation
to spkg-postinst.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] 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 accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36452
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee, Matthias Köppe
  • Loading branch information
Release Manager committed Oct 16, 2023
2 parents 7ccc105 + 8224cb0 commit 1d7d954
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 68 deletions.
29 changes: 24 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,19 @@ jobs:
(cd worktree-image && git commit -q -m "current changes" --allow-empty -a && git am; git reset --quiet old; git add -N .) < upstream/ci_fixes.patch
fi
- name: Incremental build, test changed files (sage -t --new)
- name: Incremental build
id: incremental
run: |
# Now re-bootstrap and build. The build is incremental because we were careful with the timestamps.
# We run tests with "sage -t --new"; this only tests the uncommitted changes.
./bootstrap && make build && ./sage -t --new -p2
./bootstrap && make build
working-directory: ./worktree-image
env:
MAKE: make -j2 --output-sync=recurse
SAGE_NUM_THREADS: 2

- name: Build and test modularized distributions
- name: Build modularized distributions
if: always() && steps.worktree.outcome == 'success'
run: make V=0 tox && make pypi-wheels
run: make V=0 tox && make SAGE_CHECK=no pypi-wheels
working-directory: ./worktree-image
env:
MAKE: make -j2 --output-sync=recurse
Expand Down Expand Up @@ -143,6 +142,26 @@ jobs:
MAKE: make -j2 --output-sync=recurse
SAGE_NUM_THREADS: 2

# Testing

- name: Test changed files (sage -t --new)
if: always() && steps.build.outcome == 'success'
run: |
# We run tests with "sage -t --new"; this only tests the uncommitted changes.
./sage -t --new -p2
working-directory: ./worktree-image
env:
MAKE: make -j2 --output-sync=recurse
SAGE_NUM_THREADS: 2

- name: Test modularized distributions
if: always() && steps.build.outcome == 'success'
run: make V=0 tox && make pypi-wheels-check
working-directory: ./worktree-image
env:
MAKE: make -j2 --output-sync=recurse
SAGE_NUM_THREADS: 2

- name: Pytest
if: contains(github.ref, 'pytest')
run: |
Expand Down
15 changes: 9 additions & 6 deletions build/bin/sage-dist-helpers
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,15 @@ sdh_store_wheel() {
mkdir -p "${SAGE_DESTDIR}${SAGE_SPKG_WHEELS}" && \
$sudo mv "$wheel" "${SAGE_DESTDIR}${SAGE_SPKG_WHEELS}/" || \
sdh_die "Error storing $wheel"
wheel="${SAGE_DESTDIR}${SAGE_SPKG_WHEELS}/${wheel##*/}"
wheel="${SAGE_SPKG_WHEELS}/${wheel##*/}"
if [ -n "${SAGE_SPKG_SCRIPTS}" -a -n "${PKG_BASE}" ]; then
wheel_basename="${wheel##*/}"
distname="${wheel_basename%%-*}"
# Record name and wheel file location
mkdir -p ${SAGE_DESTDIR}${SAGE_SPKG_SCRIPTS}/${PKG_BASE}
echo "${distname} @ file://${wheel}" >> ${SAGE_DESTDIR}${SAGE_SPKG_SCRIPTS}/${PKG_BASE}/spkg-requirements.txt
fi
wheel="${SAGE_DESTDIR}${wheel}"
}

sdh_store_and_pip_install_wheel() {
Expand Down Expand Up @@ -373,11 +381,6 @@ sdh_store_and_pip_install_wheel() {
fi
$sudo sage-pip-install $root $pip_options "$wheel" || \
sdh_die "Error installing ${wheel##*/}"
if [ -n "${SAGE_PKG_DIR}" ]; then
# Record name of installed distribution name for uninstallation.
wheel=${wheel##*/}
echo "${wheel%%-*}" >> ${SAGE_PKG_DIR}/spkg-piprm-requirements.txt
fi
}

sdh_pip_uninstall() {
Expand Down
24 changes: 2 additions & 22 deletions build/bin/sage-spkg
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ WRAPPED_SCRIPTS="build install check preinst postinst $INSTALLED_SCRIPTS"

# Prepare script for uninstallation of packages that use sdh_pip_install
# or sdh_store_and_pip_install_wheel.
echo 'sdh_pip_uninstall -r $SAGE_SPKG_SCRIPTS/$PKG_BASE/spkg-piprm-requirements.txt' > spkg-piprm.in
echo 'sdh_pip_uninstall -r $SAGE_SPKG_SCRIPTS/$PKG_BASE/spkg-requirements.txt' > spkg-piprm.in

for script in $WRAPPED_SCRIPTS; do
# 'Installed' scripts are not run immediately out of the package build
Expand All @@ -567,24 +567,6 @@ for script in $WRAPPED_SCRIPTS; do
fi
done


# When there is no spkg-install, assume the "spkg" is a tarball not
# specifically made for Sage. Since we want it to be as easy as
# possible to install such a package, we "guess" spkg-install.
if [ ! -f spkg-install ]; then
echo '#!/usr/bin/env bash' > spkg-install
if [ -x configure ]; then
echo './configure --prefix="$SAGE_INST_LOCAL" && make && $SAGE_SUDO make install' >> spkg-install
elif [ -f setup.py ]; then
echo 'python setup.py install' >> spkg-install
else
echo >&2 "Error: There is no spkg-install script, no setup.py, and no configure"
echo >&2 "script, so I do not know how to install $PKG_SRC."
exit 1
fi
chmod +x spkg-install
fi

echo "****************************************************"
echo "Host system:"
uname -a
Expand Down Expand Up @@ -722,9 +704,7 @@ unset SAGE_DESTDIR_LOCAL
# removed by sage-spkg-uninstall
INSTALLED_SCRIPTS_DEST="$SAGE_SPKG_SCRIPTS/$PKG_BASE"

if [ -f spkg-piprm-requirements.txt ]; then
INSTALLED_SCRIPTS="$INSTALLED_SCRIPTS piprm-requirements.txt"
else
if [ ! -f $INSTALLED_SCRIPTS_DEST/spkg-requirements.txt ]; then
# No packages to uninstall with pip, so remove the prepared uninstall script
rm -f spkg-piprm spkg-piprm.in
fi
Expand Down
30 changes: 29 additions & 1 deletion build/make/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ wheels:
$(MAKE_REC) SAGE_EDITABLE=no SAGE_WHEELS=yes $(WHEEL_PACKAGES)
@echo "Built wheels are in venv/var/lib/sage/wheels/"

pypi-wheels-check: $(PYPI_WHEEL_PACKAGES:%=%-check)

#==============================================================================
# Setting SAGE_CHECK... variables
#==============================================================================
Expand Down Expand Up @@ -724,15 +726,21 @@ $(1)-$(4)-no-deps:
echo "$$($(4)_DISABLED_MESSAGE)" 2>&1; \
exit 1; \
elif [ -x '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install' ]; then \
rm -rf '$$($(4))/var/lib/sage/scripts/$(1)'; \
cd '$$(SAGE_ROOT)/build/pkgs/$(1)' && \
. '$$(SAGE_ROOT)/src/bin/sage-src-env-config' && \
. '$$(SAGE_ROOT)/src/bin/sage-env-config' && \
. '$$(SAGE_ROOT)/src/bin/sage-env' && \
. '$$(SAGE_ROOT)/build/bin/sage-build-env-config' && \
. '$$(SAGE_ROOT)/build/bin/sage-build-env' && \
PKG_BASE="$(1)" \
PKG_VER="$(2)" \
PKG_NAME="$(1)-$(2)" \
SAGE_SPKG_WHEELS=$$($(4))/var/lib/sage/wheels \
SAGE_SPKG_SCRIPTS=$$($(4))/var/lib/sage/scripts \
SAGE_INST_LOCAL=$$($(4)) \
sage-logger -p 'SAGE_CHECK=$$(SAGE_CHECK_$(1)) $$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install' '$$(SAGE_LOGS)/$(1)-$(2).log' && \
SAGE_CHECK=$$(SAGE_CHECK_$(1)) \
sage-logger -p '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install && if [ $$$$SAGE_CHECK != no -a -x $$(SAGE_ROOT)/build/pkgs/$(1)/spkg-check ]; then $$(SAGE_ROOT)/build/pkgs/$(1)/spkg-check; fi' '$$(SAGE_LOGS)/$(1)-$(2).log' && \
rm -f "$$($(4))/$(SPKG_INST_RELDIR)/$(1)"-* && \
touch "$$($(4))/$(SPKG_INST_RELDIR)/$(1)-$(2)"; \
else ( \
Expand All @@ -752,6 +760,26 @@ $(1)-$(4)-no-deps:

$(1)-no-deps: $(1)-$(4)-no-deps

$(1)-$(4)-check:
$(PLUS)@if [ -x $$(SAGE_ROOT)/build/pkgs/$(1)/spkg-check ]; then \
cd '$$(SAGE_ROOT)/build/pkgs/$(1)' && \
. '$$(SAGE_ROOT)/src/bin/sage-src-env-config' && \
. '$$(SAGE_ROOT)/src/bin/sage-env-config' && \
. '$$(SAGE_ROOT)/src/bin/sage-env' && \
. '$$(SAGE_ROOT)/build/bin/sage-build-env-config' && \
. '$$(SAGE_ROOT)/build/bin/sage-build-env' && \
PKG_BASE="$(1)" \
PKG_VER="$(2)" \
PKG_NAME="$(1)-$(2)" \
SAGE_SPKG_WHEELS=$$($(4))/var/lib/sage/wheels \
SAGE_SPKG_SCRIPTS=$$($(4))/var/lib/sage/scripts \
SAGE_INST_LOCAL=$$($(4)) \
SAGE_CHECK=$$(SAGE_CHECK_$(1)) \
sage-logger -p '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-check' '$$(SAGE_LOGS)/$(1)-$(2).log'; \
fi

$(1)-check: $(1)-$(4)-check

$(1)-$(4)-uninstall:
-$(AM_V_at)cd '$$(SAGE_ROOT)/build/pkgs/$(1)' && \
. '$$(SAGE_ROOT)/src/bin/sage-src-env-config' && \
Expand Down
11 changes: 10 additions & 1 deletion build/pkgs/sage_sws2rst/spkg-check
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
#! /bin/sh
cd src && ./check.sh
cd src
./check.sh
if [ $? -ne 0 ]; then
if [ "$SAGE_CHECK" = "warn" ]; then
echo >&2 "Warning: Failures testing package $PKG_NAME (ignored)"
else
echo >&2 "Error testing package $PKG_NAME"
exit 1
fi
fi
10 changes: 0 additions & 10 deletions build/pkgs/sage_sws2rst/spkg-install
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,3 @@ if [ "$SAGE_EDITABLE" = yes ]; then
else
sdh_pip_install .
fi
cd ..
# For type=script packages, spkg-check is not run
case "$SAGE_CHECK" in
yes)
./spkg-check
;;
warn)
./spkg-check || echo >&2 "Warning: Failures testing package sage_sws2rst (ignored)"
;;
esac
1 change: 1 addition & 0 deletions build/pkgs/sagemath_categories/spkg-check
1 change: 1 addition & 0 deletions build/pkgs/sagemath_environment/spkg-check
27 changes: 27 additions & 0 deletions build/pkgs/sagemath_objects/spkg-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
cd src

export PIP_NO_INDEX=true
export PIP_FIND_LINKS="file://$SAGE_SPKG_WHEELS"

export TOX_PARALLEL_NO_SPINNER=1
wheel="$(sed -n '1s,.*@ file://,,p' $SAGE_SPKG_SCRIPTS/$PKG_BASE/spkg-requirements.txt)"
echo Running "tox -r -p auto -v --installpkg $wheel"
tox -r -p auto -v --installpkg "$wheel"
status=$?
case $status:$SAGE_CHECK:$([ -r known-test-failures.json ]; echo $?) in
0:*:0) echo "Passed the test suite (modulo baseline known-test-failures*.json)";;
0:*:*) echo "Passed the test suite";;
*:warn:0) echo "Warning: New failures (not in baseline known-test-failures*.json (ignored)"; status=0;;
*:warn:*) echo "Warning: Failures testing the package (ignored)"; status=0;;
*:yes:0) echo "New failures, not in baseline known-test-failures*.json";;
*:yes:*) echo "Failures testing the package";;
esac
# Show summaries of failures (suppress lines ending with '[failed in baseline]')
for f in $(pwd)/.tox/sagepython-sagewheels-nopypi-norequirements*/log/*-command*.log; do
if [ -r "$f" ]; then
echo "$f"
grep '^sage -t.*#[^]]*$' "$f"
fi
done
exit $status
23 changes: 0 additions & 23 deletions build/pkgs/sagemath_objects/spkg-install
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,3 @@ python3 -m build --outdir "$DIST_DIR"/dist . || sdh_die "Failure building sdist

wheel=$(cd "$DIST_DIR" && sdh_store_wheel . >&2 && echo $wheel)
ls -l "$wheel"

if [ "$SAGE_CHECK" != no ]; then
export TOX_PARALLEL_NO_SPINNER=1
echo Running "tox -r -p auto -v --installpkg $wheel"
tox -r -p auto -v --installpkg $wheel
status=$?
case $status:$SAGE_CHECK:$([ -r known-test-failures.json ]; echo $?) in
0:*:0) echo "Passed the test suite (modulo baseline known-test-failures*.json)";;
0:*:*) echo "Passed the test suite";;
*:warn:0) echo "Warning: New failures (not in baseline known-test-failures*.json (ignored)"; status=0;;
*:warn:*) echo "Warning: Failures testing the package (ignored)"; status=0;;
*:yes:0) echo "New failures, not in baseline known-test-failures*.json";;
*:yes:*) echo "Failures testing the package";;
esac
# Show summaries of failures (suppress lines ending with '[failed in baseline]')
for f in $(pwd)/.tox/sagepython-sagewheels-nopypi-norequirements*/log/*-command*.log; do
if [ -r "$f" ]; then
echo "$f"
grep '^sage -t.*#[^]]*$' "$f"
fi
done
exit $status
fi
1 change: 1 addition & 0 deletions build/pkgs/sagemath_repl/spkg-check

0 comments on commit 1d7d954

Please sign in to comment.