-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gto like metadata fields: labels and type
- Loading branch information
Showing
25 changed files
with
353 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from dataclasses import asdict, dataclass, field, fields | ||
from typing import ClassVar, Dict, List, Optional | ||
|
||
from funcy import compact | ||
|
||
|
||
@dataclass | ||
class Annotation: | ||
PARAM_DESC: ClassVar[str] = "desc" | ||
PARAM_TYPE: ClassVar[str] = "type" | ||
PARAM_LABELS: ClassVar[str] = "labels" | ||
|
||
desc: Optional[str] = None | ||
type: Optional[str] = None | ||
labels: List[str] = field(default_factory=list) | ||
|
||
def update(self, **kwargs) -> "Annotation": | ||
for attr, value in kwargs.items(): | ||
if value and hasattr(self, attr): | ||
setattr(self, attr, value) | ||
return self | ||
|
||
def to_dict(self) -> Dict[str, str]: | ||
return compact(asdict(self)) | ||
|
||
|
||
ANNOTATION_FIELDS = [field.name for field in fields(Annotation)] | ||
ANNOTATION_SCHEMA = { | ||
Annotation.PARAM_DESC: str, | ||
Annotation.PARAM_TYPE: str, | ||
Annotation.PARAM_LABELS: [str], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from argparse import _AppendAction | ||
|
||
|
||
class CommaSeparatedArgs(_AppendAction): # pylint: disable=protected-access | ||
def __call__(self, parser, namespace, values, option_string=None): | ||
from funcy import ldistinct | ||
|
||
items = getattr(namespace, self.dest) or [] | ||
items.extend(map(str.strip, values.split(","))) | ||
setattr(namespace, self.dest, ldistinct(items)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.