Skip to content

Commit

Permalink
Permeate tmp_path in kaledio to choreo.Browser
Browse files Browse the repository at this point in the history
  • Loading branch information
ayjayt committed Nov 14, 2024
1 parent a8f7a56 commit a442da8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/py/kaleido/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

def to_image_block(spec, f=None, topojson=None, mapbox_token=None, debug=None):
def to_image_block(spec, f=None, topojson=None, mapbox_token=None, debug=None, tmp_path=None):
if debug is None:
debug = "KALEIDO-DEBUG" in os.environ or "KALEIDO_DEBUG" in os.environ
try:
Expand All @@ -30,7 +30,7 @@ def to_image_block(spec, f=None, topojson=None, mapbox_token=None, debug=None):
def get_image():
nonlocal image
if debug: print("Calling to_image in thread", file=sys.stderr)
image = asyncio.run(to_image(spec, f, topojson, mapbox_token, debug=debug))
image = asyncio.run(to_image(spec, f, topojson, mapbox_token, debug=debug, tmp_path=tmp_path))
t = Thread(target=get_image)
if debug: print("Calling thread start", file=sys.stderr)
t.start()
Expand All @@ -40,17 +40,17 @@ def get_image():
except RuntimeError:
if debug: print("No loop, no thread", file=sys.stderr)
pass
return asyncio.run(to_image(spec, f, topojson, mapbox_token, debug=debug,))
return asyncio.run(to_image(spec, f, topojson, mapbox_token, debug=debug, tmp_path=tmp_path))

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

async with (
Browser(headless=True, debug=debug, debug_browser=debug) as browser,
Browser(headless=True, debug=debug, debug_browser=debug, tmp_path=tmp_path) as browser,
atimeout.timeout(timeout)):
async def print_all(r):
print(f"All subscription: {r}", file=sys.stderr)
Expand Down
3 changes: 2 additions & 1 deletion src/py/kaleido/scopes/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, plotlyjs=None, mathjax=None, topojson=None, mapbox_access_tok
self.debug=debug
if tmp_path is None:
tmp_path = os.environ.get("KALEIDO_TMP_PATH", None)
self._tmp_path = tmp_path
# TODO: #2 This is deprecated, this whole FILE is deprecated
self._plotlyjs = plotlyjs
self._topojson = topojson
Expand Down Expand Up @@ -229,7 +230,7 @@ def transform(self, figure, format=None, width=None, height=None, scale=None, de
# Write to process and read result within a lock so that can be
# sure we're reading the response to our request
with _proc_lock:
img = kaleido.to_image_block(spec, Path(self._tempfile.name).absolute(), self._topojson, self._mapbox_access_token, debug=debug)
img = kaleido.to_image_block(spec, Path(self._tempfile.name).absolute(), self._topojson, self._mapbox_access_token, debug=debug, tmp_path=self._tmp_path)

return img

Expand Down

0 comments on commit a442da8

Please sign in to comment.