Skip to content

Commit

Permalink
split: make separate trace and legacy utils
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtruong committed Aug 28, 2024
1 parent e9f6021 commit d7a84b1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion weave/trace/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import time
from typing import Any, Callable, Iterator, Optional, Union

from weave.legacy.weave import urls, util
from weave.legacy.weave import urls
from weave.trace import util
from weave.trace.call_context import get_current_call
from weave.trace.client_context import weave_client as weave_client_context

Expand Down
3 changes: 1 addition & 2 deletions weave/trace/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

from rich.table import Table

from weave.legacy.weave import util
from weave.trace import rich_pydantic_util
from weave.trace import rich_pydantic_util, util
from weave.trace.client_context import weave_client as weave_client_context
from weave.trace.refs import parse_uri
from weave.trace.rich_container import AbstractRichContainer
Expand Down
2 changes: 1 addition & 1 deletion weave/trace/rich_pydantic_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rich.console import Console
from rich.table import Table

from weave.legacy.weave import util
from weave.trace import util


def dict_to_table(d: dict[str, Any]) -> Table:
Expand Down
25 changes: 25 additions & 0 deletions weave/trace/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,31 @@ def run(self) -> None:
self.context.run(super().run)


def is_colab(): # type: ignore
import importlib

spec = importlib.util.find_spec("google.colab")
return bool(spec)


def is_notebook() -> bool:
if is_colab(): # type: ignore[no-untyped-call]
return True
try:
from IPython import get_ipython
except ImportError:
return False
else:
ip = get_ipython()
if ip is None:
return False
if "IPKernelApp" not in ip.config:
return False
# if "VSCODE_PID" in os.environ:
# return False
return True


# rename for cleaner export
ThreadPoolExecutor = ContextAwareThreadPoolExecutor
Thread = ContextAwareThread
Expand Down

0 comments on commit d7a84b1

Please sign in to comment.