Skip to content

Commit

Permalink
Merge pull request #405 from doddgray/fix_ipython_filename
Browse files Browse the repository at this point in the history
Use tempfile if called from IPython
  • Loading branch information
sebastian-goeldi authored Jun 26, 2024
2 parents 230b9c8 + 35a3678 commit 490e963
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/kfactory/kcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7568,6 +7568,7 @@ def show(
and not the main KCLayout.
"""
import inspect
import tempfile

delete = False
delete_lyrdb = False
Expand All @@ -7577,11 +7578,14 @@ def show(
try:
stk = inspect.getouterframes(inspect.currentframe())
frame = stk[2]
name = (
Path(frame.filename).stem + "_" + frame.function
if frame.function != "<module>"
else Path(frame.filename).stem
)
frame_filename_stem = Path(frame.filename).stem
if frame_filename_stem.startswith("<ipython-input"): # IPython Case
name = "ipython"
else: # Normal Python kernel case
if frame.function != "<module>":
name = frame_filename_stem + "_" + frame.function
else:
name = frame_filename_stem
except Exception:
try:
from __main__ import __file__ as mf
Expand Down

0 comments on commit 490e963

Please sign in to comment.