Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimize overhead when checking the supported args by RStudio #160

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions jupyter_rsession_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
jhgoebbert marked this conversation as resolved.
Show resolved Hide resolved

def _get_www_frame_origin(default="same"):
try:
Expand All @@ -101,15 +102,30 @@ def _get_cmd(port, unix_socket):
]
# 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('JUPYTER_RSESSION_PROXY_THREAD_POOL_SIZE', ""))
jhgoebbert marked this conversation as resolved.
Show resolved Hide resolved
if thread_pool_size > 0:
cmd.append('--www-thread-pool-size=' + str(thread_pool_size))
except:
pass

if unix_socket != "":
if _support_arg('www-socket'):
if supported_args['www-socket']:
cmd.append('--www-socket={unix_socket}')
else:
raise NotImplementedError(f'rstudio-server does not support requested socket connection')
Expand Down