From b86bf7a59b875144c034066605f9fbbfd5a89a37 Mon Sep 17 00:00:00 2001 From: bloodearnest Date: Thu, 17 Oct 2024 14:30:00 +0100 Subject: [PATCH] some language tweaks and cleanups --- opensafely/jupyter.py | 2 +- opensafely/rstudio.py | 16 +++++++++------- opensafely/utils.py | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/opensafely/jupyter.py b/opensafely/jupyter.py index 4970d47..160c1e1 100644 --- a/opensafely/jupyter.py +++ b/opensafely/jupyter.py @@ -36,7 +36,7 @@ def add_arguments(parser): "--port", "-p", default=None, - help="Port to run on", + help="Port to run on (random by default)", ) parser.add_argument( "jupyter_args", diff --git a/opensafely/rstudio.py b/opensafely/rstudio.py index 9096bd8..2b5440a 100644 --- a/opensafely/rstudio.py +++ b/opensafely/rstudio.py @@ -19,12 +19,11 @@ def add_arguments(parser): parser.add_argument( "--name", help="Name of docker image (defaults to use directory name)" ) - parser.add_argument( "--port", "-p", default=None, - help="Port to run on", + help="Port to run on (random by default)", ) @@ -37,8 +36,6 @@ def main(directory, name, port): url = f"http://localhost:{port}" - # Determine if on Linux, if so obtain user id - # And need to know in Windows win32 for text file line endings setting if platform == "linux": uid = os.getuid() else: @@ -57,14 +54,19 @@ def main(directory, name, port): utils.debug("docker: " + " ".join(docker_args)) print( - f"Opening an RStudio Server session at http://localhost:{port}/ when " - "you are finished working please press Ctrl+C here to end the session" + f"Opening an RStudio Server session at {url}. " + "When you are finished working please press Ctrl+C here to end the session" ) utils.open_browser_in_thread(url) ps = utils.run_docker( - docker_args, "rstudio", "", interactive=True, user="0:0", directory=directory + docker_args, + image="rstudio", + interactive=True, + # rstudio needs to start as root, but drops privileges to uid later + user="0:0", + directory=directory, ) # we want to exit with the same code that rstudio-server did diff --git a/opensafely/utils.py b/opensafely/utils.py index e6752aa..271886f 100644 --- a/opensafely/utils.py +++ b/opensafely/utils.py @@ -92,7 +92,7 @@ def git_bash_tty_wrapper(): def run_docker( docker_args, image, - cmd, + cmd=(), directory=None, interactive=False, user=None,