Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbjoernl committed Aug 20, 2024
1 parent 6c46606 commit 9d9090d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 88 deletions.
65 changes: 0 additions & 65 deletions src/aerovaldb/jsondb/jsonfiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,47 +273,6 @@ async def _put(self, obj, route, route_args, *args, **kwargs):
with open(file_path, "w") as f:
f.write(json)

@async_and_sync
async def get_experiments(self, project: str, /, *args, exp_order=None, **kwargs):
# If an experiments.json file exists, read it.
try:
access_type = self._normalize_access_type(kwargs.pop("access_type", None))
experiments = await self._get(
ROUTE_EXPERIMENTS,
{"project": project},
access_type=access_type,
)
except FileNotFoundError:
pass
else:
return experiments

# Otherwise generate it based on config and expinfo.public information.
experiments = {}
for exp in self._list_experiments(project, has_results=True):
public = False
try:
config = await self.get_config(project, exp)
except FileNotFoundError:
pass
else:
public = config.get("exp_info", {}).get("public", False)
experiments[exp] = {"public": public}

access_type = self._normalize_access_type(kwargs.pop("access_type", None))

experiments = dict(experiments.items())
if access_type == AccessType.FILE_PATH:
raise UnsupportedOperation(
f"get_experiments() does not support access_type {access_type}."
)

if access_type == AccessType.JSON_STR:
json = json_dumps_wrapper(experiments)
return json

return experiments

def rm_experiment_data(self, project: str, experiment: str) -> None:
"""Deletes ALL data associated with an experiment.
Expand Down Expand Up @@ -555,30 +514,6 @@ def list_map(

yield self._get_uri_for_file(f)

def _list_experiments(
self, project: str, /, has_results: bool = False
) -> list[str]:
project_path = os.path.join(self._basedir, project)
experiments = []

if not os.path.exists(project_path):
return []

for f in os.listdir(project_path):
if not has_results:
if os.path.isdir(os.path.join(project_path, f)):
experiments.append(f)
else:
if not os.path.isdir(os.path.join(project_path, f)):
continue
glb = os.path.join(project_path, f, "map", "*.json")
if len(glob.glob(glb)) == 0:
continue

experiments.append(f)

return experiments

@async_and_sync
async def get_by_uri(
self,
Expand Down
23 changes: 0 additions & 23 deletions tests/jsondb/test_jsonfiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,6 @@
from aerovaldb.jsondb.jsonfiledb import AerovalJsonFileDB


def test_list_experiments():
with aerovaldb.open("json_files:./tests/test-db/json") as db:
experiments = db._list_experiments("project")
assert set(experiments) == set(
["experiment", "experiment-old", "empty-experiment"]
)


def test_list_experiments_results_only():
with aerovaldb.open("json_files:./tests/test-db/json") as db:
experiments = db._list_experiments("project", has_results=True)
assert set(experiments) == set(["experiment", "experiment-old"])


def test_get_experiments():
with aerovaldb.open("json_files:./tests/test-db/json") as db:
experiments = db.get_experiments("project-no-experiments-json")

assert experiments == {
"experiment": {"public": True},
}


def test_jsonfiledb__get_uri_for_file(tmp_path):
with aerovaldb.open(f"json_files:{str(tmp_path)}") as db:
db: AerovalJsonFileDB
Expand Down

0 comments on commit 9d9090d

Please sign in to comment.