Skip to content

Commit 41ba685

Browse files
committed
Determine which executors to autogen from programmatically in stubs.py
1 parent 6fd1e9e commit 41ba685

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+181
-209
lines changed

tools/stubs.py

+54-104
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import ast
2+
import importlib
23
import inspect
4+
import os
35
import textwrap
46
from collections import defaultdict
57
from typing import Literal, cast
@@ -123,107 +125,55 @@ def visit_FunctionDef(self, node):
123125
return ast.copy_location(new_node, node)
124126

125127

126-
from weaviate.collections.aggregations.hybrid import executor as agg_hybrid
127-
from weaviate.collections.aggregations.near_image import executor as agg_near_image
128-
from weaviate.collections.aggregations.near_object import executor as agg_near_object
129-
from weaviate.collections.aggregations.near_text import executor as agg_near_text
130-
from weaviate.collections.aggregations.near_vector import executor as agg_near_vector
131-
from weaviate.collections.aggregations.over_all import executor as agg_over_all
132-
from weaviate.collections.backups import executor as backups
133-
from weaviate.collections.cluster import executor as cluster
134-
from weaviate.collections.config import executor as config
135-
from weaviate.collections.data import executor as data
136-
from weaviate.collections.queries.bm25.generate import executor as generate_bm25
137-
from weaviate.collections.queries.bm25.query import executor as query_bm25
138-
from weaviate.collections.queries.fetch_object_by_id import executor as fetch_object_by_id
139-
from weaviate.collections.queries.fetch_objects.generate import executor as generate_fetch_objects
140-
from weaviate.collections.queries.fetch_objects.query import executor as query_fetch_objects
141-
from weaviate.collections.queries.fetch_objects_by_ids.generate import (
142-
executor as generate_fetch_objects_by_ids,
143-
)
144-
from weaviate.collections.queries.fetch_objects_by_ids.query import (
145-
executor as query_fetch_objects_by_ids,
146-
)
147-
from weaviate.collections.queries.hybrid.generate import executor as generate_hybrid
148-
from weaviate.collections.queries.hybrid.query import executor as query_hybrid
149-
from weaviate.collections.queries.near_image.generate import executor as generate_near_image
150-
from weaviate.collections.queries.near_image.query import executor as query_near_image
151-
from weaviate.collections.queries.near_media.generate import executor as generate_near_media
152-
from weaviate.collections.queries.near_media.query import executor as query_near_media
153-
from weaviate.collections.queries.near_object.generate import executor as generate_near_object
154-
from weaviate.collections.queries.near_object.query import executor as query_near_object
155-
from weaviate.collections.queries.near_text.generate import executor as generate_near_text
156-
from weaviate.collections.queries.near_text.query import executor as query_near_text
157-
from weaviate.collections.queries.near_vector.generate import executor as generate_near_vector
158-
from weaviate.collections.queries.near_vector.query import executor as query_near_vector
159-
from weaviate.debug import executor as debug
160-
from weaviate.rbac import executor as rbac
161-
from weaviate.collections.tenants import executor as tenants
162-
from weaviate.users import executor as users
163-
164-
for module in [
165-
agg_hybrid,
166-
agg_near_image,
167-
agg_near_object,
168-
agg_near_text,
169-
agg_near_vector,
170-
agg_over_all,
171-
backups,
172-
cluster,
173-
config,
174-
data,
175-
debug,
176-
generate_bm25,
177-
generate_fetch_objects,
178-
generate_fetch_objects_by_ids,
179-
generate_hybrid,
180-
generate_near_image,
181-
generate_near_media,
182-
generate_near_object,
183-
generate_near_text,
184-
generate_near_vector,
185-
fetch_object_by_id,
186-
query_bm25,
187-
query_fetch_objects,
188-
query_fetch_objects_by_ids,
189-
query_hybrid,
190-
query_near_image,
191-
query_near_media,
192-
query_near_object,
193-
query_near_text,
194-
query_near_vector,
195-
rbac,
196-
tenants,
197-
users,
198-
]:
199-
source = textwrap.dedent(inspect.getsource(module))
200-
201-
colours: list[Literal["sync", "async"]] = ["sync", "async"]
202-
for colour in colours:
203-
tree = ast.parse(source, mode="exec", type_comments=True)
204-
205-
transformer = ExecutorTransformer(colour)
206-
stubbed = transformer.visit(tree)
207-
208-
imports = [
209-
node for node in stubbed.body if isinstance(node, (ast.Import, ast.ImportFrom))
210-
] + [
211-
ast.ImportFrom(
212-
module="weaviate.connect.v4",
213-
names=[ast.alias(name=f"Connection{colour.capitalize()}", asname=None)],
214-
level=0,
215-
),
216-
ast.ImportFrom(
217-
module=".executor",
218-
names=[ast.alias(name=name, asname=None) for name in transformer.executor_names],
219-
level=0,
220-
),
221-
]
222-
stubbed.body = imports + [node for node in stubbed.body if isinstance(node, ast.ClassDef)]
223-
ast.fix_missing_locations(stubbed)
224-
225-
dir = cast(str, module.__package__).replace(".", "/")
226-
file = f"{dir}/{colour}.pyi" if colour == "sync" else f"{dir}/{colour}_.pyi"
227-
with open(file, "w") as f:
228-
print(f"Writing {file}")
229-
f.write(ast.unparse(stubbed))
128+
for subdir, dirs, files in os.walk("./weaviate"):
129+
for file in files:
130+
if file != "executor.py":
131+
continue
132+
if "connect" in subdir:
133+
# ignore weaviate/connect/executor.py file
134+
continue
135+
if "collections/collections" in subdir:
136+
# ignore weaviate/collections/collections directory
137+
continue
138+
139+
mod = os.path.join(subdir, file)
140+
mod = mod[2:] # remove the leading dot and slash
141+
mod = mod[:-3] # remove the .py
142+
mod = mod.replace("/", ".") # convert into pythonic import
143+
144+
module = importlib.import_module(mod)
145+
source = textwrap.dedent(inspect.getsource(module))
146+
147+
colours: list[Literal["sync", "async"]] = ["sync", "async"]
148+
for colour in colours:
149+
tree = ast.parse(source, mode="exec", type_comments=True)
150+
151+
transformer = ExecutorTransformer(colour)
152+
stubbed = transformer.visit(tree)
153+
154+
imports = [
155+
node for node in stubbed.body if isinstance(node, (ast.Import, ast.ImportFrom))
156+
] + [
157+
ast.ImportFrom(
158+
module="weaviate.connect.v4",
159+
names=[ast.alias(name=f"Connection{colour.capitalize()}", asname=None)],
160+
level=0,
161+
),
162+
ast.ImportFrom(
163+
module=".executor",
164+
names=[
165+
ast.alias(name=name, asname=None) for name in transformer.executor_names
166+
],
167+
level=0,
168+
),
169+
]
170+
stubbed.body = imports + [
171+
node for node in stubbed.body if isinstance(node, ast.ClassDef)
172+
]
173+
ast.fix_missing_locations(stubbed)
174+
175+
dir = cast(str, module.__package__).replace(".", "/")
176+
file = f"{dir}/{colour}.pyi" if colour == "sync" else f"{dir}/{colour}_.pyi"
177+
with open(file, "w") as f:
178+
print(f"Writing {file}")
179+
f.write(ast.unparse(stubbed))

weaviate/backup/async_.pyi

+26-15
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
from typing import Optional, Union, List
2-
3-
from weaviate.backup.base import _BackupBase
4-
from weaviate.backup.executor import (
1+
import asyncio
2+
import time
3+
from typing import Generic, Optional, Union, List, Tuple, Dict
4+
from httpx import Response
5+
from weaviate.backup.backup import (
56
BackupStorage,
67
BackupReturn,
78
BackupStatusReturn,
9+
STORAGE_NAMES,
810
BackupConfigCreate,
11+
BackupStatus,
912
BackupConfigRestore,
10-
_BackupExecutor,
1113
)
1214
from weaviate.backup.backup_location import BackupLocationType
15+
from weaviate.connect import executor
16+
from weaviate.connect.v4 import _ExpectedStatusCodes, Connection, ConnectionAsync, ConnectionType
17+
from weaviate.exceptions import (
18+
WeaviateInvalidInputError,
19+
WeaviateUnsupportedFeatureError,
20+
BackupFailedException,
21+
EmptyResponseException,
22+
BackupCanceledError,
23+
)
24+
from weaviate.util import _capitalize_first_letter, _decode_json_response_dict
1325
from weaviate.connect.v4 import ConnectionAsync
26+
from .executor import _BackupExecutor
1427

1528
class _BackupAsync(_BackupExecutor[ConnectionAsync]):
16-
"""Backup class used to schedule and/or check the status of a backup process of Weaviate objects."""
17-
18-
async def cancel(
19-
self,
20-
backup_id: str,
21-
backend: BackupStorage,
22-
backup_location: Optional[BackupLocationType] = None,
23-
) -> bool: ...
2429
async def create(
2530
self,
2631
backup_id: str,
2732
backend: BackupStorage,
28-
include_collections: Optional[Union[List[str], str]] = None,
29-
exclude_collections: Optional[Union[List[str], str]] = None,
33+
include_collections: Union[List[str], str, None] = None,
34+
exclude_collections: Union[List[str], str, None] = None,
3035
wait_for_completion: bool = False,
3136
config: Optional[BackupConfigCreate] = None,
3237
backup_location: Optional[BackupLocationType] = None,
@@ -53,3 +58,9 @@ class _BackupAsync(_BackupExecutor[ConnectionAsync]):
5358
backend: BackupStorage,
5459
backup_location: Optional[BackupLocationType] = None,
5560
) -> BackupStatusReturn: ...
61+
async def cancel(
62+
self,
63+
backup_id: str,
64+
backend: BackupStorage,
65+
backup_location: Optional[BackupLocationType] = None,
66+
) -> bool: ...

weaviate/backup/sync.pyi

+26-15
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
from typing import Optional, Union, List
2-
3-
from weaviate.backup.base import _BackupBase
4-
from weaviate.backup.executor import (
1+
import asyncio
2+
import time
3+
from typing import Generic, Optional, Union, List, Tuple, Dict
4+
from httpx import Response
5+
from weaviate.backup.backup import (
56
BackupStorage,
67
BackupReturn,
78
BackupStatusReturn,
9+
STORAGE_NAMES,
810
BackupConfigCreate,
11+
BackupStatus,
912
BackupConfigRestore,
10-
_BackupExecutor,
1113
)
1214
from weaviate.backup.backup_location import BackupLocationType
15+
from weaviate.connect import executor
16+
from weaviate.connect.v4 import _ExpectedStatusCodes, Connection, ConnectionAsync, ConnectionType
17+
from weaviate.exceptions import (
18+
WeaviateInvalidInputError,
19+
WeaviateUnsupportedFeatureError,
20+
BackupFailedException,
21+
EmptyResponseException,
22+
BackupCanceledError,
23+
)
24+
from weaviate.util import _capitalize_first_letter, _decode_json_response_dict
1325
from weaviate.connect.v4 import ConnectionSync
26+
from .executor import _BackupExecutor
1427

1528
class _Backup(_BackupExecutor[ConnectionSync]):
16-
"""Backup class used to schedule and/or check the status of a backup process of Weaviate objects."""
17-
18-
def cancel(
19-
self,
20-
backup_id: str,
21-
backend: BackupStorage,
22-
backup_location: Optional[BackupLocationType] = None,
23-
) -> bool: ...
2429
def create(
2530
self,
2631
backup_id: str,
2732
backend: BackupStorage,
28-
include_collections: Optional[Union[List[str], str]] = None,
29-
exclude_collections: Optional[Union[List[str], str]] = None,
33+
include_collections: Union[List[str], str, None] = None,
34+
exclude_collections: Union[List[str], str, None] = None,
3035
wait_for_completion: bool = False,
3136
config: Optional[BackupConfigCreate] = None,
3237
backup_location: Optional[BackupLocationType] = None,
@@ -53,3 +58,9 @@ class _Backup(_BackupExecutor[ConnectionSync]):
5358
backend: BackupStorage,
5459
backup_location: Optional[BackupLocationType] = None,
5560
) -> BackupStatusReturn: ...
61+
def cancel(
62+
self,
63+
backup_id: str,
64+
backend: BackupStorage,
65+
backup_location: Optional[BackupLocationType] = None,
66+
) -> bool: ...

weaviate/collections/aggregations/hybrid/async_.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Generic, List, Literal, Optional, Union, overload
2-
from weaviate.collections.aggregations.executor import _BaseExecutor
2+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
33
from weaviate.collections.classes.aggregate import (
44
PropertiesMetrics,
55
AggregateReturn,

weaviate/collections/aggregations/hybrid/executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Generic, List, Literal, Optional, Union, overload
22

3-
from weaviate.collections.aggregations.executor import _BaseExecutor
3+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
44
from weaviate.collections.classes.aggregate import (
55
PropertiesMetrics,
66
AggregateReturn,

weaviate/collections/aggregations/hybrid/sync.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Generic, List, Literal, Optional, Union, overload
2-
from weaviate.collections.aggregations.executor import _BaseExecutor
2+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
33
from weaviate.collections.classes.aggregate import (
44
PropertiesMetrics,
55
AggregateReturn,

weaviate/collections/aggregations/near_image/async_.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Generic, Literal, Optional, Union, overload
2-
from weaviate.collections.aggregations.executor import _BaseExecutor
2+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
33
from weaviate.collections.classes.aggregate import (
44
PropertiesMetrics,
55
AggregateReturn,

weaviate/collections/aggregations/near_image/executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Generic, Literal, Optional, Union, overload
22

3-
from weaviate.collections.aggregations.executor import _BaseExecutor
3+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
44
from weaviate.collections.classes.aggregate import (
55
PropertiesMetrics,
66
AggregateReturn,

weaviate/collections/aggregations/near_image/sync.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Generic, Literal, Optional, Union, overload
2-
from weaviate.collections.aggregations.executor import _BaseExecutor
2+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
33
from weaviate.collections.classes.aggregate import (
44
PropertiesMetrics,
55
AggregateReturn,

weaviate/collections/aggregations/near_object/async_.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Generic, Literal, Optional, Union, overload
2-
from weaviate.collections.aggregations.executor import _BaseExecutor
2+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
33
from weaviate.collections.classes.aggregate import (
44
PropertiesMetrics,
55
AggregateReturn,

weaviate/collections/aggregations/near_object/executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Generic, Literal, Optional, Union, overload
22

3-
from weaviate.collections.aggregations.executor import _BaseExecutor
3+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
44
from weaviate.collections.classes.aggregate import (
55
PropertiesMetrics,
66
AggregateReturn,

weaviate/collections/aggregations/near_object/sync.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Generic, Literal, Optional, Union, overload
2-
from weaviate.collections.aggregations.executor import _BaseExecutor
2+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
33
from weaviate.collections.classes.aggregate import (
44
PropertiesMetrics,
55
AggregateReturn,

weaviate/collections/aggregations/near_text/async_.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Generic, List, Literal, Optional, Union, overload
2-
from weaviate.collections.aggregations.executor import _BaseExecutor
2+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
33
from weaviate.collections.classes.aggregate import (
44
PropertiesMetrics,
55
AggregateReturn,

weaviate/collections/aggregations/near_text/executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Generic, List, Literal, Optional, Union, overload
22

3-
from weaviate.collections.aggregations.executor import _BaseExecutor
3+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
44
from weaviate.collections.classes.aggregate import (
55
PropertiesMetrics,
66
AggregateReturn,

weaviate/collections/aggregations/near_text/sync.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Generic, List, Literal, Optional, Union, overload
2-
from weaviate.collections.aggregations.executor import _BaseExecutor
2+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
33
from weaviate.collections.classes.aggregate import (
44
PropertiesMetrics,
55
AggregateReturn,

weaviate/collections/aggregations/near_vector/async_.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Generic, List, Literal, Optional, Union, cast, overload
2-
from weaviate.collections.aggregations.executor import _BaseExecutor
2+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
33
from weaviate.collections.classes.aggregate import (
44
PropertiesMetrics,
55
AggregateReturn,

weaviate/collections/aggregations/near_vector/executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Generic, List, Literal, Optional, Union, cast, overload
22

3-
from weaviate.collections.aggregations.executor import _BaseExecutor
3+
from weaviate.collections.aggregations.base_executor import _BaseExecutor
44
from weaviate.collections.classes.aggregate import (
55
PropertiesMetrics,
66
AggregateReturn,

0 commit comments

Comments
 (0)