-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IO-1278][IO-1277] Core Items/Folders apis #691
Changes from 13 commits
e9c5615
bb3743a
cfa2e6a
8abc2df
5bca9ff
1aa2773
2ab3fd1
1a3cce4
5dc229b
785c764
0ffbe10
d5e8f8f
32f11e0
7e7d0c5
5a2a89d
6d0ea6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Can't import * in this module because of a circular import problem specific to teams | ||
# The TeamCore module can instantiate from a client, but the client needs to use the team backend module | ||
# to request the object for team. To circumvent this there's a get_raw method in this module that returns | ||
# the raw team object, which is then passed to the TeamCore module, but if we import * here it introduces the | ||
# The TeamCore module can instantiate from a client, but the client needs to use the | ||
# team backend module to request the object for team. To circumvent this there's a | ||
# get_raw method in this module that returns the raw team object, which is then passed | ||
# to the TeamCore module, but if we import * here it introduces the | ||
# circular import problem. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# @see: GraphotateWeb.Schemas.DatasetsV2.ItemRegistration.ExistingItem | ||
from typing import Dict, List, Literal, Optional, Union | ||
from uuid import UUID | ||
|
||
from pydantic import Field, validator | ||
|
||
from darwin.datatypes import NumberLike | ||
from darwin.future.data_objects.pydantic_base import DefaultDarwin | ||
from darwin.future.data_objects.typing import UnknownType | ||
|
||
ItemFrameRate = Union[NumberLike, Literal["native"]] | ||
|
||
|
||
def validate_no_slashes(v: UnknownType) -> str: | ||
assert isinstance(v, str), "Must be a string" | ||
assert len(v) > 0, "cannot be empty" | ||
assert r"^[^/].*$".find(v) == -1, "cannot start with a slash" | ||
|
||
return v | ||
|
||
|
||
class ItemSlot(DefaultDarwin): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main one I've changed in my branch |
||
# GraphotateWeb.Schemas.DatasetsV2.ItemRegistration.ExistingSlot | ||
|
||
# Required fields | ||
slot_name: str | ||
file_name: str | ||
|
||
# Optional fields | ||
storage_key: Optional[str] | ||
as_frames: Optional[bool] | ||
extract_views: Optional[bool] | ||
fps: Optional[ItemFrameRate] = Field(None, alias="fps") | ||
metadata: Optional[Dict[str, UnknownType]] = Field({}, alias="metadata") | ||
tags: Optional[Union[List[str], Dict[str, str]]] = Field(None, alias="tags") | ||
type: Literal["image", "video", "pdf", "dicom"] = Field(..., alias="type") | ||
|
||
@validator("slot_name") | ||
def validate_slot_name(cls, v: UnknownType) -> str: | ||
assert isinstance(v, str), "slot_name must be a string" | ||
assert len(v) > 0, "slot_name cannot be empty" | ||
return v | ||
|
||
@validator("storage_key") | ||
def validate_storage_key(cls, v: UnknownType) -> str: | ||
return validate_no_slashes(v) | ||
|
||
@validator("fps") | ||
def validate_fps(cls, v: UnknownType) -> ItemFrameRate: | ||
assert isinstance(v, (int, float, str)), "fps must be a number or 'native'" | ||
if isinstance(v, (int, float)): | ||
assert v >= 0.0, "fps must be a positive number" | ||
if isinstance(v, str): | ||
assert v == "native", "fps must be 'native' or a number greater than 0" | ||
return v | ||
|
||
|
||
class Item(DefaultDarwin): | ||
name: str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this is where we'll have to figure it out between us. |
||
path: str | ||
archived: bool | ||
dataset_id: int | ||
id: UUID | ||
layout: Dict[str, UnknownType] | ||
slots: List[ItemSlot] | ||
processing_status: str | ||
priority: int | ||
|
||
@validator("name") | ||
def validate_name(cls, v: UnknownType) -> str: | ||
return validate_no_slashes(v) | ||
|
||
|
||
class Folder(DefaultDarwin): | ||
dataset_id: int | ||
filtered_item_count: int | ||
path: str | ||
unfiltered_item_count: int |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,4 +69,5 @@ def edges(self) -> List[List[UUID]]: | |
return [ | ||
[edge.id, edge.source_stage_id, edge.target_stage_id] | ||
for edge in self._element.edges | ||
if edge.source_stage_id and edge.target_stage_id | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JBWilkie source_stage_id and target_stage_id are optional so they can be None. Which means this comprehension without the if check actually returns a List[List[UUID | None]]. Let me know if this change doesn't make sense though and you want the None's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't see a use case for why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually changed this so that it returns the This means we don't need to worry about this if check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this stuff especially 😉