From 04dba887ab544214759ba804e4ddb2b8c9d99f00 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Mon, 4 Mar 2024 10:22:36 +0000 Subject: [PATCH 1/8] Check syntax of Python config file in terraform --- .../modules/kubernetes/services/jupyterhub/configmaps.tf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf index 6fe6cd0e5e..fe7ee4deab 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf @@ -30,6 +30,11 @@ locals { resource "local_file" "jupyter_server_config_py" { content = local.jupyter-notebook-config-py-template filename = "${path.module}/files/jupyter/jupyter_server_config.py" + + provisioner "local-exec" { + # check the syntax of the config file without running it + command = "python -m py_compile ${self.filename}" + } } resource "local_file" "jupyter_jupyterlab_pioneer_config_py" { From d140bf7e235abdddec31248ffac137b9acc82401 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Mon, 4 Mar 2024 11:22:47 +0000 Subject: [PATCH 2/8] Check for syntax errors in `jupyter_jupyterlab_pioneer_config.py` too --- .../modules/kubernetes/services/jupyterhub/configmaps.tf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf index fe7ee4deab..4b8f9145b9 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf @@ -40,6 +40,11 @@ resource "local_file" "jupyter_server_config_py" { resource "local_file" "jupyter_jupyterlab_pioneer_config_py" { content = local.jupyter-pioneer-config-py-template filename = "${path.module}/files/jupyter/jupyter_jupyterlab_pioneer_config.py" + + provisioner "local-exec" { + # check the syntax of the config file without running it + command = "python -m py_compile ${self.filename}" + } } From 875b273b10b30281283cef10ea1f34c00dd1c924 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Mon, 4 Mar 2024 11:25:38 +0000 Subject: [PATCH 3/8] Add missing quotes around preferred dir path variable --- .../jupyterhub/files/jupyter/jupyter_server_config.py.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl index ab5117ee1b..64216a2511 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl @@ -10,7 +10,7 @@ c.ContentsManager.allow_hidden = True c.FileContentsManager.allow_hidden = True # Set the preferred path for the frontend to start in -preferred_dir = ${jupyterlab_preferred_dir} +preferred_dir = "${jupyterlab_preferred_dir}" c.FileContentsManager.preferred_dir = preferred_dir if preferred_dir else None # Timeout (in seconds) in which a terminal has been inactive and ready to From f47dda8226e08128597508941a187d1ebfbf42a5 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Mon, 4 Mar 2024 12:19:10 +0000 Subject: [PATCH 4/8] Add quotes around "log_format" in pioneer config --- .../files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl index 2149d298f8..66b653b894 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl @@ -3,7 +3,7 @@ import json default_log_format = "%(asctime)s %(levelname)9s %(lineno)4s %(module)s: %(message)s" -log_format = ${log_format} +log_format = "${log_format}" logging.basicConfig( level=logging.INFO, From cc47baee0e29602d04966d1b402e7d02570db53b Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Mon, 4 Mar 2024 14:01:03 +0000 Subject: [PATCH 5/8] [debug] comment out pioneer config --- .../files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl index 66b653b894..bb773b9fa2 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl @@ -1,3 +1,4 @@ +""" import logging import json @@ -16,7 +17,6 @@ CUSTOM_EXPORTER_NAME = "MyCustomExporter" def my_custom_exporter(args): - """Custom exporter to log JupyterLab events to command line.""" logger.info(json.dumps(args.get("data"))) return { "exporter": CUSTOM_EXPORTER_NAME, @@ -58,3 +58,4 @@ c.JupyterLabPioneerApp.activeEvents = [ {"name": "NotebookScrollEvent", "logWholeNotebook": False}, {"name": "NotebookVisibleEvent", "logWholeNotebook": False}, ] +""" From 23b2ae2fca7ddc405d32a1b557b02fabddf9af7f Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Mon, 4 Mar 2024 14:26:19 +0000 Subject: [PATCH 6/8] [debug] comment out first half of the server config file --- .../files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl | 3 +-- .../jupyterhub/files/jupyter/jupyter_server_config.py.tpl | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl index bb773b9fa2..66b653b894 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl @@ -1,4 +1,3 @@ -""" import logging import json @@ -17,6 +16,7 @@ CUSTOM_EXPORTER_NAME = "MyCustomExporter" def my_custom_exporter(args): + """Custom exporter to log JupyterLab events to command line.""" logger.info(json.dumps(args.get("data"))) return { "exporter": CUSTOM_EXPORTER_NAME, @@ -58,4 +58,3 @@ c.JupyterLabPioneerApp.activeEvents = [ {"name": "NotebookScrollEvent", "logWholeNotebook": False}, {"name": "NotebookVisibleEvent", "logWholeNotebook": False}, ] -""" diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl index 64216a2511..caa1daa27c 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl @@ -4,7 +4,7 @@ # Extra config available at: # https://zero-to-jupyterhub.readthedocs.io/en/1.x/jupyterhub/customizing/user-management.html#culling-user-pods - +""" # Enable Show Hidden Files menu option in View menu c.ContentsManager.allow_hidden = True c.FileContentsManager.allow_hidden = True @@ -28,6 +28,7 @@ c.MappingKernelManager.cull_idle_timeout = ${kernel_cull_idle_timeout} * 60 # cull_interval: the interval (in seconds) on which to check for idle # kernels exceeding the cull timeout value c.MappingKernelManager.cull_interval = ${kernel_cull_interval} * 60 +""" # cull_connected: whether to consider culling kernels which have one # or more connections From 569a953a306ed3fd19f3fc9f6c20f7be70205e50 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Mon, 4 Mar 2024 14:56:27 +0000 Subject: [PATCH 7/8] [debug] narrow down the bisection (previous commit passed) --- .../jupyterhub/files/jupyter/jupyter_server_config.py.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl index caa1daa27c..58ecc5fa03 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl @@ -12,6 +12,7 @@ c.FileContentsManager.allow_hidden = True # Set the preferred path for the frontend to start in preferred_dir = "${jupyterlab_preferred_dir}" c.FileContentsManager.preferred_dir = preferred_dir if preferred_dir else None +""" # Timeout (in seconds) in which a terminal has been inactive and ready to # be culled. @@ -28,7 +29,6 @@ c.MappingKernelManager.cull_idle_timeout = ${kernel_cull_idle_timeout} * 60 # cull_interval: the interval (in seconds) on which to check for idle # kernels exceeding the cull timeout value c.MappingKernelManager.cull_interval = ${kernel_cull_interval} * 60 -""" # cull_connected: whether to consider culling kernels which have one # or more connections From b6f2ca08e7cac2a1d418aeb486b480d6f43774f2 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:37:02 +0000 Subject: [PATCH 8/8] Fix the `preferred_dir` issue (it does not take `None`) --- .../jupyterhub/files/jupyter/jupyter_server_config.py.tpl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl index 58ecc5fa03..d5e089dfa3 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl @@ -4,15 +4,12 @@ # Extra config available at: # https://zero-to-jupyterhub.readthedocs.io/en/1.x/jupyterhub/customizing/user-management.html#culling-user-pods -""" # Enable Show Hidden Files menu option in View menu c.ContentsManager.allow_hidden = True c.FileContentsManager.allow_hidden = True # Set the preferred path for the frontend to start in -preferred_dir = "${jupyterlab_preferred_dir}" -c.FileContentsManager.preferred_dir = preferred_dir if preferred_dir else None -""" +c.FileContentsManager.preferred_dir = "${jupyterlab_preferred_dir}" # Timeout (in seconds) in which a terminal has been inactive and ready to # be culled.