From 6f9f616fb8a5f841078290d9a4ce365db782f0ec Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Wed, 1 Jan 2025 21:02:40 +0100 Subject: [PATCH 1/4] adds supported_args --- jupyter_rsession_proxy/__init__.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 37f7033..262ecfb 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -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: @@ -102,13 +103,32 @@ def _get_cmd(port): ] # 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 support_args['server-data-dir']: cmd.append(f'--server-data-dir={server_data_dir}') - if _support_arg('database-config-file'): + if support_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}') + return cmd def _get_timeout(default=15): From d86d419a91da01e88dd91c16d95521208aeae342 Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Wed, 1 Jan 2025 21:19:32 +0100 Subject: [PATCH 2/4] fix typo --- 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 262ecfb..5d6141d 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -112,9 +112,9 @@ def _get_cmd(port): ]) if supported_args['www-root-path']: cmd.append('--www-root-path={base_url}rstudio/') - if support_args['server-data-dir']: + if supported_args['server-data-dir']: cmd.append(f'--server-data-dir={server_data_dir}') - if support_args['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']: From 4ced2e0e48da1021bca78d55cb2e01d7268e2322 Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Fri, 3 Jan 2025 13:52:20 +0100 Subject: [PATCH 3/4] rename envvar --- 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 473aae2..5539e98 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -118,7 +118,7 @@ def _get_cmd(port, unix_socket): if supported_args['www-thread-pool-size']: try: - thread_pool_size = int(os.getenv('RSERVER_THREAD_POOL_SIZE', "")) + thread_pool_size = int(os.getenv('JUPYTER_RSESSION_PROXY_THREAD_POOL_SIZE', "")) if thread_pool_size > 0: cmd.append('--www-thread-pool-size=' + str(thread_pool_size)) except: @@ -126,7 +126,7 @@ def _get_cmd(port, unix_socket): if unix_socket != "": if supported_args['www-socket']: - cmd.append('--www-socket={unix_socket}') + cmd.append('--www-socket={unix_socket}') else: raise NotImplementedError(f'rstudio-server does not support requested socket connection') else: From cc509612d8fdf80c989f2cc10f88252dfca43118 Mon Sep 17 00:00:00 2001 From: goebbert1 Date: Fri, 3 Jan 2025 23:35:24 +0100 Subject: [PATCH 4/4] add suggestions --- jupyter_rsession_proxy/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 5539e98..6e11eac 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -76,7 +76,7 @@ def db_config(db_dir): def _support_args(args): ret = subprocess.check_output([get_rstudio_executable('rserver'), '--help']) help_output = ret.decode() - return {arg: (help_output.find(arg) != -1) for arg in args} + return {arg: (help_output.find(f"--{arg}") != -1) for arg in args} def _get_www_frame_origin(default="same"): try: @@ -117,11 +117,14 @@ def _get_cmd(port, unix_socket): cmd.append(f'--database-config-file={database_config_file}') if supported_args['www-thread-pool-size']: + thread_pool_size_env = os.getenv('JUPYTER_RSESSION_PROXY_THREAD_POOL_SIZE', None) try: - thread_pool_size = int(os.getenv('JUPYTER_RSESSION_PROXY_THREAD_POOL_SIZE', "")) - if thread_pool_size > 0: - cmd.append('--www-thread-pool-size=' + str(thread_pool_size)) - except: + if thread_pool_size_env is not None: + thread_pool_size = int(thread_pool_size_env) + if thread_pool_size > 0: + cmd.append('--www-thread-pool-size=' + str(thread_pool_size)) + except ValueError: + print("Invalid value for JUPYTER_RSESSION_PROXY_THREAD_POOL_SIZE. Must be an integer.") pass if unix_socket != "":