-
Notifications
You must be signed in to change notification settings - Fork 22
/
jupyter_notebook_config.py
91 lines (74 loc) · 3.01 KB
/
jupyter_notebook_config.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
git_url = os.getenv('GIT_URL', None)
git_name = os.getenv('GIT_NAME', 'Default user')
git_email = os.getenv('GIT_EMAIL', '[email protected]')
persistent_folder = os.getenv('PERSISTENT_FOLDER', None)
workspace = os.getenv('WORKSPACE', None)
# Preconfigure git to avoid to do it manually
os.system('git config --global user.name "' + git_name + '"')
os.system('git config --global user.email "' + git_email + '"')
c.ServerApp.terminado_settings = {'shell_command': ['/bin/zsh']}
c.ServerProxy.servers = {
"code-server": {
"command": [
"code-server",
"--auth=none",
"--disable-telemetry",
"--host=127.0.0.1",
"--port={port}",
os.getenv("JUPYTER_SERVER_ROOT", ".")
],
"timeout": 20,
"launcher_entry": {
"title": "VisualStudio Code",
"icon_path": "/etc/jupyter/vscode.svg",
"enabled" : True
},
},
}
if persistent_folder:
os.chdir(persistent_folder)
if git_url:
os.system('git clone --quiet --recursive ' + git_url)
repo_id = git_url.rsplit('/', 1)[-1].rsplit('.git', 1)[0]
print(f'📥️ Cloning {repo_id}')
os.chdir(repo_id)
if os.path.exists('packages.txt'):
os.system('sudo apt-get update')
os.system('cat packages.txt | xargs sudo apt-get install -y')
if os.path.exists('requirements.txt'):
os.system('pip install -r requirements.txt')
if os.path.exists('extensions.txt'):
os.system('cat extensions.txt | xargs -I {} jupyter {} install --user')
## Conda install getting stuck sometimes
if os.path.exists('environment.yml'):
os.system('mamba env create -f environment.yml')
# os.system('conda env create -f environment.yml')
if os.path.exists('environment.yaml'):
os.system('mamba env create -f environment.yaml')
# os.system('conda env create -f environment.yaml')
if workspace:
os.chdir(workspace)
# https://github.com/jupyter/docker-stacks/blob/master/base-notebook/jupyter_notebook_config.py
# Avoid duplicate conda kernel starters https://github.com/Anaconda-Platform/nb_conda_kernels/issues/141
# https://github.com/jupyterhub/jupyterhub/issues/715#issuecomment-463756411
# c.ServerApp.kernel_spec_manager_class = 'nb_conda_kernels.CondaKernelSpecManager'
# c.CondaKernelSpecManager.env_filter = 'root'
# Remove default Java and Python kernel (to use the conda one and avoid duplicate)
# os.system('echo y | jupyter kernelspec remove java')
# os.system('echo y | jupyter kernelspec remove python3')
# https://github.com/jupyter/notebook/issues/3130
# c.FileContentsManager.delete_to_trash = False
# "openvscode": {
# "command": [
# os.getenv("OPENVSCODE_SERVER_ROOT", "/opt/openvscode") + "/server.sh ",
# "--port={port}",
# # os.getenv("JUPYTER_SERVER_ROOT", ".")
# ],
# "timeout": 20,
# "launcher_entry": {
# "title": "Open VS Code",
# "icon_path": "/etc/jupyter/vscode.svg",
# "enabled" : True
# },
# },