From 6c780e8e6f83a1570e4d9af5dfb3137c15e55ea2 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 27 Aug 2024 11:28:16 -0400 Subject: [PATCH] move to legacy: ref_base --- weave/legacy/arrow/list_.py | 2 +- weave/legacy/artifact_base.py | 2 +- weave/legacy/artifact_fs.py | 4 ++-- weave/legacy/artifact_mem.py | 2 +- weave/legacy/execute.py | 2 +- weave/legacy/execute_fast.py | 2 +- weave/legacy/graph_mapper.py | 2 +- weave/legacy/mappers_arrow.py | 3 ++- weave/legacy/mappers_publisher.py | 3 ++- weave/legacy/mappers_python_def.py | 3 ++- weave/legacy/node_ref.py | 2 +- weave/legacy/object_context.py | 2 +- weave/legacy/ops_primitives/artifacts.py | 4 ++-- weave/legacy/ops_primitives/weave_api.py | 2 +- weave/{ => legacy}/ref_base.py | 11 +++++------ weave/legacy/show.py | 4 ++-- weave/legacy/trace_legacy.py | 2 +- weave/legacy/trace_local.py | 2 +- weave/legacy/uris.py | 2 +- weave/query_api.py | 2 +- weave/ref_util.py | 2 +- weave/storage.py | 3 ++- weave/tests/legacy/test_mutation2.py | 3 +-- weave/tests/legacy/test_wb_end_to_end.py | 2 +- weave/tests/trace/test_evaluate.py | 2 +- weave/tests/trace/test_weaveflow.py | 2 +- weave/trace/box.py | 2 +- weave/trace/weave_client.py | 2 +- weave/weave_types.py | 4 ++-- 29 files changed, 41 insertions(+), 39 deletions(-) rename weave/{ => legacy}/ref_base.py (96%) diff --git a/weave/legacy/arrow/list_.py b/weave/legacy/arrow/list_.py index 6db149220d5..f8a7f09bbb3 100644 --- a/weave/legacy/arrow/list_.py +++ b/weave/legacy/arrow/list_.py @@ -12,7 +12,6 @@ from weave import ( errors, - ref_base, ref_util, weave_internal, ) @@ -27,6 +26,7 @@ op_def, op_def_type, node_ref, + ref_base, ) from weave.legacy.arrow.arrow import ( ArrowWeaveListType, diff --git a/weave/legacy/artifact_base.py b/weave/legacy/artifact_base.py index 9e62e34fa83..02b2e35d213 100644 --- a/weave/legacy/artifact_base.py +++ b/weave/legacy/artifact_base.py @@ -8,7 +8,7 @@ import typing from weave import weave_types as types -from weave import ref_base +from weave.legacy import ref_base class Artifact: diff --git a/weave/legacy/artifact_fs.py b/weave/legacy/artifact_fs.py index b753b501974..f09e110e612 100644 --- a/weave/legacy/artifact_fs.py +++ b/weave/legacy/artifact_fs.py @@ -6,9 +6,9 @@ import os import typing -from weave import errors, ref_base, ref_util +from weave import errors, ref_util from weave import weave_types as types -from weave.legacy import artifact_base, file_base, object_context, uris +from weave.legacy import artifact_base, file_base, object_context, ref_base, uris from weave.legacy.language_features.tagging import tag_store if typing.TYPE_CHECKING: diff --git a/weave/legacy/artifact_mem.py b/weave/legacy/artifact_mem.py index 5e6f63f9159..58471d6460f 100644 --- a/weave/legacy/artifact_mem.py +++ b/weave/legacy/artifact_mem.py @@ -3,7 +3,7 @@ from . import artifact_base from weave import weave_types as types from weave import errors -from weave import ref_base +from weave.legacy import ref_base class MemArtifact(artifact_base.Artifact): diff --git a/weave/legacy/execute.py b/weave/legacy/execute.py index 916d9646f82..8c9bb02475e 100644 --- a/weave/legacy/execute.py +++ b/weave/legacy/execute.py @@ -12,7 +12,6 @@ from weave import ( environment, errors, - ref_base, ) from weave import weave_types as types @@ -25,6 +24,7 @@ from weave.legacy import ( engine_trace, parallelism, + ref_base, registry_mem, box, compile, diff --git a/weave/legacy/execute_fast.py b/weave/legacy/execute_fast.py index 91a8e640b5b..f4b571c86ea 100644 --- a/weave/legacy/execute_fast.py +++ b/weave/legacy/execute_fast.py @@ -2,12 +2,12 @@ from weave import ( errors, - ref_base, weave_internal, ) from weave import weave_types as types from weave.legacy import ( engine_trace, + ref_base, registry_mem, box, compile, diff --git a/weave/legacy/graph_mapper.py b/weave/legacy/graph_mapper.py index 8e0b6cce626..f2c68399433 100644 --- a/weave/legacy/graph_mapper.py +++ b/weave/legacy/graph_mapper.py @@ -1,4 +1,4 @@ -from weave import ref_base +from weave.legacy import ref_base from weave import weave_types as types from weave.legacy import graph, mappers, node_ref from weave.legacy import mappers_python_def as mappers_python diff --git a/weave/legacy/mappers_arrow.py b/weave/legacy/mappers_arrow.py index 6b3ed376577..2f1ca904ef1 100644 --- a/weave/legacy/mappers_arrow.py +++ b/weave/legacy/mappers_arrow.py @@ -5,7 +5,7 @@ import pyarrow as pa -from weave import errors, ref_base +from weave import errors from weave import weave_types as types from weave.legacy import ( arrow_util, @@ -15,6 +15,7 @@ mappers_weave, node_ref, partial_object, + ref_base, ) from weave.legacy import mappers_python_def as mappers_python from weave.legacy.arrow import arrow diff --git a/weave/legacy/mappers_publisher.py b/weave/legacy/mappers_publisher.py index f9facd494e7..2e57541b60e 100644 --- a/weave/legacy/mappers_publisher.py +++ b/weave/legacy/mappers_publisher.py @@ -2,7 +2,7 @@ import dataclasses import typing -from weave import errors, ref_base, storage, weave_internal +from weave import errors, storage, weave_internal from weave import weave_types as types from weave.legacy.node_ref import ref_to_node @@ -15,6 +15,7 @@ graph, mappers, mappers_python_def, + ref_base, ) from weave.legacy.artifact_wandb import likely_commit_hash from weave.legacy.language_features.tagging import tag_store, tagged_value_type diff --git a/weave/legacy/mappers_python_def.py b/weave/legacy/mappers_python_def.py index 40359e01d8c..88a38b59af1 100644 --- a/weave/legacy/mappers_python_def.py +++ b/weave/legacy/mappers_python_def.py @@ -4,7 +4,7 @@ import math import typing -from weave import errors, ref_base, storage +from weave import errors, storage from weave import weave_types as types from weave.legacy import ( artifact_fs, @@ -12,6 +12,7 @@ mappers, mappers_python, mappers_weave, + ref_base, val_const, ) from weave.legacy import timestamp as weave_timestamp diff --git a/weave/legacy/node_ref.py b/weave/legacy/node_ref.py index 9c19030ba8f..47edbc6804b 100644 --- a/weave/legacy/node_ref.py +++ b/weave/legacy/node_ref.py @@ -3,7 +3,7 @@ from weave.legacy import graph -from .. import ref_base +from . import ref_base # Notes for the future: # - I added list.lookup to lookup rows in a list by ID. I think we probably should diff --git a/weave/legacy/object_context.py b/weave/legacy/object_context.py index 836fd054151..b8d916063e2 100644 --- a/weave/legacy/object_context.py +++ b/weave/legacy/object_context.py @@ -12,7 +12,7 @@ from typing import Any if typing.TYPE_CHECKING: - from weave import ref_base + from weave.legacy import ref_base from weave import weave_types as types from weave.legacy import box, uris diff --git a/weave/legacy/ops_primitives/artifacts.py b/weave/legacy/ops_primitives/artifacts.py index d48f86d9da2..d05c9223c8b 100644 --- a/weave/legacy/ops_primitives/artifacts.py +++ b/weave/legacy/ops_primitives/artifacts.py @@ -4,8 +4,8 @@ import typing from weave.query_api import op -from weave import ref_base, types -from weave.legacy import artifact_fs +from weave import types +from weave.legacy import artifact_fs, ref_base from weave.legacy.artifact_local import WORKING_DIR_PREFIX, LocalArtifact diff --git a/weave/legacy/ops_primitives/weave_api.py b/weave/legacy/ops_primitives/weave_api.py index 33ace6416b4..d59113a2997 100644 --- a/weave/legacy/ops_primitives/weave_api.py +++ b/weave/legacy/ops_primitives/weave_api.py @@ -4,13 +4,13 @@ from weave import ( errors, - ref_base, storage, weave_internal, ) from weave import weave_types as types from weave.query_api import mutation, op, weave_class from weave.legacy import ( + ref_base, registry_mem, artifact_fs, artifact_local, diff --git a/weave/ref_base.py b/weave/legacy/ref_base.py similarity index 96% rename from weave/ref_base.py rename to weave/legacy/ref_base.py index 120ff9fed6d..e7742d9eb65 100644 --- a/weave/ref_base.py +++ b/weave/legacy/ref_base.py @@ -6,19 +6,18 @@ from typing import Sequence from weave.client_context import weave_client as weave_client_context -from weave.legacy import box, context_state, object_context +from weave.legacy import box, context_state, object_context, uris from weave.legacy.language_features.tagging import tag_store -from . import errors -from . import weave_types as types -from .legacy import uris +from .. import errors +from .. import weave_types as types # We store Refs here if we can't attach them directly to the object REFS: weakref.WeakValueDictionary[int, "Ref"] = weakref.WeakValueDictionary() if typing.TYPE_CHECKING: - from . import weave_types as types - from .trace import weave_client + from .. import weave_types as types + from ..trace import weave_client def _map_to_ref_strs(obj: typing.Any) -> typing.Any: diff --git a/weave/legacy/show.py b/weave/legacy/show.py index df57367e12f..92ae3f7cf16 100644 --- a/weave/legacy/show.py +++ b/weave/legacy/show.py @@ -5,8 +5,8 @@ from IPython.display import IFrame, display -from weave.legacy import artifact_fs, context, graph, ops, node_ref, panel -from weave import errors, ref_base, storage, util +from weave.legacy import artifact_fs, context, graph, ops, node_ref, panel, ref_base +from weave import errors, storage, util from . import usage_analytics from .. import weave_types as types from . import weavejs_fixes diff --git a/weave/legacy/trace_legacy.py b/weave/legacy/trace_legacy.py index 3264585672d..3d9e6529cc4 100644 --- a/weave/legacy/trace_legacy.py +++ b/weave/legacy/trace_legacy.py @@ -3,7 +3,7 @@ from weave.legacy import artifact_local, graph, runs -from .. import ref_base +from . import ref_base from . import errors from .. import weave_types as types diff --git a/weave/legacy/trace_local.py b/weave/legacy/trace_local.py index bc1376d5e35..b210d313b09 100644 --- a/weave/legacy/trace_local.py +++ b/weave/legacy/trace_local.py @@ -6,9 +6,9 @@ from typing import Mapping from weave.legacy import artifact_local, graph, op_def, op_policy, runs +from . import ref_base from .. import ( - ref_base, storage, weave_internal, ) diff --git a/weave/legacy/uris.py b/weave/legacy/uris.py index dc1e562b80e..7ce5150f23b 100644 --- a/weave/legacy/uris.py +++ b/weave/legacy/uris.py @@ -5,7 +5,7 @@ from .. import errors if typing.TYPE_CHECKING: - from .. import ref_base + from . import ref_base @dataclasses.dataclass diff --git a/weave/query_api.py b/weave/query_api.py index 908c7e526fb..9f2140b8416 100644 --- a/weave/query_api.py +++ b/weave/query_api.py @@ -9,7 +9,7 @@ from weave.legacy import graph_mapper as _graph_mapper from . import storage as _storage -from . import ref_base as _ref_base +from .legacy import ref_base as _ref_base from weave.legacy import wandb_api as _wandb_api from . import weave_internal as _weave_internal diff --git a/weave/ref_util.py b/weave/ref_util.py index d2adf5a005f..968a584ca61 100644 --- a/weave/ref_util.py +++ b/weave/ref_util.py @@ -25,7 +25,7 @@ def val_with_relative_ref( ) -> typing.Any: from weave.legacy import context_state - from . import ref_base + from .legacy import ref_base # If we already have a ref, resolve it if isinstance(child_object, ref_base.Ref): diff --git a/weave/storage.py b/weave/storage.py index 8f0336d37c8..c87c1db4060 100644 --- a/weave/storage.py +++ b/weave/storage.py @@ -17,10 +17,11 @@ box, graph, mappers_python, + ref_base, timestamp, ) -from . import errors, ref_base +from . import errors from . import weave_types as types Ref = ref_base.Ref diff --git a/weave/tests/legacy/test_mutation2.py b/weave/tests/legacy/test_mutation2.py index 9fe786a3578..d344f10b0f9 100644 --- a/weave/tests/legacy/test_mutation2.py +++ b/weave/tests/legacy/test_mutation2.py @@ -1,6 +1,5 @@ import weave -from weave import ref_base -from weave.legacy import uris +from weave.legacy import ref_base, uris from ... import weave_internal diff --git a/weave/tests/legacy/test_wb_end_to_end.py b/weave/tests/legacy/test_wb_end_to_end.py index 1529cfff655..2232079248d 100644 --- a/weave/tests/legacy/test_wb_end_to_end.py +++ b/weave/tests/legacy/test_wb_end_to_end.py @@ -60,7 +60,7 @@ def _test_basic_publish(user_fixture): uri == f"wandb-artifact:///{user_fixture.username}/weave/list:0cdf3358dc939f961ca9/obj" ) - assert weave.ref_base.Ref.from_str(uri).get() == [1, 2, 3] + assert weave.legacy.ref_base.Ref.from_str(uri).get() == [1, 2, 3] # Example of end to end integration test diff --git a/weave/tests/trace/test_evaluate.py b/weave/tests/trace/test_evaluate.py index 0af269f1c88..b855eea3def 100644 --- a/weave/tests/trace/test_evaluate.py +++ b/weave/tests/trace/test_evaluate.py @@ -3,7 +3,7 @@ import pytest import weave -from weave import Dataset, Evaluation, Model, ref_base +from weave import Dataset, Evaluation, Model from weave.flow.scorer import MultiTaskBinaryClassificationF1 pytestmark = pytest.mark.webtest diff --git a/weave/tests/trace/test_weaveflow.py b/weave/tests/trace/test_weaveflow.py index ca3218dc98f..a41f4eba9d4 100644 --- a/weave/tests/trace/test_weaveflow.py +++ b/weave/tests/trace/test_weaveflow.py @@ -5,7 +5,7 @@ from pydantic import Field import weave -from weave import ref_base +from weave.legacy import ref_base pytestmark = pytest.mark.trace diff --git a/weave/trace/box.py b/weave/trace/box.py index 6662aedc113..1c39bf5e39f 100644 --- a/weave/trace/box.py +++ b/weave/trace/box.py @@ -10,7 +10,7 @@ import numpy as np -from weave.ref_base import Ref +from weave.legacy.ref_base import Ref T = TypeVar("T") diff --git a/weave/trace/weave_client.py b/weave/trace/weave_client.py index ce2ea38eea1..32a382f5999 100644 --- a/weave/trace/weave_client.py +++ b/weave/trace/weave_client.py @@ -51,7 +51,7 @@ ) if typing.TYPE_CHECKING: - from .. import ref_base + from ..legacy import ref_base # Controls if objects can have refs to projects not the WeaveClient project. diff --git a/weave/weave_types.py b/weave/weave_types.py index bee5df4bd11..039b7377c1a 100644 --- a/weave/weave_types.py +++ b/weave/weave_types.py @@ -122,7 +122,7 @@ def type_class_of(obj): @staticmethod def type_of(obj: typing.Any) -> "Type": - from . import ref_base + from weave.legacy import ref_base if ( context_state.ref_tracking_enabled() @@ -1381,7 +1381,7 @@ def _is_assignable_to(self, other_type) -> typing.Optional[bool]: return None def save_instance(self, obj, artifact, name): - from . import ref_base + from weave.legacy import ref_base obj_ref = ref_base.get_ref(obj) if obj_ref is None: