Skip to content

Commit 8b86f54

Browse files
authored
Merge pull request #54 from yuvipanda/path-hack
Detect path of rsession in default rstudio install automatically
2 parents d65e838 + cf844be commit 8b86f54

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

jupyter_rsession_proxy/__init__.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import tempfile
33
import subprocess
44
import getpass
5+
import shutil
56
from textwrap import dedent
67

78
def setup_shiny():
@@ -56,16 +57,36 @@ def _get_rsession_env(port):
5657
'RSTUDIO_DEFAULT_R_VERSION': version,
5758
}
5859

59-
return {
60-
'command': [
61-
'rsession',
60+
def _get_rsession_cmd(port):
61+
# Other paths rsession maybe in
62+
other_paths = [
63+
# When rstudio-server deb is installed
64+
'/usr/lib/rstudio-server/bin/rsession',
65+
# When just rstudio deb is installed
66+
'/usr/lib/rstudio/bin/rsession',
67+
]
68+
if shutil.which('rsession'):
69+
executable = 'rsession'
70+
else:
71+
for op in other_paths:
72+
if os.path.exists(op):
73+
executable = op
74+
break
75+
else:
76+
raise FileNotFoundError('Can not find rsession in PATH')
77+
78+
return [
79+
executable,
6280
'--standalone=1',
6381
'--program-mode=server',
6482
'--log-stderr=1',
6583
'--session-timeout-minutes=0',
6684
'--user-identity=' + getpass.getuser(),
67-
'--www-port={port}'
68-
],
85+
'--www-port=' + str(port)
86+
]
87+
88+
return {
89+
'command': _get_rsession_cmd,
6990
'environment': _get_rsession_env,
7091
'title': 'RStudio',
7192
'icon': os.path.join(os.path.dirname(os.path.abspath(__file__)), 'icons', 'rstudio.svg')

0 commit comments

Comments
 (0)