gatoniel / podmanspawner

Spawner to use podman with JupyterHub
BSD 3-Clause "New" or "Revised" License
6 stars 4 forks source link

fix for jupyterhub 3.1.0 (patch included) #3

Open aminasyan opened 1 year ago

aminasyan commented 1 year ago

Hi, I have patched podmanspawner to work with jupyterhub 3.1.0 also added a needed feature to jupyter_additional_cmds.

(podmanspawner-v3-hub.patch)

diff -ruN a/podmanspawner/podmanspawner.py b/podmanspawner/podmanspawner.py
--- a/podmanspawner/podmanspawner.py    2022-03-23 23:54:42.000000000 -0700
+++ b/podmanspawner/podmanspawner.py    2023-01-14 18:41:30.418601680 -0800
@@ -77,7 +77,7 @@
         "start-notebook.sh",
         help="""This command is run in the container. Should be 'start-notebook.sh'
         or 'jupyterhub-singleuser'. PORT gets replaced by the port number the notebook should run on."""
-        )
+        ).tag(config=True)
     standard_jupyter_port = Integer(
         8888,
         help="""The standard port, the Jupyter Notebook is listening in the
@@ -96,20 +96,21 @@
         ).tag(config=True)
     jupyter_additional_cmds = List(
         default_value=[],
-        help="""These commands are appended to the jupyter_base_cmd."""
+        help="""These commands are appended to the jupyter_base_cmd. Use USERNAME to refer
+        to the users name in the cmd options"""
         ).tag(config=True)

     enable_lab = Bool(
         False,
         help="""Enable Jupyter Lab in the container via environment variable.
         Dont forget to change c.Spawner.default_url = '/lab'."""
-        )
+        ).tag(config=True)

     env_keep = List(
         [],
         help="""Override the env_keep of the Spawner calls, since we do not need
         to keep these env variables in the container."""
-        )
+        ).tag(config=True)
     # here we would need traitlets callable type...
     preexec_fn_set = Integer(
         0,
@@ -117,10 +118,10 @@
         Set this to 1, when there is a different preexec_fn""",
     )
     conthome = Unicode(
-        "/home/jovyan/home",
+        "",
         help="""Where to map the users home directory. Use USERNAME to refer
         to the users name in the filepath"""
-        )
+        ).tag(config=True)
     startatconthome = Bool(False, help="""add -w conthome to podman cmd""")

     def make_preexec_fn(self, name):
@@ -185,6 +186,8 @@
     def get_env(self):
         """Get the complete set of environment variables to be set in the spawned process."""
         env = super().get_env()
+        env['JUPYTERHUB_OAUTH_SCOPES']=env['JUPYTERHUB_OAUTH_SCOPES'].translate(str.maketrans({"[":  r"'[", "]":  r"]'",}))
+        env['JUPYTERHUB_OAUTH_ACCESS_SCOPES']=env['JUPYTERHUB_OAUTH_ACCESS_SCOPES'].translate(str.maketrans({"[":  r"'[", "]":  r"]'",}))
         # We do not need user defined stuff in the container. So we do not need
         # this next line...
         # env = self.user_env(env)
@@ -280,7 +283,7 @@
             jupyter_base_cmd.append("--NotebookApp.port={}".format(self.port))

         podman_cmd = podman_base_cmd+self.podman_additional_cmds
-        jupyter_cmd = jupyter_base_cmd+self.jupyter_additional_cmds
+        jupyter_cmd = jupyter_base_cmd+[sub.replace('USERNAME', self.user.name ) for sub in self.jupyter_additional_cmds]

         cmd = shlex.split(" ".join(podman_cmd+jupyter_cmd))

Best Regards Aram

aminasyan commented 1 year ago

I have packaged it here https://copr.fedorainfracloud.org/coprs/aminasyan/el8-collection/