Skip to content

Commit

Permalink
Some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbjoernl committed Aug 30, 2024
1 parent caa59cf commit 5df6a31
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/aerovaldb/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IMG_FILE_EXTS = set([".bmp", ".jpeg", ".jpg", ".png", ".tiff"])
18 changes: 6 additions & 12 deletions src/aerovaldb/jsondb/jsonfiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from packaging.version import Version

from aerovaldb.aerovaldb import AerovalDB
from aerovaldb.const import IMG_FILE_EXTS
from aerovaldb.exceptions import UnusedArguments
from aerovaldb.types import AccessType
from ..utils.string_mapper import StringMapper, VersionConstraintMapper
Expand Down Expand Up @@ -348,7 +349,10 @@ async def _get_uri_for_file(self, file_path: str) -> str:

_, ext = os.path.splitext(file_path)

if ext.lower() in [".png", ".jpg"]:
if ext.lower() in IMG_FILE_EXTS:
# TODO: Fix this.
# The image endpoint is the only endpoint which needs to accept an arbitrary path
# under the experiment directory. Treating it as a special case for now.
split = file_path.split("/")
project = split[1]
experiment = split[2]
Expand Down Expand Up @@ -541,11 +545,6 @@ async def get_by_uri(
return uri

route, route_args, kwargs = parse_uri(uri)
for k, v in route_args.items():
route_args[k] = v.replace(":", "/")

for k, v in kwargs.items():
route_args[k] = v.replace(":", "/")

if route.startswith("/v0/report-image/"):
return await self.get_report_image(
Expand All @@ -567,11 +566,6 @@ async def get_by_uri(
@async_and_sync
async def put_by_uri(self, obj, uri: str):
route, route_args, kwargs = parse_uri(uri)
for k, v in route_args.items():
route_args[k] = v.replace(":", "/")

for k, v in kwargs.items():
route_args[k] = v.replace(":", "/")

if route.startswith("/v0/report-image/"):
await self.put_report_image(
Expand Down Expand Up @@ -659,6 +653,6 @@ async def put_report_image(self, obj, project: str, experiment: str, path: str):
self._basedir,
template.format(project=project, experiment=experiment, path=path),
)
os.makedirs(Path(file_path).parent)
os.makedirs(Path(file_path).parent, exist_ok=True)
with open(file_path, "wb") as f:
f.write(obj)
2 changes: 2 additions & 0 deletions src/aerovaldb/utils/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def parse_uri(uri: str) -> tuple[str, dict[str, str], dict[str, str]]:
except Exception:
continue
else:
for k, v in route_args.items():
route_args[k] = v.replace(":", "/")
return (template, route_args, dict())

elif len(split) == 2:
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_aerovaldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def test_list_glob_stats(testdb):
@TESTDB_PARAMETRIZATION
def test_list_all(testdb):
with aerovaldb.open(testdb) as db:
assert len(db.list_all()) == 42
assert len(db.list_all()) == 46


@TESTDB_PARAMETRIZATION
Expand All @@ -508,4 +508,4 @@ def test_rm_experiment_data(tmpdb):

tmpdb.rm_experiment_data("project", "experiment")

assert len(list(tmpdb.list_all())) == 26
assert len(list(tmpdb.list_all())) == 30

0 comments on commit 5df6a31

Please sign in to comment.