Skip to content

Commit a442da8

Browse files
committed
Permeate tmp_path in kaledio to choreo.Browser
1 parent a8f7a56 commit a442da8

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/py/kaleido/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
_scope_flags_ = ("plotlyjs", "mathjax", "topojson", "mapbox_access_token")
2121

22-
def to_image_block(spec, f=None, topojson=None, mapbox_token=None, debug=None):
22+
def to_image_block(spec, f=None, topojson=None, mapbox_token=None, debug=None, tmp_path=None):
2323
if debug is None:
2424
debug = "KALEIDO-DEBUG" in os.environ or "KALEIDO_DEBUG" in os.environ
2525
try:
@@ -30,7 +30,7 @@ def to_image_block(spec, f=None, topojson=None, mapbox_token=None, debug=None):
3030
def get_image():
3131
nonlocal image
3232
if debug: print("Calling to_image in thread", file=sys.stderr)
33-
image = asyncio.run(to_image(spec, f, topojson, mapbox_token, debug=debug))
33+
image = asyncio.run(to_image(spec, f, topojson, mapbox_token, debug=debug, tmp_path=tmp_path))
3434
t = Thread(target=get_image)
3535
if debug: print("Calling thread start", file=sys.stderr)
3636
t.start()
@@ -40,17 +40,17 @@ def get_image():
4040
except RuntimeError:
4141
if debug: print("No loop, no thread", file=sys.stderr)
4242
pass
43-
return asyncio.run(to_image(spec, f, topojson, mapbox_token, debug=debug,))
43+
return asyncio.run(to_image(spec, f, topojson, mapbox_token, debug=debug, tmp_path=tmp_path))
4444

45-
async def to_image(spec, f=None, topojson=None, mapbox_token=None, debug=None, timeout=60):
45+
async def to_image(spec, f=None, topojson=None, mapbox_token=None, debug=None, timeout=60, tmp_path=None):
4646
if debug is None:
4747
debug = "KALEIDO-DEBUG" in os.environ or "KALEIDO_DEBUG" in os.environ
4848
def check_error(res):
4949
if 'error' in res:
5050
raise RuntimeError(str(res))
5151

5252
async with (
53-
Browser(headless=True, debug=debug, debug_browser=debug) as browser,
53+
Browser(headless=True, debug=debug, debug_browser=debug, tmp_path=tmp_path) as browser,
5454
atimeout.timeout(timeout)):
5555
async def print_all(r):
5656
print(f"All subscription: {r}", file=sys.stderr)

src/py/kaleido/scopes/plotly.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, plotlyjs=None, mathjax=None, topojson=None, mapbox_access_tok
3535
self.debug=debug
3636
if tmp_path is None:
3737
tmp_path = os.environ.get("KALEIDO_TMP_PATH", None)
38+
self._tmp_path = tmp_path
3839
# TODO: #2 This is deprecated, this whole FILE is deprecated
3940
self._plotlyjs = plotlyjs
4041
self._topojson = topojson
@@ -229,7 +230,7 @@ def transform(self, figure, format=None, width=None, height=None, scale=None, de
229230
# Write to process and read result within a lock so that can be
230231
# sure we're reading the response to our request
231232
with _proc_lock:
232-
img = kaleido.to_image_block(spec, Path(self._tempfile.name).absolute(), self._topojson, self._mapbox_access_token, debug=debug)
233+
img = kaleido.to_image_block(spec, Path(self._tempfile.name).absolute(), self._topojson, self._mapbox_access_token, debug=debug, tmp_path=self._tmp_path)
233234

234235
return img
235236

0 commit comments

Comments
 (0)