-
Notifications
You must be signed in to change notification settings - Fork 88
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
Optimize checking of supported args #152
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,5 @@ | ||||||||||||
import getpass | ||||||||||||
import os | ||||||||||||
import pathlib | ||||||||||||
import shutil | ||||||||||||
import subprocess | ||||||||||||
import tempfile | ||||||||||||
|
@@ -46,7 +45,7 @@ def rewrite_netloc(response, request): | |||||||||||
def get_system_user(): | ||||||||||||
try: | ||||||||||||
user = pwd.getpwuid(os.getuid())[0] | ||||||||||||
except: | ||||||||||||
except Exception: | ||||||||||||
user = os.getenv('NB_USER', getpass.getuser()) | ||||||||||||
return(user) | ||||||||||||
|
||||||||||||
|
@@ -73,9 +72,16 @@ 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: | ||||||||||||
return os.getenv('JUPYTER_RSESSION_PROXY_WWW_FRAME_ORIGIN', default) | ||||||||||||
except Exception: | ||||||||||||
return default | ||||||||||||
Comment on lines
+81
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think a try/except block is relevant here, I don't know of an error to be raised that we want that can be raised in this situation using os.getenv.
Suggested change
Could you update the PR title or description to try capture this is now configurable via an environment variable? Whatever is put in the title will be visible via the changelog btw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I've seen #148 now. So this PR isn't really introducing this after all, its already there? |
||||||||||||
|
||||||||||||
def _get_www_frame_origin(default="same"): | ||||||||||||
try: | ||||||||||||
|
@@ -102,13 +108,27 @@ 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', | ||||||||||||
]) | ||||||||||||
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 Exception: | ||||||||||||
pass | ||||||||||||
|
||||||||||||
Comment on lines
+125
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is errorously configured, such as having I think maybe something like...
|
||||||||||||
return cmd | ||||||||||||
|
||||||||||||
def _get_timeout(default=15): | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed pathlib since it is not used