Skip to content

Commit

Permalink
chore(weave): Legacy Refactor pt13 (#2231)
Browse files Browse the repository at this point in the history
* move to legacy: util

* move to legacy: filesystem

* move to legacy: weave_http
  • Loading branch information
andrewtruong authored Aug 28, 2024
1 parent 42d5483 commit a32d3cc
Show file tree
Hide file tree
Showing 31 changed files with 48 additions and 64 deletions.
2 changes: 1 addition & 1 deletion weave/legacy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from .. import weave_internal as _weave_internal

from .. import util as _util
from weave.legacy import util as _util

from weave.legacy import context as _context
from .. import weave_init as _weave_init
Expand Down
3 changes: 2 additions & 1 deletion weave/legacy/artifact_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import typing
from datetime import datetime

from weave import filesystem, util
from weave.legacy import filesystem
from weave import weave_types as types
from weave.legacy import (
artifact_fs,
Expand All @@ -19,6 +19,7 @@
file_base,
file_util,
uris,
util,
)

WORKING_DIR_PREFIX = "__working__"
Expand Down
6 changes: 2 additions & 4 deletions weave/legacy/artifact_wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
from wandb.apis.public import api as wb_public
from wandb.sdk.lib.hashutil import b64_to_hex_id, hex_to_b64_id

from weave import (
filesystem,
util,
)
from weave import weave_types as types
from weave.legacy import (
filesystem,
urls,
errors,
engine_trace,
Expand All @@ -29,6 +26,7 @@
memo,
uris,
wandb_client_api,
util,
)
from weave.legacy.wandb_interface import wandb_artifact_pusher

Expand Down
2 changes: 1 addition & 1 deletion weave/legacy/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import typing
from urllib.parse import urlparse

from weave import util
from weave.legacy import util
from weave.legacy import urls, client, context_state
from weave.legacy.client_interface import ClientInterface

Expand Down
2 changes: 1 addition & 1 deletion weave/legacy/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import typing
from dataclasses import dataclass

from weave import util
from weave.legacy import util
from weave import weave_types as types
from weave.legacy import graph, memo, op_args, op_def, pyfunc_type_util, registry_mem, errors
from weave.legacy.language_features.tagging.is_tag_getter import is_tag_getter
Expand Down
2 changes: 1 addition & 1 deletion weave/legacy/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from distutils.util import strtobool
from urllib.parse import urlparse
from weave.legacy import errors
from .. import util
from weave.legacy import util

if typing.TYPE_CHECKING:
from weave.legacy import logs
Expand Down
2 changes: 1 addition & 1 deletion weave/legacy/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pathlib
import typing

from weave import filesystem
from weave.legacy import filesystem
from weave.legacy import cache, environment, path_util


Expand Down
4 changes: 1 addition & 3 deletions weave/filesystem.py → weave/legacy/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
from aiofiles.threadpool import binary as aiofiles_binary
from aiofiles.threadpool import text as aiofiles_text

from weave.legacy import cache, engine_trace, environment, errors

from . import util
from weave.legacy import cache, engine_trace, environment, errors, util

tracer = engine_trace.tracer() # type: ignore
async_utime = aiofiles_os.wrap(os.utime) # type: ignore
Expand Down
6 changes: 2 additions & 4 deletions weave/legacy/io_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@

import aioprocessing

from weave import (
filesystem,
weave_http,
)
from weave.legacy import (
weave_http,
filesystem,
errors,
engine_trace,
server_error_handling,
Expand Down
4 changes: 1 addition & 3 deletions weave/legacy/ops_domain/run_history/history_op_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import pyarrow as pa
from pyarrow import parquet as pq

from weave import (
util,
)
from weave import weave_types as types
from weave.legacy.api import use
from weave.legacy import (
util,
errors,
engine_trace,
registry_mem,
Expand Down
3 changes: 2 additions & 1 deletion weave/legacy/ops_domain/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import typing

from weave import util, weave_internal
from weave import weave_internal
from weave import weave_types as types
from weave.legacy.api import op, weave_class
from weave.legacy import (
Expand All @@ -16,6 +16,7 @@
wandb_util,
engine_trace,
errors,
util,
)
from weave.legacy import timestamp as weave_timestamp
from weave.legacy.ops_domain import trace_tree, wbmedia
Expand Down
3 changes: 2 additions & 1 deletion weave/legacy/panels_py/panel_autoboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import typing

import weave
from weave import util, weave_internal
from weave import weave_internal
from weave.legacy.panels import panel_plot
from weave.legacy.panels_py.generator_templates import template_registry
from weave.legacy import util


@weave.type()
Expand Down
4 changes: 2 additions & 2 deletions weave/legacy/panels_py/panel_llm_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import typing

import weave
from weave import util, weave_internal
from weave import weave_internal
from weave import weave_internal as internal
from weave import weave_types as types
from weave.legacy import dispatch
from weave.legacy import util, dispatch
from weave.legacy.panels import panel_board, panel_group
from weave.legacy.panels_py import panel_autoboard
from weave.legacy.panels_py.generator_templates import template_registry
Expand Down
4 changes: 2 additions & 2 deletions weave/legacy/panels_py/panel_trace_monitor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os

import weave
from weave import util, weave_internal
from weave import weave_internal
from weave import weave_internal as internal
from weave import weave_types as types
from weave.legacy import dispatch, graph
from weave.legacy import util, dispatch, graph
from weave.legacy.panels import panel_board, panel_group, panel_trace
from weave.legacy.panels.panel_trace_span import TraceSpanModelPanel, TraceSpanPanel
from weave.legacy.panels_py import panel_autoboard
Expand Down
2 changes: 1 addition & 1 deletion weave/legacy/runfiles_wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import typing

from weave.legacy import environment as weave_env
from weave import filesystem
from weave.legacy import filesystem
from weave import weave_types as types
from weave.legacy import (
artifact_fs,
Expand Down
2 changes: 1 addition & 1 deletion weave/legacy/scripts/syndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pyarrow as pa
from scipy.signal import butter, filtfilt

from ... import util
from weave.legacy import util
from ..ops_arrow import ArrowWeaveList

value_fns: list[typing.Any] = [
Expand Down
3 changes: 2 additions & 1 deletion weave/legacy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
value_or_error,
wandb_api,
logs,
util,
)
from weave.legacy.language_features.tagging import tag_store
from weave.legacy.language_features.tagging.tag_store import isolated_tagging_context

from .. import storage, util, weave_types
from .. import storage, weave_types

# A function to monkeypatch the request post method
# def patch_request_post():
Expand Down
2 changes: 1 addition & 1 deletion weave/legacy/server_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from werkzeug import http as werkzeug_http
from weave.legacy import errors

from .. import util
from weave.legacy import util


class WeaveInternalHttpException(werkzeug_exceptions.HTTPException):
Expand Down
2 changes: 1 addition & 1 deletion weave/legacy/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from IPython.display import IFrame, display

from weave.legacy import storage, artifact_fs, context, errors, graph, ops, node_ref, panel, ref_base
from weave import util
from weave.legacy import util
from . import usage_analytics
from .. import weave_types as types
from . import weavejs_fixes
Expand Down
16 changes: 8 additions & 8 deletions weave/util.py → weave/legacy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
# import ipynbname
import typing

from .legacy.errors import WeaveFingerprintErrorMixin
from weave.legacy.errors import WeaveFingerprintErrorMixin

sentry_inited = False


def init_sentry():
def init_sentry(): # type: ignore
global sentry_inited
if sentry_inited:
return
Expand Down Expand Up @@ -59,11 +59,11 @@ def capture_exception_with_sentry_if_available(
# return ipynbname.name()


def get_hostname():
def get_hostname(): # type: ignore
return socket.gethostname()


def get_pid():
def get_pid(): # type: ignore
return os.getpid()


Expand Down Expand Up @@ -95,7 +95,7 @@ def parse_number_env_var(name: str) -> typing.Optional[typing.Union[int, float]]
return float(raw_val)


def find_names(obj):
def find_names(obj): # type: ignore
if hasattr(obj, "name"):
return [obj.name]
frame = inspect.currentframe()
Expand All @@ -110,15 +110,15 @@ def find_names(obj):
return obj_names


def is_colab():
def is_colab(): # type: ignore
import importlib

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


def is_notebook() -> bool:
if is_colab():
if is_colab(): # type: ignore[no-untyped-call]
return True
try:
from IPython import get_ipython
Expand All @@ -135,7 +135,7 @@ def is_notebook() -> bool:
return True


def is_pandas_dataframe(obj):
def is_pandas_dataframe(obj): # type: ignore
try:
import pandas as pd
except ImportError:
Expand Down
3 changes: 1 addition & 2 deletions weave/legacy/wandb_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
from requests.auth import HTTPBasicAuth
from wandb.sdk.lib import hashutil

from weave import filesystem, weave_http
from weave.legacy import environment as weave_env
from weave.legacy import artifact_wandb, cache, errors, wandb_api, engine_trace
from weave.legacy import filesystem, artifact_wandb, cache, errors, wandb_api, engine_trace, weave_http

tracer = engine_trace.tracer() # type: ignore

Expand Down
4 changes: 1 addition & 3 deletions weave/weave_http.py → weave/legacy/weave_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import requests.auth
import yarl

from weave.legacy import engine_trace, server_error_handling

from . import filesystem
from weave.legacy import engine_trace, filesystem, server_error_handling

logging.getLogger("aiohttp.access").setLevel(logging.WARNING)
logging.getLogger("aiohttp.client").setLevel(logging.WARNING)
Expand Down
4 changes: 2 additions & 2 deletions weave/test_scripts/wandb_artifact_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
artifact_wandb,
async_map,
engine_trace,
filesystem,
wandb_api,
wandb_file_manager,
weave_http,
)

from .. import filesystem, weave_http

tracer = engine_trace.tracer() # type: ignore


Expand Down
3 changes: 1 addition & 2 deletions weave/tests/fixture_fakewandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
import wandb

import weave
from weave import util

# Note: We're mocking out the whole io_service right now. This is too
# high level and doesn't test the actual io implementation. We should
# mock wandb_api instead probably.
from weave.legacy import io_service, wandb_api, wandb_client_api
from weave.legacy import io_service, util, wandb_api, wandb_client_api
from weave.legacy.artifact_wandb import (
WandbArtifact,
WandbArtifactManifest,
Expand Down
4 changes: 1 addition & 3 deletions weave/tests/legacy/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import pytest

from weave.legacy import environment, errors

from ... import filesystem
from weave.legacy import environment, errors, filesystem


@pytest.fixture()
Expand Down
4 changes: 1 addition & 3 deletions weave/tests/legacy/test_io_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import pytest

from weave.legacy import io_service

from ... import filesystem
from weave.legacy import filesystem, io_service


@pytest.mark.timeout(10)
Expand Down
2 changes: 1 addition & 1 deletion weave/tests/legacy/test_relpath_no_syscalls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from ...util import relpath_no_syscalls
from weave.legacy.util import relpath_no_syscalls


@pytest.mark.parametrize(
Expand Down
3 changes: 1 addition & 2 deletions weave/trace/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
from typing import Any, Callable, Iterator, Optional, Union

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

# TODO: type_serializers is imported here to trigger registration of the image serializer.
# There is probably a better place for this, but including here for now to get the fix in.
from .. import (
type_serializers, # noqa: F401
util,
weave_init,
)
from . import context, weave_client
Expand Down
Loading

0 comments on commit a32d3cc

Please sign in to comment.