Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
3-manifolds
GitHub Repository: 3-manifolds/Sage_macOS
Path: blob/main/Sage_framework/build_sage_framework.sh
170 views
1
BASE_DIR=`pwd`
2
VERSION=`../bin/get_sage_version`
3
SAGE_SYMLINK="/var/tmp/sage-$VERSION-current"
4
PYTHON_LONG_VERSION=`readlink repo/sage/venv | cut -f2 -d '-' | sed s/python//`
5
PYTHON_VERSION=`echo ${PYTHON_LONG_VERSION} | cut -f 1,2 -d'.'`
6
PY_VRSN=`echo ${PYTHON_VERSION} | sed 's/\\.//g'`
7
echo Building framework for SageMath ${VERSION} using Python ${PYTHON_LONG_VERSION}
8
TKINTER_LIB=_tkinter.cpython-${PY_VRSN}-darwin.so
9
REPO=${BASE_DIR}/repo/sage
10
FILES=${BASE_DIR}/files
11
BUILD=${BASE_DIR}/build
12
VERSION_DIR=${BUILD}/Sage.framework/Versions/${VERSION}
13
CURRENT_DIR=${BUILD}/Sage.framework/Versions/Current
14
RESOURCE_DIR=${VERSION_DIR}/Resources
15
VENV_DIR="local/var/lib/sage/venv-python${PYTHON_LONG_VERSION}"
16
VENV_PYLIB="${VENV_DIR}/lib/python${PYTHON_VERSION}"
17
VENV_KERNEL_DIR=${VERSION_DIR}/"${VENV_DIR}/share/jupyter/kernels"
18
NBEXTENSIONS="${VERSION_DIR}/${VENV_DIR}/share/jupyter/nbextensions"
19
THREEJS_SAGE="${NBEXTENSIONS}/threejs-sage"
20
INPUT_HOOKS=${VERSION_DIR}/${VENV_PYLIB}/site-packages/IPython/terminal/pt_inputhooks
21
22
# This allows Sage.framework to be a symlink to the framework inside the application.
23
if ! [ -d "${BUILD}/Sage.framework" ]; then
24
mkdir -p "${BUILD}"/Sage.framework
25
fi
26
27
# Clean out everything.
28
echo Removing old framework ...
29
rm -rf "${BUILD}"/Sage.framework/*
30
31
# Create the bundle directories
32
mkdir -p "${RESOURCE_DIR}"
33
ln -s ${VERSION} "${CURRENT_DIR}"
34
ln -s Versions/Current/Resources "${BUILD}"/Sage.framework/Resources
35
ln -s ${VENV_DIR} ${VERSION_DIR}/venv
36
37
# Create the resource files
38
cp "${REPO}"/{COPYING.txt,README.md,VERSION.txt} "${RESOURCE_DIR}"
39
sed "s/__VERSION__/${VERSION}/g" "${FILES}"/Info.plist > "${RESOURCE_DIR}"/Info.plist
40
cp ${FILES}/pip.conf ${RESOURCE_DIR}
41
mkdir -p ${VERSION_DIR}/local/{bin,include,lib,etc,libexec}
42
echo "Copying files ..."
43
cp -R "${REPO}"/local/bin/ ${VERSION_DIR}/local/bin
44
cp -R "${REPO}"/local/include/ ${VERSION_DIR}/local/include
45
cp -R "${REPO}"/local/lib/ ${VERSION_DIR}/local/lib
46
cp -R "${REPO}"/local/etc/ ${VERSION_DIR}/local/etc
47
cp -R "${REPO}"/local/libexec/ ${VERSION_DIR}/local/libexec
48
ln -s lib "${VERSION_DIR}"/local/lib64
49
mkdir -p ${VERSION_DIR}/local/var/lib/sage/{installed,scripts}
50
mkdir -p ${VERSION_DIR}/${VENV_DIR}/etc
51
cp -R "${REPO}"/local/var/lib/sage/installed/ ${VERSION_DIR}/local/var/lib/sage/installed
52
cp -R "${REPO}"/local/var/lib/sage/scripts/ ${VERSION_DIR}/local/var/lib/sage/scripts
53
cp -R "${REPO}"/${VENV_DIR}/{bin,lib,include,share} ${VERSION_DIR}/${VENV_DIR}
54
cp -R "${REPO}"/${VENV_DIR}/etc/jupyter ${VERSION_DIR}/${VENV_DIR}/etc
55
56
# Copy the useful parts of local/share
57
rm -rf ${VERSION_DIR}/${VENV_DIR}/share/{doc,man}
58
mkdir -p ${VERSION_DIR}/local/share
59
for share_dir in `ls "${REPO}"/local/share`; do
60
if [ $share_dir != "doc" ]; then
61
cp -R "${REPO}"/local/share/$share_dir ${VERSION_DIR}/local/share/$share_dir
62
fi
63
done
64
65
# Create the runpath.sh script
66
echo SAGE_SYMLINK=/var/tmp/sage-${VERSION}-current > ${VERSION_DIR}/local/var/lib/sage/runpath.sh
67
chmod 755 ${VERSION_DIR}/local/var/lib/sage/runpath.sh
68
69
# Copy our modified files into the bundle
70
# Install jupyter kernels, etc.
71
rm -rf ${VERSION_DIR}/${VENV_DIR}/share/jupyter/kernels/sagemath
72
# See sage/repl/ipython_kernel/install.py
73
mkdir -p ${VENV_KERNEL_DIR}/sagemath
74
sed "s/__VERSION__/${VERSION}/g" "${FILES}"/kernel.json > ${VENV_KERNEL_DIR}/sagemath/kernel.json
75
#cp -p ${FILES}/${TKINTER} ${VERSION_DIR}/${VENV_PYLIB}/lib-dynload/
76
cp -p ${FILES}/tkinter/__init__.py ${VERSION_DIR}/${VENV_PYLIB}/tkinter/__init__.py
77
cp ${FILES}/osx.py ${INPUT_HOOKS}
78
cp -p ${FILES}/BuildPackages.sh ${VERSION_DIR}/local/lib/gap/bin
79
cp ${FILES}/sage-notebook ${VERSION_DIR}/${VENV_DIR}/bin
80
sed "s/__VERSION__/${VERSION}/g" "${FILES}"/sage-notebook > ${VERSION_DIR}/${VENV_DIR}/bin/sage-notebook
81
cp ${FILES}/sage ${VERSION_DIR}/${VENV_DIR}/bin
82
cp ${FILES}/sage-env ${VERSION_DIR}/${VENV_DIR}/bin
83
cp ${FILES}/sagedoc.py ${VERSION_DIR}/${VENV_PYLIB}/site-packages/sage/misc/
84
cp ${FILES}/ipython_kernel/* ${VERSION_DIR}/${VENV_PYLIB}/site-packages/sage/repl/ipython_kernel
85
# Fix illegal symlinks that point outside of the bundle
86
rm -rf ${VERSION_DIR}/local/share/jupyter/kernels/sagemath/doc
87
rm -f ${VERSION_DIR}/local/share/threejs-sage/threejs-sage
88
rm -rf ${THREEJS_SAGE}
89
ln -s ../../../../../../../share/threejs-sage ${THREEJS_SAGE}
90
91
# Make @interact work
92
mkdir -p ${NBEXTENSIONS}/widgets/notebook
93
ln -s ../../jupyter-js-widgets ${NBEXTENSIONS}/widgets/notebook/js
94
95
# Remove some useless stuff
96
rm -rf ${VERSION_DIR}/local/lib/saclib
97
rm -rf ${VERSION_DIR}/local/share/man
98
99
# Update Sage's jupyter kernel directory.
100
rm -rf ${VERSION_DIR}/venv/share/jupyter/kernels
101
cp -R ../package/local_share/jupyter/kernels ${VERSION_DIR}/venv/share/jupyter
102
103
# # Install current versions of pip packages over the ones built by Sage
104
105
if [ -L ${SAGE_SYMLINK} ]; then
106
rm ${SAGE_SYMLINK}
107
elif [ -e ${SAGE_SYMLINK} ]; then
108
echo ${SAGE_SYMLINK} is not a symlink !!!
109
exit 1
110
fi
111
mv $VERSION_DIR $SAGE_SYMLINK
112
pushd ${SAGE_SYMLINK}
113
114
PIP_ARGS="install --upgrade --no-user --force-reinstall --upgrade-strategy eager"
115
venv/bin/python3 -m pip $PIP_ARGS jupyterlab
116
venv/bin/python3 -m pip $PIP_ARGS notebook
117
venv/bin/python3 -m pip $PIP_ARGS pillow
118
119
# Install cocoserver
120
PIP_ARGS="install --no-user --upgrade --no-deps"
121
venv/bin/python3 -m pip $PIP_ARGS cocoserver
122
123
popd
124
mv $SAGE_SYMLINK $VERSION_DIR
125
126
# Fix up rpaths and shebangs
127
echo "Patching files ..."
128
source ../IDs.sh
129
mv files_to_sign files_to_sign.bak
130
python3 fix_paths.py repo ${VERSION_DIR}/local/bin >> files_to_sign
131
python3 fix_paths.py repo ${VERSION_DIR}/local/lib >> files_to_sign
132
python3 fix_paths.py repo ${VERSION_DIR}/local/libexec >> files_to_sign
133
python3 fix_paths.py repo ${VERSION_DIR}/${VENV_DIR}/bin >> files_to_sign
134
python3 fix_paths.py repo ${VERSION_DIR}/${VENV_DIR}/lib >> files_to_sign
135
python3 fix_scripts.py ${VERSION_DIR}/$VENV_DIR}/bin
136
137
# Fix the absolute symlinks for the GAP packages
138
pushd ${VERSION_DIR}/local/share/gap/pkg > /dev/null
139
for pkg in `ls` ; do
140
if [[ -L $pkg/bin ]]; then
141
rm $pkg/bin ;
142
ln -s ../../../../lib/gap/pkg/$pkg/bin $pkg/bin ;
143
fi
144
done
145
popd > /dev/null
146
147
# Remove xattrs (must be done before signing!)
148
xattr -rc ${BUILD}/Sage.framework
149
150
# Remove byte code
151
find ${BUILD}/Sage.framework -name '*.pyc' -delete
152
# Sign the framework.
153
echo "Signing files ..."
154
python3 sign_sage.py
155
# Overwrite the _tkinter extension with our signed version
156
cp -p ${FILES}/${TKINTER_LIB} ${VERSION_DIR}/${VENV_PYLIB}/lib-dynload/
157
# Start sage to create a minimal set of bytecode files.
158
echo "Starting Sage to create byte code files ..."
159
${VERSION_DIR}/venv/bin/sage -c "print(2+2) ; exit"
160
echo "We need to sign the framework again:"
161
python3 sign_sage.py framework
162
163