From 026dd60a94c4bf79050f9ec3f1a46d598ca99415 Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Sun, 7 Jul 2024 15:42:32 +0200 Subject: [PATCH 1/7] add support for unix_socket --- jupyter_rsession_proxy/__init__.py | 42 ++++++++++++++++++++++++------ setup.py | 2 +- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 37f7033..469e616 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -51,7 +51,7 @@ def get_system_user(): return(user) def setup_rserver(): - def _get_env(port): + def _get_env(port, unix_socket): return dict(USER=get_system_user()) def db_config(db_dir): @@ -73,9 +73,10 @@ def db_config(db_dir): f.close() return db_config_name - def _support_arg(arg): + def _support_args(args): ret = subprocess.check_output([get_rstudio_executable('rserver'), '--help']) - return ret.decode().find(arg) != -1 + help_output = ret.decode() + return {arg: (help_output.find(arg) != -1) for arg in args} def _get_www_frame_origin(default="same"): try: @@ -83,7 +84,7 @@ def _get_www_frame_origin(default="same"): except Exception: return default - def _get_cmd(port): + def _get_cmd(port, unix_socket): ntf = tempfile.NamedTemporaryFile() # use mkdtemp() so the directory and its contents don't vanish when @@ -95,19 +96,41 @@ def _get_cmd(port): get_rstudio_executable('rserver'), '--auth-none=1', '--www-frame-origin=' + _get_www_frame_origin(), - '--www-port=' + str(port), '--www-verify-user-agent=0', '--secure-cookie-key-file=' + ntf.name, '--server-user=' + get_system_user(), ] # Support at least v1.2.1335 and up - if _support_arg('www-root-path'): + supported_args = _support_args([ + 'www-root-path', + 'server-data-dir', + 'database-config-file', + 'www-thread-pool-size', + 'www-socket', + + ]) + if supported_args['www-root-path']: cmd.append('--www-root-path={base_url}rstudio/') - if _support_arg('server-data-dir'): + if supported_args['server-data-dir']: cmd.append(f'--server-data-dir={server_data_dir}') - if _support_arg('database-config-file'): + if supported_args['database-config-file']: cmd.append(f'--database-config-file={database_config_file}') + if supported_args['www-thread-pool-size']: + try: + thread_pool_size = int(os.getenv('RSERVER_THREAD_POOL_SIZE', "")) + if thread_pool_size > 0: + cmd.append('--www-thread-pool-size=' + str(thread_pool_size)) + except: + pass + + if unix_socket != "": + if supported_args['www-socket']: + cmd.append('--www-socket={unix_socket}') + else: + raise NotImplementedError(f'rstudio-server does not support requested socket connection') + else: + cmd.append('--www-port={port}') return cmd @@ -127,6 +150,9 @@ def _get_timeout(default=15): 'icon_path': get_icon_path() } } + if os.getenv('RSERVER_USE_SOCKET', "") != "": + server_process['unix_socket'] = True + return server_process def setup_rsession(): diff --git a/setup.py b/setup.py index 246fe07..2cd7144 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ keywords=['Jupyter'], classifiers=['Framework :: Jupyter'], install_requires=[ - 'jupyter-server-proxy>=3.2.3,!=4.0.0,!=4.1.0' + 'jupyter-server-proxy>=4.1.0' ], entry_points={ 'jupyter_serverproxy_servers': [ From 52c5cac87aaba439f164a99542a742c24df959de Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Sun, 7 Jul 2024 15:46:27 +0200 Subject: [PATCH 2/7] fix style --- jupyter_rsession_proxy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 469e616..901ebd8 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -108,7 +108,6 @@ def _get_cmd(port, unix_socket): 'database-config-file', 'www-thread-pool-size', 'www-socket', - ]) if supported_args['www-root-path']: cmd.append('--www-root-path={base_url}rstudio/') @@ -116,6 +115,7 @@ def _get_cmd(port, unix_socket): cmd.append(f'--server-data-dir={server_data_dir}') if supported_args['database-config-file']: cmd.append(f'--database-config-file={database_config_file}') + if supported_args['www-thread-pool-size']: try: thread_pool_size = int(os.getenv('RSERVER_THREAD_POOL_SIZE', "")) From e40ef8de5263cf219b729e4be32dcce539ad86d7 Mon Sep 17 00:00:00 2001 From: Jens Henrik Goebbert Date: Mon, 8 Jul 2024 08:31:14 +0200 Subject: [PATCH 3/7] Update install_requires --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2cd7144..4485924 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ keywords=['Jupyter'], classifiers=['Framework :: Jupyter'], install_requires=[ - 'jupyter-server-proxy>=4.1.0' + 'jupyter-server-proxy>4.1.0' ], entry_points={ 'jupyter_serverproxy_servers': [ From 63835158047895cfe6256b99fd257c3fb2cdd64f Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Wed, 1 Jan 2025 20:13:23 +0100 Subject: [PATCH 4/7] rename env-vars --- jupyter_rsession_proxy/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 901ebd8..7dd4b4d 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -136,7 +136,7 @@ def _get_cmd(port, unix_socket): def _get_timeout(default=15): try: - return float(os.getenv('RSERVER_TIMEOUT', default)) + return float(os.getenv('JUPYTER_RSESSION_PROXY_TIMEOUT', default)) except Exception: return default @@ -150,7 +150,7 @@ def _get_timeout(default=15): 'icon_path': get_icon_path() } } - if os.getenv('RSERVER_USE_SOCKET', "") != "": + if os.getenv('JUPYTER_RSESSION_PROXY_USE_SOCKET'): server_process['unix_socket'] = True return server_process From 4567a6a5edebb164bff1ed7d2a1446c3c29b31fa Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Wed, 1 Jan 2025 20:23:53 +0100 Subject: [PATCH 5/7] undo to RSERVER_ --- jupyter_rsession_proxy/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 7dd4b4d..3998dce 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -80,7 +80,7 @@ def _support_args(args): def _get_www_frame_origin(default="same"): try: - return os.getenv('JUPYTER_RSESSION_PROXY_WWW_FRAME_ORIGIN', default) + return os.getenv('RSERVER_WWW_FRAME_ORIGIN', default) except Exception: return default @@ -136,7 +136,7 @@ def _get_cmd(port, unix_socket): def _get_timeout(default=15): try: - return float(os.getenv('JUPYTER_RSESSION_PROXY_TIMEOUT', default)) + return float(os.getenv('RSERVER_TIMEOUT', default)) except Exception: return default @@ -150,9 +150,9 @@ def _get_timeout(default=15): 'icon_path': get_icon_path() } } - if os.getenv('JUPYTER_RSESSION_PROXY_USE_SOCKET'): + if os.getenv('RSERVER_USE_SOCKET'): server_process['unix_socket'] = True - +RSERVER_TIMEOUT return server_process def setup_rsession(): From 09491d72d1c243d7ca534fc4642d47703dab2bd7 Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Wed, 1 Jan 2025 20:28:41 +0100 Subject: [PATCH 6/7] undo FRAME_ORIGIN var --- jupyter_rsession_proxy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 3998dce..097e047 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -80,7 +80,7 @@ def _support_args(args): def _get_www_frame_origin(default="same"): try: - return os.getenv('RSERVER_WWW_FRAME_ORIGIN', default) + return os.getenv('JUPYTER_RSESSION_PROXY_WWW_FRAME_ORIGIN', default) except Exception: return default From f16923df24266d6f1d5af2555d80da9f3cb98aca Mon Sep 17 00:00:00 2001 From: Jens Henrik Goebbert Date: Wed, 1 Jan 2025 20:49:06 +0100 Subject: [PATCH 7/7] fix fix copy-paste-error --- jupyter_rsession_proxy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 097e047..49c4a96 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -152,7 +152,7 @@ def _get_timeout(default=15): } if os.getenv('RSERVER_USE_SOCKET'): server_process['unix_socket'] = True -RSERVER_TIMEOUT + return server_process def setup_rsession():