Skip to content

Commit

Permalink
Doctest example
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbjoernl committed Feb 21, 2025
1 parent 46ade90 commit 2b5ee1d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
24 changes: 19 additions & 5 deletions src/aerovaldb/aerovaldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import functools
import inspect
from typing import Iterable

from aerovaldb.utils.query import QueryEntry

Expand Down Expand Up @@ -1333,18 +1334,31 @@ async def get_experiment_mtime(

@async_and_sync
async def query(
self, asset_type: AssetType | set[AssetType] | None = None, **kwargs
self, asset_type: AssetType | Iterable[AssetType] | None = None, **kwargs
) -> list[QueryEntry]:
"""Query function for getting information about assets
stored in the db.
:param asset_type: Enum of the type of asset to query (Can be a set). By default, all asset types
will be included.
:param kwargs: Optional additional filter arguments. Will be matched against QueryEntry.args.
:param asset_type: Enum of the type of asset to query (Can be an iterable of multiple types). By default,
all asset types will be included.
:param kwargs: Optional additional filter arguments. Will be matched against QueryEntry.meta.
All provided keys must match. For possible keys see function signature of the getter for which
you want to match.
:return: A list of QueryEntry objects that contains URIs and information about
:return: A list of QueryEntry objects that contains the URI and information about
the queried files.
Example:
>>> import tempfile
>>> import aerovaldb
>>>
>>> with tempfile.TemporaryDirectory() as dir:
... with aerovaldb.open(f"json_files:{dir}") as db:
... db.put_experiments({}, "project1")
... db.put_experiments({}, "project2")
... db.query(aerovaldb.AssetType.EXPERIMENTS, project="project1")
... db.query(aerovaldb.AssetType.EXPERIMENTS, project="project1")[0].meta
['/v0/experiments/project1?version=0.0.1']
{'project': 'project1'}
"""
raise NotImplementedError
13 changes: 9 additions & 4 deletions src/aerovaldb/jsondb/jsonfiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys
from hashlib import md5
from pathlib import Path
from typing import Any, Awaitable, Callable
from typing import Any, Awaitable, Callable, Iterable

import filetype # type: ignore
import simplejson # type: ignore
Expand Down Expand Up @@ -652,13 +652,18 @@ def lock(self):
@async_and_sync
@override
async def query(
self, asset_type: AssetType | set[AssetType] | None = None, **kwargs
self, asset_type: AssetType | Iterable[AssetType] | None = None, **kwargs
) -> list[QueryEntry]:
if asset_type is None:
asset_type = set([AssetType(x) for x in ALL_ROUTES])

if isinstance(asset_type, AssetType):
elif isinstance(asset_type, AssetType):
asset_type = set([asset_type])
elif isinstance(asset_type, Iterable):
asset_type = set(asset_type)
else:
raise TypeError(
f"Expected AssetType | Iterable[AssetType]. Got {type(asset_type)}"
)

glb = glob.iglob(
os.path.join(glob.escape(self._basedir), "./**"), recursive=True
Expand Down

0 comments on commit 2b5ee1d

Please sign in to comment.