-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathon-jupyter-server-start.sh
75 lines (67 loc) · 3.35 KB
/
on-jupyter-server-start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Install and configure assistive IDE tools *if* running high enough JupyterLab version (v3)
#
# This script sets up code completion, continuous hinting, hover tips, code formatting, and
# markdown spell-checking. Includes some config setting on these tools - see below for details.
set -eu
export AWS_SAGEMAKER_JUPYTERSERVER_IMAGE="${AWS_SAGEMAKER_JUPYTERSERVER_IMAGE:-'jupyter-server'}"
if [ "$AWS_SAGEMAKER_JUPYTERSERVER_IMAGE" != "jupyter-server-3" ] ; then
echo "SageMaker version '$AWS_SAGEMAKER_JUPYTERSERVER_IMAGE' does not match 'jupyter-server-3'"
echo "Skipping assistive features install (which depends on JupyterLab v3)"
exit 0
fi
# Activate the conda environment where Jupyter is installed:
eval "$(conda shell.bash hook)"
conda activate studio
# Install:
# - The core JupyterLab LSP integration and whatever language servers you need (omitting autopep8
# and yapf code formatters for Python, which don't yet have integrations per
# https://github.com/jupyter-lsp/jupyterlab-lsp/issues/632)
# - Additional LSP plugins for formatting (black, isort) and refactoring (rope)
# - Spellchecker for markdown cells
# - Code formatting extension to bridge the LSP gap, and supported formatters
echo "Installing jupyterlab-lsp and language tools"
pip install jupyterlab-lsp \
'python-lsp-server[flake8,mccabe,pycodestyle,pydocstyle,pyflakes,pylint,rope]' \
jupyterlab-spellchecker \
jupyterlab-code-formatter black isort
# Some LSP language servers install via JS, not Python. For full list of language servers see:
# https://jupyterlab-lsp.readthedocs.io/en/latest/Language%20Servers.html
jlpm add --dev bash-language-server@"<5.0.0" dockerfile-language-server-nodejs
# This configuration override is optional, to make LSP "extra-helpful" by default:
CMP_CONFIG_DIR=.jupyter/lab/user-settings/@krassowski/jupyterlab-lsp/
CMP_CONFIG_FILE=completion.jupyterlab-settings
CMP_CONFIG_PATH="$CMP_CONFIG_DIR/$CMP_CONFIG_FILE"
if test -f $CMP_CONFIG_PATH; then
echo "jupyterlab-lsp config file already exists: Skipping default config setup"
else
echo "Setting continuous hinting to enabled by default"
mkdir -p $CMP_CONFIG_DIR
echo '{ "continuousHinting": true }' > $CMP_CONFIG_PATH
fi
# Similarly can set other configurations. Note:
# - Line width is unfortunately configured separately for several of these plugins.
# - If you enable automatic "formatOnSave" as shown here, you'll see an error dialog when saving a
# notebook with incomplete/invalid Python syntax - but the file should still save.
FMT_CONFIG_DIR=~/.jupyter/lab/user-settings/@ryantam626/jupyterlab_code_formatter
FMT_CONFIG_FILE=settings.jupyterlab-settings
FMT_CONFIG_PATH="$FMT_CONFIG_DIR/$FMT_CONFIG_FILE"
if test -f $FMT_CONFIG_PATH; then
echo "jupyterlab-code-formatter config file already exists: Skipping default config setup"
else
echo "Configuring jupyterlab-code-formatter format on save and line width"
mkdir -p $FMT_CONFIG_DIR
cat > $FMT_CONFIG_PATH <<EOF
{"black": {"line_length": 100}, "isort": {"line_length": 100}, "formatOnSave": true}
EOF
fi
echo "Configuring pycodestyle linter max line width"
mkdir -p ~/.config
cat > ~/.config/pycodestyle <<EOF
[pycodestyle]
max-line-length = 100
EOF
conda deactivate
# Once components are installed and configured, restart Jupyter to make sure everything propagates:
echo "Restarting Jupyter server..."
restart-jupyter-server