Skip to content

Commit

Permalink
chore(weave): Legacy Refactor pt22 (#2240)
Browse files Browse the repository at this point in the history
* split: further split trace and legacy errors

* split: make separate trace and legacy utils

* delete: extraneous import
  • Loading branch information
andrewtruong authored Aug 28, 2024
1 parent eaa7b6a commit 8ff732b
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 24 deletions.
1 change: 0 additions & 1 deletion weave/tests/trace/op_versioning_solo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np

import weave
from weave.legacy.weave import artifact_fs


@weave.op()
Expand Down
2 changes: 1 addition & 1 deletion weave/tests/trace/test_op_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

import weave
from weave.legacy.weave import artifact_fs, derive_op, op_def
from weave.legacy.weave import artifact_fs, derive_op
from weave.trace_server.trace_server_interface import FileContentReadReq, ObjReadReq


Expand Down
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
2 changes: 1 addition & 1 deletion weave/trace/client_context/weave_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING, Optional

from weave.legacy.weave import context_state
from weave.legacy.weave.errors import WeaveInitError
from weave.trace.errors import WeaveInitError

if TYPE_CHECKING:
from weave.trace.weave_client import WeaveClient
Expand Down
27 changes: 21 additions & 6 deletions weave/trace/errors.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
class Error(Exception):
pass
class Error(Exception): ...


class InternalError(Error):
pass
class InternalError(Error): ...


class OpCallError(Error):
pass
class OpCallError(Error): ...


class WeaveTypeError(Error): ...


class WeaveSerializeError(Error): ...


class WeaveOpSerializeError(WeaveSerializeError): ...


class WeaveInitError(Error): ...


class WeaveDefinitionError(Error): ...


class WeaveWandbAuthenticationException(Error): ...
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
5 changes: 2 additions & 3 deletions weave/trace/serve_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
except ImportError:
from typing_extensions import Annotated # type: ignore

from weave.legacy.weave import cache, op_args, pyfunc_type_util
from weave.legacy.weave import cache, op_args, pyfunc_type_util, weave_pydantic
from weave.legacy.weave.wandb_api import WandbApiAsync
from weave.trace import errors
from weave.trace.op import Op
from weave.trace.refs import ObjectRef

from ..legacy.weave import errors, weave_pydantic

key_cache: cache.LruTimeWindowCache[str, typing.Optional[bool]] = (
cache.LruTimeWindowCache(datetime.timedelta(minutes=5))
)
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
8 changes: 2 additions & 6 deletions weave/trace/weave_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@
TraceServerInterface,
)

if typing.TYPE_CHECKING:
from ..legacy.weave import ref_base


# Controls if objects can have refs to projects not the WeaveClient project.
# If False, object refs with with mismatching projects will be recreated.
# If True, use existing ref to object in other project.
Expand Down Expand Up @@ -904,10 +900,10 @@ def _set_call_display_name(
def _remove_call_display_name(self, call: Call) -> None:
self._set_call_display_name(call, None)

def _ref_input_to(self, ref: "ref_base.Ref") -> Sequence[Call]:
def _ref_input_to(self, ref: Ref) -> Sequence[Call]:
raise NotImplementedError()

def _ref_value_input_to(self, ref: "ref_base.Ref") -> list[Call]:
def _ref_value_input_to(self, ref: Ref) -> list[Call]:
raise NotImplementedError()

def _ref_output_of(self, ref: ObjectRef) -> typing.Optional[Call]:
Expand Down
3 changes: 1 addition & 2 deletions weave/trace/weave_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import typing

from weave.legacy.weave import errors
from weave.trace import autopatch, init_message, trace_sentry, weave_client
from weave.trace import autopatch, errors, init_message, trace_sentry, weave_client
from weave.trace.client_context import weave_client as weave_client_context
from weave.trace_server import remote_http_trace_server, sqlite_trace_server

Expand Down

0 comments on commit 8ff732b

Please sign in to comment.