Skip to content

Commit

Permalink
streamlit support
Browse files Browse the repository at this point in the history
  • Loading branch information
safranchik committed Jul 14, 2024
1 parent 9602258 commit 1cbecd1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cubyc/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ def query(
log.error("Comments table can only be queried from remote repositories.")
exit()

loop = asyncio.get_event_loop()

# check if asyncio event loop is already running

try:
loop = asyncio.get_event_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

if branch == "all" or branch is None:
branch = Repo(path=utils.get_caller_path()).active_branch.name
Expand Down
18 changes: 17 additions & 1 deletion cubyc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def get_caller_path():

path = os.path.abspath("")

if not is_running_in_notebook():
if not is_running_in_notebook() and not is_running_in_streamlit():
# Get the current frame
current_frame = inspect.currentframe()

Expand Down Expand Up @@ -393,3 +393,19 @@ def is_running_in_notebook() -> bool:
return False

return 'IPKernelApp' in ipython.config


def is_running_in_streamlit() -> bool:
"""
Check if the code is running in a Streamlit app.
Returns
-------
bool
True if running in a Streamlit app, False otherwise.
"""
try:
import streamlit.runtime.scriptrunner.script_run_context
return True
except ImportError:
return False

0 comments on commit 1cbecd1

Please sign in to comment.