mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
This adds support for custom metadata in outputs under `meta` key. Also adds `--meta` flag to `add`/`import`/`import-url` that supports `key=value` values.
36 lines
1006 B
Python
36 lines
1006 B
Python
from dataclasses import asdict, dataclass, field, fields
|
|
from typing import Any, 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"
|
|
PARAM_META: ClassVar[str] = "meta"
|
|
|
|
desc: Optional[str] = None
|
|
type: Optional[str] = None
|
|
labels: List[str] = field(default_factory=list)
|
|
meta: Dict[str, Any] = field(default_factory=dict)
|
|
|
|
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],
|
|
Annotation.PARAM_META: object,
|
|
}
|