Skip to content

Commit 9e5ffa3

Browse files
authored
Merge pull request #55 from rediscovery-io/set_remo_home
Set remo home
2 parents fe1e772 + d52dbfa commit 9e5ffa3

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

remo/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
_sdk = None
66

77

8-
def connect(server: str = '', email: str = '', password: str = '', viewer: str = 'browser'):
8+
def connect(server: str = '', email: str = '', password: str = '', viewer: str = 'browser', remo_home: str = None):
99
"""
1010
Connect to a remo server.
1111
If no parameters are passed, it connects to a local running remo server. To connect to a remote remo, specify connection details.
@@ -15,7 +15,13 @@ def connect(server: str = '', email: str = '', password: str = '', viewer: str =
1515
email: email address used for authentication
1616
password: password used for authentication
1717
(optional) viewer: viewer to use, one between 'browser', 'electron' and 'jupyter'
18+
(optional) remo_home: location of remo home
1819
"""
20+
21+
if remo_home:
22+
from .config import set_REMO_HOME
23+
set_REMO_HOME(remo_home)
24+
1925
if not (server and email and password):
2026
from .config import Config
2127
config = Config.load()

remo/config.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
import os
33
from pathlib import Path
44

5-
REMO_HOME = os.getenv('REMO_HOME', str(Path.home().joinpath('.remo')))
5+
REMO_HOME_ENV = 'REMO_HOME'
6+
7+
8+
def REMO_HOME():
9+
return os.getenv(REMO_HOME_ENV, str(Path.home().joinpath('.remo')))
10+
11+
12+
def set_REMO_HOME(path: str):
13+
if not os.path.exists(path):
14+
os.makedirs(path)
15+
os.environ[REMO_HOME_ENV] = path
616

717

818
class Config:
@@ -28,7 +38,7 @@ def server_url(self):
2838
return '{}:{}'.format(self.server, self.port)
2939

3040
@staticmethod
31-
def load(config_path: str = str(os.path.join(REMO_HOME, 'remo.json'))):
41+
def load(config_path: str = str(os.path.join(REMO_HOME(), 'remo.json'))):
3242
if not os.path.exists(config_path):
3343
return None
3444

remo/viewer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import platform
44
import subprocess
55
from abc import abstractmethod, ABCMeta
6-
from pathlib import Path
76
import webbrowser
87
import uuid
98

9+
from remo.config import REMO_HOME
10+
1011

1112
class AbstractViewer(metaclass=ABCMeta):
1213
@abstractmethod
@@ -67,7 +68,6 @@ def browse(self, url: str):
6768

6869
class ElectronViewer(AbstractViewer):
6970
exe_path = {'Linux': 'app/remo', 'Darwin': 'app/remo.app/Contents/MacOS/remo', 'Windows': 'app/remo.exe'}
70-
REMO_HOME = os.getenv('REMO_HOME', str(Path.home().joinpath('.remo')))
7171
url_rxp = re.compile(r'(http[s]?://[.\w-]+)(:([0-9]+))?/?(.+)?')
7272

7373
def browse(self, url):
@@ -86,7 +86,7 @@ def build_cmd(executable, **kwargs):
8686
return '{} {}'.format(executable, ' '.join('--{}={}'.format(k, v) for k, v in kwargs.items() if v))
8787

8888
def get_remo_path(self):
89-
return str(os.path.join(self.REMO_HOME, self.exe_path.get(platform.system())))
89+
return str(os.path.join(REMO_HOME(), self.exe_path.get(platform.system())))
9090

9191

9292
def factory(name: str):

0 commit comments

Comments
 (0)