Skip to content

Commit

Permalink
m4/sage_python_package_check.m4: Replace direct access to version_req…
Browse files Browse the repository at this point in the history
…uirements.txt
  • Loading branch information
Matthias Koeppe committed May 14, 2024
1 parent c2594fb commit 048d891
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
14 changes: 8 additions & 6 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ AS_VAR_SET_IF([SAGE_ENABLE_$pkgname], [], [AS_VAR_SET([SAGE_ENABLE_$pkgname], [y
*:none)
# Issue #31163: Just an optional dummy package
spkg_configures="$spkg_configures
AC_SUBST(SAGE_ENABLE_$pkgname, [if_installed])"
AC_SUBST(SAGE_ENABLE_$pkgname, [if_installed])"
;;
*:*)
spkg_configures="$spkg_configures
Expand All @@ -98,24 +98,26 @@ $config"
$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
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
eval DIR=\$path_$pkgname
Expand Down
6 changes: 4 additions & 2 deletions build/bin/sage-get-system-packages
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ case "$SYSTEM" in
# 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;"
# also normalizes quotes from "" to ''.
STRIP_COMMENTS="sed s/#.*//;/^[[:space:]]*$/d;s/\"/'/g;"
FROM_PYPROJECT_TOML=1
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/$/',/;"
# also normalizes quotes from '' to "".
STRIP_COMMENTS="sed s/#.*//;/^[[:space:]]*$/d;s/'/\"/g;s/^/'/;s/$/',/;"
FROM_PYPROJECT_TOML=1
COLLECT=
;;
Expand Down
28 changes: 8 additions & 20 deletions m4/sage_python_package_check.m4
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,17 @@ AC_DEFUN([SAGE_PYTHON_PACKAGE_CHECK], [
config.venv dnl
2>&AS_MESSAGE_LOG_FD], [
AC_MSG_RESULT(yes)
dnl strip all comments from version_requirements.txt; this should leave
dnl only a single line containing the version specification for this
dnl package. Afterwards, convert all double-quotes to single quotes.
dnl Both work, but only single quotes are documented. However, at the
dnl time of writing, double quotes are more compatible with our toml
dnl generation in ./bootstrap. Converting them from double- to single-
dnl quotes on-the-fly here lets us support both (in this macro, at
dnl least).
SAGE_PKG_VERSPEC=$(sed \
-e '/^#/d' \
-e "s/\"/'/g" \
"./build/pkgs/$1/version_requirements.txt"
)
AC_MSG_CHECKING([for python package $1 ("${SAGE_PKG_VERSPEC}")])
dnl SAGE_PKG_VERSPEC is in the format of a toml list, but
dnl without surrounding brackets, of single-quoted strings,
dnl with any double-quotes escaped by backslash.
AS_VAR_SET([SAGE_PKG_VERSPEC], ["SPKG_INSTALL_REQUIRES_]$1["])
AC_MSG_CHECKING([for python package $1 (${SAGE_PKG_VERSPEC%,})])
WITH_SAGE_PYTHONUSERBASE([dnl
dnl double-quote SAGE_PKG_VERSPEC because platform-specific
dnl dependencies like python_version<'3.11' will have single
dnl quotes in them. (We normalized the quotes earlier with sed.)
AS_IF(
[config.venv/bin/python3 -c dnl
"import pkg_resources; dnl
pkg_resources.require(\"${SAGE_PKG_VERSPEC}\".splitlines())" dnl
[config.venv/bin/python3 -c dnl
"import pkg_resources; dnl
pkg_resources.require((${SAGE_PKG_VERSPEC}))" dnl
2>&AS_MESSAGE_LOG_FD],
[AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no); sage_spkg_install_$1=yes]
Expand Down

0 comments on commit 048d891

Please sign in to comment.