Skip to content

Commit 010fcde

Browse files
committed
if not provided, create temp HOME and notebook dirs
1 parent 72980ee commit 010fcde

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

anaconda-project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ commands:
2525
env_spec: rfjl37
2626

2727
atest:
28-
unix: python -m atest.run
28+
unix: rm -rf _artifacts/test_output && python -m atest.run
2929
env_spec: rfjl37
3030

3131

src/JupyterLibrary/keywords/server.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import os
2+
import shutil
13
import subprocess
4+
import tempfile
25
import time
6+
from os.path import join
37

48
from robot.libraries.BuiltIn import BuiltIn
59
from SeleniumLibrary.base import LibraryComponent, keyword
@@ -9,6 +13,7 @@
913

1014
class ServerKeywords(LibraryComponent):
1115
_nbserver_handles = []
16+
_nbserver_tmpdirs = {}
1217

1318
@keyword
1419
def start_new_jupyter_server(self, command="jupyter", *arguments, **configuration):
@@ -18,8 +23,23 @@ def start_new_jupyter_server(self, command="jupyter", *arguments, **configuratio
1823
if not arguments:
1924
arguments = self.build_jupyter_server_arguments()
2025

26+
tmpdir = tempfile.mkdtemp()
27+
28+
if "--notebook-dir" not in arguments:
29+
notebook_dir = join(tmpdir, "notebooks")
30+
os.mkdir(notebook_dir)
31+
arguments += ["--notebook-dir", notebook_dir]
32+
33+
if "env:HOME" not in configuration:
34+
home_dir = join(tmpdir, "home")
35+
os.mkdir(home_dir)
36+
configuration["env:HOME"] = home_dir
37+
2138
handle = plib.start_process("jupyter", *arguments, **configuration)
39+
2240
self._nbserver_handles += [handle]
41+
self._nbserver_tmpdirs[handle] = tmpdir
42+
2343
return handle
2444

2545
@keyword
@@ -83,7 +103,11 @@ def terminate_all_jupyter_servers(self, kill=False):
83103
plib.terminate_process(handle, kill=kill)
84104
terminated += 1
85105

106+
for tmpdir in self._nbserver_tmpdirs.values():
107+
shutil.rmtree(tmpdir)
108+
86109
self._nbserver_handles = []
110+
self._nbserver_tmpdirs = {}
87111

88112
return terminated
89113

0 commit comments

Comments
 (0)