-
Notifications
You must be signed in to change notification settings - Fork 3
/
version_info.py
150 lines (103 loc) · 4.01 KB
/
version_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from __future__ import annotations
from datetime import datetime
from typing import ClassVar, List, Literal, Optional, Sequence, Union
import pydantic
from typing_extensions import Annotated
from .._settings import settings
from ..common import Node
class _StatusBase(Node, frozen=True):
timestamp: datetime = pydantic.Field(default_factory=datetime.now)
run_url: Optional[str] = settings.run_url
class _DraftStatusBase(_StatusBase, frozen=True):
description: str
num_steps: int = 6
@pydantic.model_validator(mode="after")
def _validate_num_steps(self):
assert self.num_steps >= getattr(self, "step", 0)
return self
class UnpackingStatus(_DraftStatusBase, frozen=True):
name: Literal["unpacking"] = "unpacking"
step: Literal[1] = 1
class UnpackedStatus(_DraftStatusBase, frozen=True):
name: Literal["unpacked"] = "unpacked"
description: str = "staging was successful; awaiting automated tests to start ⏳"
step: Literal[2] = 2
class TestingStatus(_DraftStatusBase, frozen=True):
name: Literal["testing"] = "testing"
step: Literal[3] = 3
class AwaitingReviewStatus(_DraftStatusBase, frozen=True):
name: Literal["awaiting review"] = "awaiting review"
description: str = (
"Thank you for your contribution! 💪"
"Our bioimage.io maintainers will take a look soon. 🦒"
)
step: Literal[4] = 4
class ChangesRequestedStatus(_DraftStatusBase, frozen=True):
name: Literal["changes requested"] = "changes requested"
step: Literal[5] = 5
class AcceptedStatus(_DraftStatusBase, frozen=True):
name: Literal["accepted"] = "accepted"
description: str = (
"This staged version has been accepted by a bioimage.io maintainer and is about to be published."
)
step: Literal[5] = 5
class PublishedDraftStatus(_DraftStatusBase, frozen=True):
"""following `AcceptedStatus`"""
name: Literal["published"] = "published"
description: str = "published! (this draft will be deleted shortly)"
step: Literal[6] = 6
DraftStatus = Annotated[
Union[
UnpackingStatus,
UnpackedStatus,
TestingStatus,
AwaitingReviewStatus,
ChangesRequestedStatus,
AcceptedStatus,
PublishedDraftStatus,
],
pydantic.Discriminator("name"),
]
class ErrorStatus(_StatusBase, frozen=True):
name: Literal["error"] = "error"
step: Literal[0] = 0
message: str
traceback: List[str]
during: Optional[DraftStatus]
class DraftInfo(Node, frozen=True):
"""`<concept_id>/draft/draft.json` contains the collection entry metadata"""
file_name: ClassVar[str] = "draft.json"
status: Optional[
Annotated[Union[DraftStatus, ErrorStatus], pydantic.Discriminator("name")]
] = None
created: datetime = pydantic.Field(default_factory=datetime.now)
def get_updated(self, update: DraftInfo) -> DraftInfo:
return DraftInfo(created=self.created, status=update.status)
class RecordInfo(Node, frozen=True):
"""`<concept_id>/info.json` contains the collection entry metadata"""
file_name: ClassVar[str] = "info.json"
created: datetime = pydantic.Field(default_factory=datetime.now)
concept_doi: Optional[str] = None
doi: Optional[str] = None
"""version specific DOI"""
download_count: Union[int, Literal["?"]] = "?"
def get_updated(self, update: RecordInfo) -> RecordInfo:
return RecordInfo(
created=self.created,
concept_doi=self.concept_doi or update.concept_doi,
doi=self.doi or update.doi,
download_count=(
self.download_count
if update.download_count == "?"
else update.download_count
),
)
class VersionInfo(Node, frozen=True):
created: datetime = pydantic.Field(default_factory=datetime.now)
doi: Optional[str] = None
"""version specific DOI"""
v: str
"""version"""
class VersionsInfo(Node, frozen=True):
concept_doi: Optional[str] = None
versions: Sequence[VersionInfo] = ()