Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor bootstrap, bootstrap-conda, m4/sage_spkg_collect.m4, sage-spkg-info through sage --package properties, sage-get-system-packages #37430

Merged
merged 17 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
113 changes: 48 additions & 65 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ cd "$SAGE_ROOT"

export PATH="$SAGE_ROOT/build/bin:$PATH"

PKG=build/pkgs/configure
MAKE="${MAKE:-make}"
CONFVERSION=$(cat $PKG/package-version.txt)


bootstrap () {
Expand All @@ -54,6 +52,7 @@ bootstrap () {
for a in m4/sage_spkg_versions.m4 m4/sage_spkg_versions_toml.m4; do
echo 'changequote(`>>>'"'"', `<<<'"')dnl" >> $a
done
eval $(sage-package properties --format=shell :all:)
spkg_configures=""
# initialize SAGE_ENABLE... options for standard packages
for pkgname in $(sage-package list :standard:); do
Expand All @@ -62,75 +61,67 @@ AS_VAR_SET_IF([SAGE_ENABLE_$pkgname], [], [AS_VAR_SET([SAGE_ENABLE_$pkgname], [y
done
# --enable-SPKG options
for pkgname in $(sage-package list :optional: :experimental:); do
eval DIR=\$path_$pkgname pkgtype=\$type_$pkgname pkgsource=\$source_$pkgname
case "$pkgname:$pkgsource" in
*:pip)
# Issue #29629: Temporary solution for Sage 9.1: Do not provide
# --enable-SPKG options for installing pip packages
if [ ! -f build/pkgs/$pkgname/requirements.txt ]; then
pkgtype="$(cat build/pkgs/$pkgname/type)"
# Issue #29124: Do not provide --enable-_recommended and similar
case "$pkgname" in
_*) ;;
*) spkg_configures="$spkg_configures
;;
_*:*)
# Issue #29124: Do not provide --enable-_recommended and similar
;;
*:none)
# Issue #31163: Just an optional dummy package
spkg_configures="$spkg_configures
AC_SUBST(SAGE_ENABLE_$pkgname, [if_installed])"
if [ -f build/pkgs/$pkgname/spkg-install -o -f build/pkgs/$pkgname/spkg-install.in ]; then
# Issue #31163: Not just an optional dummy package
spkg_configures="$spkg_configures
SAGE_SPKG_ENABLE([$pkgname], [$pkgtype], [$(grep -v ^= build/pkgs/$pkgname/SPKG.rst | head -n1 2>/dev/null || echo $pkgname)])"
fi
;;
esac
fi
;;
*:*)
spkg_configures="$spkg_configures
AC_SUBST(SAGE_ENABLE_$pkgname, [if_installed])"
spkg_configures="$spkg_configures
SAGE_SPKG_ENABLE([$pkgname], [$pkgtype], [$(grep -v ^= "$DIR/SPKG.rst" | head -n1 2>/dev/null || echo $pkgname)])"
;;
esac
done
cat >> m4/sage_spkg_configures.m4 <<EOF
SAGE_SPKG_COLLECT_INIT([$(echo $(sage-package list))])
EOF
for pkgname in $(sage-package list --has-file spkg-configure.m4); do
echo "m4_sinclude([build/pkgs/$pkgname/spkg-configure.m4])"
eval DIR=\$path_$pkgname
echo "m4_sinclude([$DIR/spkg-configure.m4])"
config="SAGE_SPKG_CONFIGURE_$(echo ${pkgname} | tr '[a-z]' '[A-Z]')"
if grep -q SAGE_PYTHON_PACKAGE_CHECK build/pkgs/$pkgname/spkg-configure.m4; then
if grep -q SAGE_PYTHON_PACKAGE_CHECK "$DIR/spkg-configure.m4"; then
spkg_configures_python="$spkg_configures_python
$config"
else
spkg_configures="$spkg_configures
$config"
fi
done >> m4/sage_spkg_configures.m4
cat >> m4/sage_spkg_configures.m4 <<EOF
$spkg_configures
$spkg_configures_python
EOF
for pkgname in $(sage-package list); do
DIR=build/pkgs/$pkgname
pkgtype="$(cat $DIR/type)"
if test -f "$DIR/requirements.txt"; then
SPKG_SOURCE=pip
elif test ! -f "$DIR/checksums.ini"; then
if test -f "$DIR/spkg-install" -o -f "$DIR/spkg-install.in"; then
SPKG_SOURCE=script
else
# a dummy package
SPKG_SOURCE=none
fi
else
SPKG_SOURCE=normal
fi
if test -f "$DIR/trees.txt"; then
SPKG_TREE_VAR="$(sed "s/#.*//;" "$DIR/trees.txt")"
else
SPKG_TREE_VAR=SAGE_LOCAL
if test -f "$DIR/requirements.txt" -o -f "$DIR/version_requirements.txt"; then
# A Python package
SPKG_TREE_VAR=SAGE_VENV
echo "define(>>>SPKG_INSTALL_REQUIRES_${pkgname}<<<, >>>$(echo $(sage-get-system-packages install-requires ${pkgname}))<<<)dnl" >> m4/sage_spkg_versions.m4
echo "define(>>>SPKG_INSTALL_REQUIRES_${pkgname}<<<, >>>$(echo $(sage-get-system-packages install-requires-toml ${pkgname}))<<<)dnl" >> m4/sage_spkg_versions_toml.m4
fi
eval DIR=\$path_$pkgname pkgtype=\$type_$pkgname SPKG_SOURCE=\$source_$pkgname SPKG_TREE_VAR=\$trees_$pkgname
if test -f "$DIR/requirements.txt" -o -f "$DIR/version_requirements.txt"; then
# A Python package
echo "define(>>>SPKG_INSTALL_REQUIRES_${pkgname}<<<, >>>$(echo $(sage-get-system-packages install-requires ${pkgname}))<<<)dnl" >> m4/sage_spkg_versions.m4
INSTALL_REQUIRES_TOML=
echo "define(>>>SPKG_INSTALL_REQUIRES_${pkgname}<<<, >>>$(echo $(sage-get-system-packages install-requires-toml ${pkgname}))<<<)dnl" >> m4/sage_spkg_versions_toml.m4
echo "m4_define([SPKG_INSTALL_REQUIRES_${pkgname}], [[$(echo $(sage-get-system-packages install-requires-toml ${pkgname} | sed 's/"/\\"/g'))]])dnl" >> m4/sage_spkg_configures.m4
fi
spkg_finalizes="$spkg_finalizes
SAGE_SPKG_FINALIZE([$pkgname], [$pkgtype], [$SPKG_SOURCE], [$SPKG_TREE_VAR])"
done
echo "$spkg_finalizes" >> m4/sage_spkg_configures.m4
for a in m4/sage_spkg_versions.m4 m4/sage_spkg_versions_toml.m4; do
echo 'changequote(>>>`<<<, >>>'"'"'<<<)dnl' >> $a
done
cat >> m4/sage_spkg_configures.m4 <<EOF
$spkg_configures
$spkg_configures_python
$spkg_finalizes
EOF

for pkgname in $(sage-package list --has-file bootstrap "$@"); do
(cd build/pkgs/$pkgname && if [ -x bootstrap ]; then ./bootstrap; else echo >&2 "bootstrap:$LINENO: Nothing to do for $pkgname"; fi) || exit 1
eval DIR=\$path_$pkgname
(cd "$DIR" && if [ -x bootstrap ]; then ./bootstrap; else echo >&2 "bootstrap:$LINENO: Nothing to do for $pkgname"; fi) || exit 1
done

if [ $# != 0 ]; then
Expand Down Expand Up @@ -196,10 +187,10 @@ SAGE_SPKG_FINALIZE([$pkgname], [$pkgtype], [$SPKG_SOURCE], [$SPKG_TREE_VAR])"
bootstrap_download () {
SAGE_DL_LOGLEVEL=""
[ "${BOOTSTRAP_QUIET}" = "yes" ] && SAGE_DL_LOGLEVEL="--log=WARNING"
sage-download-file ${SAGE_DL_LOGLEVEL} configure-$CONFVERSION.tar.gz

CONFBALL=$(sage-package download $SAGE_DL_LOGLEVEL configure)
if [ $? -ne 0 ]; then
echo >&2 "Error: downloading configure-$CONFVERSION.tar.gz failed"
echo >&2 "Error: downloading configure tarball failed"
exit 1
fi

Expand Down Expand Up @@ -255,16 +246,8 @@ save () {
build/pkgs/setuptools/version_requirements.txt \
build/pkgs/wheel/version_requirements.txt

# Update version
echo "$NEWCONFVERSION" >$PKG/package-version.txt

# Compute checksum
if [ "${BOOTSTRAP_QUIET}" = "no" ]; then
sage-package fix-checksum configure
else
# Hide the "Updating checksum..." message
sage-package fix-checksum configure > /dev/null
fi
# Update version; this re-computes the checksum
sage-package update configure "$NEWCONFVERSION"
}


Expand Down Expand Up @@ -304,7 +287,6 @@ do
done
shift $(($OPTIND - 1))
export BOOTSTRAP_QUIET
CONFBALL="upstream/configure-$CONFVERSION.tar.gz"

if [ $DOWNLOAD$SAVE = yesyes ]; then
echo >&2 "$0: refusing to download and save."
Expand All @@ -331,15 +313,16 @@ mkdir -p config 2>/dev/null

if [ $ALWAYSDOWNLOAD = yes ]; then
if [ -n "$CONFTARBALL_URL" ]; then
URL="$CONFTARBALL_URL"/configure-$CONFVERSION.tar.gz
CONFTARBALL=$(sage-package tarball configure)
URL="$CONFTARBALL_URL"/"$CONFTARBALL"
SAGE_DL_LOGLEVEL=""
[ "${BOOTSTRAP_QUIET}" = "yes" ] && SAGE_DL_LOGLEVEL="--log=WARNING"
sage-download-file ${SAGE_DL_LOGLEVEL} "$URL" upstream/configure-$CONFVERSION.tar.gz
sage-download-file ${SAGE_DL_LOGLEVEL} "$URL" upstream/"$CONFTARBALL"
if [ $? -ne 0 ]; then
echo >&2 "Error: downloading configure-$CONFVERSION.tar.gz from $CONFTARBALL_URL failed"
echo >&2 "Error: downloading $CONFTARBALL from $CONFTARBALL_URL failed"
exit 1
fi
echo >&2 "Downloaded configure-$CONFVERSION.tar.gz from $CONFTARBALL_URL "
echo >&2 "Downloaded $CONFTARBALL from $CONFTARBALL_URL "
else
bootstrap_download || exit $?
fi
Expand Down
8 changes: 4 additions & 4 deletions bootstrap-conda
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ SAGELIB_PACKAGES=
SAGELIB_OPTIONAL_PACKAGES=
DEVELOP_PACKAGES=

eval $(sage-package properties --format=shell :all:)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to tie bootstrap conda even closer to the sage-the-distribution scripts. Please revert the changes in the bootstrap-conda file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nonsense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkoeppe could you elaborate why this is "nonsense" from your point of view?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR replaces direct access to the files in build/pkgs (an implementation detail of the sage-bootstrap package) by access through a script of the sage-bootstrap package. Such refactoring does not "tie bootstrap closer to sage-the-distribution scripts".


for PKG_BASE in $(sage-package list --has-file distros/conda.txt --exclude _sagemath); do
PKG_SCRIPTS=build/pkgs/$PKG_BASE
eval PKG_SCRIPTS=\$path_$PKG_BASE PKG_TYPE=\$type_$PKG_BASE
SYSTEM_PACKAGES_FILE=$PKG_SCRIPTS/distros/conda.txt
PKG_TYPE=$(cat $PKG_SCRIPTS/type)
PKG_SYSTEM_PACKAGES=$(echo $(${STRIP_COMMENTS} $SYSTEM_PACKAGES_FILE))
if [ -n "$PKG_SYSTEM_PACKAGES" ]; then
if [ -f $PKG_SCRIPTS/spkg-configure.m4 ]; then
Expand Down Expand Up @@ -133,12 +134,11 @@ echo >&2 $0:$LINENO: generate conda environment files
echo >&4 " - pip:"
echo >&5 " - pip:"
for PKG_BASE in $(sage-package list :standard: :optional: --has-file requirements.txt --no-file distros/conda.txt --no-file src; sage-package list :standard: :optional: --has-file version_requirements.txt --no-file requirements.txt --no-file distros/conda.txt --no-file src); do
PKG_SCRIPTS=build/pkgs/$PKG_BASE
eval PKG_SCRIPTS=\$path_$PKG_BASE PKG_TYPE=\$type_$PKG_BASE
SYSTEM_PACKAGES_FILE=$PKG_SCRIPTS/requirements.txt
if [ ! -f $SYSTEM_PACKAGES_FILE ]; then
SYSTEM_PACKAGES_FILE=$PKG_SCRIPTS/version_requirements.txt
fi
PKG_TYPE=$(cat $PKG_SCRIPTS/type)
if grep -q SAGERUNTIME $PKG_SCRIPTS/dependencies $PKG_SCRIPTS/dependencies_order_only 2>/dev/null; then
: # cannot install packages that depend on the Sage library
else
Expand Down
82 changes: 51 additions & 31 deletions build/bin/sage-get-system-packages
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,40 @@ fi
case "$SYSTEM" in
install-requires)
# Collect from src/pyproject.toml or from version_requirements.txt (falling back to requirements.txt) and output it in the format
# needed by setup.cfg [options] version_requirements=
SYSTEM_PACKAGES_FILE_NAMES="version_requirements.txt requirements.txt"
STRIP_COMMENTS="sed s/#.*//;/^[[:space:]]*$/d;"
FROM_PYPROJECT_TOML=1
# needed by setup.cfg [options] install_requires=
SYSTEM_PACKAGES_FILE_NAMES="src/pyproject.toml version_requirements.txt requirements.txt"
# also normalizes quotes from "" to ''.
STRIP_COMMENTS="sed s/#.*//;/^[[:space:]]*$/d;s/\"/'/g;"
COLLECT=
;;
install-requires-toml)
# Collect from src/pyproject.toml or from version_requirements.txt (falling back to requirements.txt) and output it in the format
# needed by pyproject.toml [build-system] requires=
SYSTEM_PACKAGES_FILE_NAMES="version_requirements.txt requirements.txt"
STRIP_COMMENTS="sed s/#.*//;/^[[:space:]]*$/d;s/^/'/;s/$/',/;"
FROM_PYPROJECT_TOML=1
SYSTEM_PACKAGES_FILE_NAMES="src/pyproject.toml version_requirements.txt requirements.txt"
# also normalizes quotes from '' to "".
STRIP_COMMENTS="sed s/#.*//;/^[[:space:]]*$/d;s/'/\"/g;s/^/'/;s/$/',/;"
COLLECT=
;;
pip)
SYSTEM_PACKAGES_FILE_NAMES="requirements.txt version_requirements.txt"
SYSTEM_PACKAGES_FILE_NAMES="requirements.txt src/pyproject.toml version_requirements.txt"
STRIP_COMMENTS='sed s/#.*//;s/[[:space:]]//g;'
FROM_PYPROJECT_TOML=1
COLLECT=echo
;;
versions)
# For use in sage-spkg-info
SYSTEM_PACKAGES_FILE_NAMES="package-version.txt requirements.txt src/pyproject.toml version_requirements.txt"
strip_comments () {
TEXT=$(sed "s/#.*//;/^[[:space:]]*$/d;s/\"/'/g;s/^/ /;" "$@")
if [ -n "$(echo $TEXT)" ]; then
echo "$NAME::"
echo
echo "$TEXT"
echo
fi
}
STRIP_COMMENTS=strip_comments
COLLECT=
;;
*)
if [ "$SYSTEM" = auto ]; then
SYSTEM=$(sage-guess-package-system 2>/dev/null)
Expand All @@ -45,7 +59,6 @@ case "$SYSTEM" in
fi
SYSTEM_PACKAGES_FILE_NAMES="distros/$SYSTEM.txt"
STRIP_COMMENTS="sed s/#.*//;s/\${PYTHON_MINOR}/${PYTHON_MINOR}/g"
FROM_PYPROJECT_TOML=0
COLLECT=echo
;;
esac
Expand All @@ -57,19 +70,10 @@ case "$SPKGS" in
esac

for PKG_BASE in $SPKGS; do
if [ $FROM_PYPROJECT_TOML -eq 1 ]; then
if [ -f "$SAGE_ROOT/src/pyproject.toml" ]; then
# Extract from the "requires" block in src/pyproject.toml
# Packages are in the format "'sage-conf ~= 10.3b3',"
PACKAGE_INFO=$(sed -n '/requires *= *\[/,/^\]/s/^ *'\''\('$PKG_BASE'.*\)'\'',/\1/p' "$SAGE_ROOT/src/pyproject.toml")
if [ -n "$PACKAGE_INFO" ]; then
echo "$PACKAGE_INFO" | ${STRIP_COMMENTS}
continue
fi
fi
fi

case "$SYSTEM:$ENABLE_SYSTEM_SITE_PACKAGES" in
versions*)
# Show everything.
;;
install-requires*|pip*)
# This is output for installation of packages into a Python environment.
# So it's OK to use any Python packages.
Expand All @@ -93,14 +97,30 @@ for PKG_BASE in $SPKGS; do
esac

for NAME in $SYSTEM_PACKAGES_FILE_NAMES; do
SYSTEM_PACKAGES_FILE="$SAGE_ROOT"/build/pkgs/$PKG_BASE/$NAME
if [ -f $SYSTEM_PACKAGES_FILE ]; then
if [ -z "$COLLECT" ]; then
${STRIP_COMMENTS} $SYSTEM_PACKAGES_FILE
else
$COLLECT $(${STRIP_COMMENTS} $SYSTEM_PACKAGES_FILE)
fi
break
fi
case $NAME in
*pyproject.toml)
SYSTEM_PACKAGES_FILE="$SAGE_ROOT"/$NAME
if [ -f "$SYSTEM_PACKAGES_FILE" ]; then
# Extract from the "requires" block in src/pyproject.toml
# Packages are in the format "'sage-conf ~= 10.3b3',"
PACKAGE_INFO=$(sed -n '/requires *= *\[/,/^\]/s/^ *'\''\('$PKG_BASE'.*\)'\'',/\1/p' "$SAGE_ROOT/src/pyproject.toml")
if [ -n "$PACKAGE_INFO" ]; then
echo "$PACKAGE_INFO" | ${STRIP_COMMENTS}
[ $SYSTEM = versions ] || break
fi
fi
;;
*)
SYSTEM_PACKAGES_FILE="$SAGE_ROOT"/build/pkgs/$PKG_BASE/$NAME
if [ -f $SYSTEM_PACKAGES_FILE ]; then
if [ -z "$COLLECT" ]; then
${STRIP_COMMENTS} $SYSTEM_PACKAGES_FILE
else
$COLLECT $(${STRIP_COMMENTS} $SYSTEM_PACKAGES_FILE)
fi
[ $SYSTEM = versions ] || break
fi
;;
esac
done
done
9 changes: 1 addition & 8 deletions build/bin/sage-spkg-info
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ echo
echo "Version Information"
echo "-------------------"
echo
for a in package-version.txt requirements.txt version_requirements.txt; do
if [ -f "$PKG_SCRIPTS"/"$a" ]; then
echo "$a::"
echo
sed 's/^/ /' "$PKG_SCRIPTS/$a"
echo
fi
done
sage-get-system-packages versions $PKG_BASE
echo
echo "Equivalent System Packages"
echo "--------------------------"
Expand Down
Loading
Loading