Skip to content

Commit 18abd75

Browse files
author
Release Manager
committed
Trac #32698: Fix up builds without system python3 after #32442
URL: https://trac.sagemath.org/32698 Reported by: mkoeppe Ticket author(s): Matthias Koeppe Reviewer(s): John Palmieri
2 parents e866070 + 3bbc5d8 commit 18abd75

File tree

7 files changed

+71
-8
lines changed

7 files changed

+71
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ src/*.egg-info/
182182
/src/bin/sage-src-env-config
183183

184184
# Virtual environments
185+
/venv
185186
src/.env
186187
src/.venv
187188
src/env/

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ distclean: build-clean
109109
@echo "Deleting all remaining output from build system ..."
110110
rm -rf local
111111
rm -f src/bin/sage-env-config
112+
rm -f prefix venv
112113

113114
# Delete all auto-generated files which are distributed as part of the
114115
# source tarball

build/make/Makefile.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,10 @@ $(1)-$(4)-no-deps:
535535
$(1)-no-deps: $(1)-$(4)-no-deps
536536

537537
$(1)-$(4)-clean:
538-
sage-spkg-uninstall $(if $(filter $(1),$(TOOLCHAIN_DEPS)),--keep-files) \
539-
$(1) '$$($(4))'
538+
if [ -d '$$($(4))' ]; then \
539+
sage-spkg-uninstall $(if $(filter $(1),$(TOOLCHAIN_DEPS)),--keep-files) \
540+
$(1) '$$($(4))'; \
541+
fi
540542

541543
$(1)-clean: $(1)-$(4)-clean
542544

build/pkgs/python3/spkg-build.in

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,24 @@ sdh_configure --enable-shared $PYTHON_CONFIGURE
8484
# Make sure -L. is placed before -L$SAGE_LOCAL/lib so that python and extension
8585
# modules are linked with the right libpython; we pass this in at make time
8686
# only, since we don't want -L. to be saved as one of the default LDFLAGS
87-
# used for building third-party extension modules
88-
sdh_make LDFLAGS="-L. $LDFLAGS"
87+
# used for building third-party extension modules.
88+
#
89+
# Trac #32442: As we now install python in SAGE_VENV, not SAGE_LOCAL,
90+
# we need to provide paths into $SAGE_LOCAL, so that setup.py finds
91+
# the libraries needed for the extension modules - in particular sqlite3.
92+
# (The search code there does not know about CPATH and LIBRARY_PATH.)
93+
make_LDFLAGS="-L. -L$SAGE_LOCAL/lib $LDFLAGS"
94+
make_CPPFLAGS="-I$SAGE_LOCAL/include $CPPFLAGS"
95+
96+
# Also, we need to add an rpath, like we do for SAGE_LOCAL in src/bin/sage-env.
97+
# SAGE_INST_LOCAL is the installation hierarchy for the current package
98+
# -- for python3, this is SAGE_VENV.
99+
make_LDFLAGS="-Wl,-rpath,$SAGE_INST_LOCAL/lib $make_LDFLAGS"
100+
if [ "$UNAME" = "Linux" ]; then
101+
make_LDFLAGS="-Wl,-rpath-link,$SAGE_INST_LOCAL/lib $make_LDFLAGS"
102+
fi
103+
104+
sdh_make LDFLAGS="$make_LDFLAGS" CPPFLAGS="$make_CPPFLAGS"
89105

90106
if [ "$UNAME" = "Darwin" ]; then
91107
export DYLD_LIBRARY_PATH="."

build/pkgs/python3/spkg-configure.m4

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ To build Sage with a different system python, use ./configure --with-python=/pat
119119
])
120120
AC_SUBST([PYTHON_FOR_VENV])
121121
122+
AS_VAR_IF([SAGE_VENV], [auto], [SAGE_VENV=$SAGE_VENV_AUTO])
123+
AS_CASE([$SAGE_VENV],
124+
[no], [SAGE_VENV='${SAGE_LOCAL}'],dnl Quoted so that it is resolved at build time by shell/Makefile
125+
[yes], [AS_IF([test -n "$PYTHON_FOR_VENV"], [
126+
PYTHON_VERSION=$("$PYTHON_FOR_VENV" -c "import sysconfig; print(sysconfig.get_python_version())")
127+
], [
128+
PYTHON_VERSION=$(echo $(cat build/pkgs/python3/package-version.txt))
129+
])
130+
SAGE_VENV='${SAGE_LOCAL}'/var/lib/sage/venv-python$PYTHON_VERSION]
131+
)
132+
122133
dnl These temporary directories are created by the check above
123134
dnl and need to be cleaned up to prevent the "rm -f conftest*"
124135
dnl (that a bunch of other checks do) from emitting warnings about

configure.ac

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,24 @@ SAGE_LOCAL="$prefix"
7070
# This is nonstandard.
7171
if test "$SAGE_LOCAL" = NONE; then
7272
SAGE_LOCAL=local
73+
if test -x "$SAGE_LOCAL"/bin/python3; then
74+
# Incremental build with an existing installation of python3 spkg
75+
# in SAGE_LOCAL or venv in SAGE_LOCAL. Keep old behavior.
76+
SAGE_VENV_AUTO=no
77+
else
78+
SAGE_VENV_AUTO=yes
79+
fi
80+
else
81+
SAGE_VENV_AUTO=no
7382
fi
7483
SAGE_SRC="$SAGE_ROOT/src"
7584
SAGE_SPKG_INST="$SAGE_LOCAL/var/lib/sage/installed"
7685

7786
AC_ARG_WITH([sage-venv],
78-
[AS_HELP_STRING([--with-sage-venv=SAGE_VENV],
87+
[AS_HELP_STRING([--with-sage-venv={auto (default),yes,no,SAGE_VENV}],
7988
[put Python packages into an installation hierarchy separate from prefix])],
8089
[SAGE_VENV="$withval"],
81-
[SAGE_VENV='${SAGE_LOCAL}'])dnl Quoted so that it is resolved at build time by shell/Makefile
90+
[SAGE_VENV="auto"])
8291
AC_SUBST([SAGE_VENV])
8392

8493
#---------------------------------------------------------
@@ -493,6 +502,29 @@ AC_CONFIG_COMMANDS(mkdirs,
493502
SAGE_INST="$SAGE_SPKG_INST"
494503
])
495504

505+
AC_CONFIG_COMMANDS(links, [
506+
dnl Create links for the convenience of users
507+
SYMLINK="${ac_top_build_prefix}prefix"
508+
AS_IF([test -L "$SYMLINK" -o ! -e "$SYMLINK"], [
509+
AC_MSG_NOTICE([creating convenience symlink $SYMLINK -> $SAGE_LOCAL])
510+
rm -f "$SYMLINK"
511+
ln -sf "$SAGE_LOCAL" "$SYMLINK"
512+
], [
513+
AC_MSG_NOTICE([cannot create convenience symlink $SYMLINK -> $SAGE_LOCAL because the file exists and is not a symlink; this is harmless])
514+
])
515+
SYMLINK="${ac_top_build_prefix}venv"
516+
AS_IF([test -L "$SYMLINK" -o ! -e "$SYMLINK"], [
517+
AC_MSG_NOTICE([creating convenience symlink $SYMLINK -> $SAGE_VENV])
518+
rm -f "$SYMLINK"
519+
ln -sf "$SAGE_VENV" "$SYMLINK"
520+
], [
521+
AC_MSG_NOTICE([cannot create convenience symlink $SYMLINK -> $SAGE_VENV because the file exists and is not a symlink; this is harmless])
522+
])
523+
], [
524+
SAGE_LOCAL="$SAGE_LOCAL"
525+
eval SAGE_VENV="$SAGE_VENV"dnl eval so as to evaluate the embedded ${SAGE_LOCAL}
526+
])
527+
496528
AC_OUTPUT()
497529

498530
SAGE_SYSTEM_PACKAGE_NOTICE()

m4/sage_spkg_collect.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ for DIR in $SAGE_ROOT/build/pkgs/*; do
182182
dnl Jupyter notebook, then packages such as jupyter_core would have to be installed into
183183
dnl two trees.
184184
SPKG_TREE_VAR=SAGE_LOCAL
185-
if test -f "$DIR/requirements.txt" -o -f "$DIR/install-requires.txt"; then
186-
dnl A Python package
185+
if test -f "$DIR/requirements.txt" -o -f "$DIR/install-requires.txt" -o "$SPKG_NAME" = python3; then
186+
dnl A Python package or spkg installation of python3 itself
187187
SPKG_TREE_VAR=SAGE_VENV
188188
fi
189189
SAGE_PACKAGE_TREES="${SAGE_PACKAGE_TREES}$(printf '\ntrees_')${SPKG_NAME} = ${SPKG_TREE_VAR}"

0 commit comments

Comments
 (0)