Skip to content

Commit 263ded3

Browse files
committed
Adjust code and test suite to work with recent changes
1 parent a3be278 commit 263ded3

28 files changed

+250
-247
lines changed

Tekst-API/openapi.json

Lines changed: 24 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8354,16 +8354,10 @@
83548354
"description": "Public user data for users allowed to write this resource"
83558355
},
83568356
"corrections": {
8357-
"anyOf": [
8358-
{
8359-
"type": "integer"
8360-
},
8361-
{
8362-
"type": "null"
8363-
}
8364-
],
8357+
"type": "integer",
83658358
"title": "Corrections",
8366-
"description": "Number of correction notes available for this resource"
8359+
"description": "Number of correction notes available for this resource",
8360+
"default": 0
83678361
},
83688362
"title": {
83698363
"items": {
@@ -9199,16 +9193,10 @@
91999193
"description": "Public user data for users allowed to write this resource"
92009194
},
92019195
"corrections": {
9202-
"anyOf": [
9203-
{
9204-
"type": "integer"
9205-
},
9206-
{
9207-
"type": "null"
9208-
}
9209-
],
9196+
"type": "integer",
92109197
"title": "Corrections",
9211-
"description": "Number of correction notes available for this resource"
9198+
"description": "Number of correction notes available for this resource",
9199+
"default": 0
92129200
},
92139201
"title": {
92149202
"items": {
@@ -10968,16 +10956,10 @@
1096810956
"description": "Public user data for users allowed to write this resource"
1096910957
},
1097010958
"corrections": {
10971-
"anyOf": [
10972-
{
10973-
"type": "integer"
10974-
},
10975-
{
10976-
"type": "null"
10977-
}
10978-
],
10959+
"type": "integer",
1097910960
"title": "Corrections",
10980-
"description": "Number of correction notes available for this resource"
10961+
"description": "Number of correction notes available for this resource",
10962+
"default": 0
1098110963
},
1098210964
"title": {
1098310965
"items": {
@@ -12011,16 +11993,10 @@
1201111993
"description": "Public user data for users allowed to write this resource"
1201211994
},
1201311995
"corrections": {
12014-
"anyOf": [
12015-
{
12016-
"type": "integer"
12017-
},
12018-
{
12019-
"type": "null"
12020-
}
12021-
],
11996+
"type": "integer",
1202211997
"title": "Corrections",
12023-
"description": "Number of correction notes available for this resource"
11998+
"description": "Number of correction notes available for this resource",
11999+
"default": 0
1202412000
},
1202512001
"title": {
1202612002
"items": {
@@ -13391,16 +13367,10 @@
1339113367
"description": "Public user data for users allowed to write this resource"
1339213368
},
1339313369
"corrections": {
13394-
"anyOf": [
13395-
{
13396-
"type": "integer"
13397-
},
13398-
{
13399-
"type": "null"
13400-
}
13401-
],
13370+
"type": "integer",
1340213371
"title": "Corrections",
13403-
"description": "Number of correction notes available for this resource"
13372+
"description": "Number of correction notes available for this resource",
13373+
"default": 0
1340413374
},
1340513375
"title": {
1340613376
"items": {
@@ -14645,16 +14615,10 @@
1464514615
"description": "Public user data for users allowed to write this resource"
1464614616
},
1464714617
"corrections": {
14648-
"anyOf": [
14649-
{
14650-
"type": "integer"
14651-
},
14652-
{
14653-
"type": "null"
14654-
}
14655-
],
14618+
"type": "integer",
1465614619
"title": "Corrections",
14657-
"description": "Number of correction notes available for this resource"
14620+
"description": "Number of correction notes available for this resource",
14621+
"default": 0
1465814622
},
1465914623
"title": {
1466014624
"items": {
@@ -16702,16 +16666,10 @@
1670216666
"description": "Public user data for users allowed to write this resource"
1670316667
},
1670416668
"corrections": {
16705-
"anyOf": [
16706-
{
16707-
"type": "integer"
16708-
},
16709-
{
16710-
"type": "null"
16711-
}
16712-
],
16669+
"type": "integer",
1671316670
"title": "Corrections",
16714-
"description": "Number of correction notes available for this resource"
16671+
"description": "Number of correction notes available for this resource",
16672+
"default": 0
1671516673
},
1671616674
"title": {
1671716675
"items": {
@@ -18065,16 +18023,10 @@
1806518023
"description": "Public user data for users allowed to write this resource"
1806618024
},
1806718025
"corrections": {
18068-
"anyOf": [
18069-
{
18070-
"type": "integer"
18071-
},
18072-
{
18073-
"type": "null"
18074-
}
18075-
],
18026+
"type": "integer",
1807618027
"title": "Corrections",
18077-
"description": "Number of correction notes available for this resource"
18028+
"description": "Number of correction notes available for this resource",
18029+
"default": 0
1807818030
},
1807918031
"title": {
1808018032
"items": {

Tekst-API/tekst/models/resource.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
from typing_extensions import TypedDict
1717

18+
from tekst.html import force_html, sanitize_html
1819
from tekst.i18n import TranslationBase, Translations
1920
from tekst.logs import log, log_op_end, log_op_start
2021
from tekst.models.common import (
@@ -36,7 +37,7 @@
3637
ResourceTypeName,
3738
SingleLineString,
3839
)
39-
from tekst.utils.html import force_html, sanitize_html
40+
from tekst.utils import ensure
4041

4142

4243
# class for one arbitrary metadate
@@ -563,14 +564,11 @@ async def __precompute_coverage_data(
563564
.to_list()
564565
)
565566

566-
text_doc: TextDocument | None = await TextDocument.get(self.text_id)
567-
assert text_doc
567+
text = ensure(await TextDocument.get(self.text_id))
568568
# get all resource level location labels
569-
location_labels = await text_doc.full_location_labels(self.level)
569+
location_labels = await text.full_location_labels(self.level)
570570
# get all parent level location labels
571-
parent_location_labels = await text_doc.full_location_labels(
572-
max(self.level - 1, 0)
573-
)
571+
parent_location_labels = await text.full_location_labels(max(self.level - 1, 0))
574572

575573
# generate coverage details data
576574
coverage_per_parent = {}
@@ -668,9 +666,9 @@ class ResourceReadExtras(ModelBase):
668666
Field(description="Public user data for users allowed to write this resource"),
669667
] = None
670668
corrections: Annotated[
671-
int | None,
669+
int,
672670
Field(description="Number of correction notes available for this resource"),
673-
] = None
671+
] = 0
674672

675673

676674
ResourceBaseUpdate = make_update_model(ResourceBase)

Tekst-API/tekst/resource_types/audio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
SchemaOptionalNullable,
2424
SingleLineString,
2525
)
26+
from tekst.utils import ensure
2627

2728

2829
if TYPE_CHECKING:
@@ -122,8 +123,7 @@ async def _export_csv(
122123
contents: list["AudioContent"],
123124
file_path: Path,
124125
) -> None:
125-
text = await TextDocument.get(resource.text_id)
126-
assert text
126+
text = ensure(await TextDocument.get(resource.text_id))
127127
# construct labels of all locations on the resource's level
128128
full_loc_labels = await text.full_location_labels(resource.level)
129129
sort_num = 0

Tekst-API/tekst/resource_types/external_references.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
SchemaOptionalNullable,
2727
SingleLineString,
2828
)
29+
from tekst.utils import ensure
2930

3031

3132
if TYPE_CHECKING:
@@ -131,8 +132,7 @@ async def _export_csv(
131132
contents: list["ExternalReferencesContent"],
132133
file_path: Path,
133134
) -> None:
134-
text = await TextDocument.get(resource.text_id)
135-
assert text
135+
text = ensure(await TextDocument.get(resource.text_id))
136136
# construct labels of all locations on the resource's level
137137
full_loc_labels = await text.full_location_labels(resource.level)
138138
sort_num = 0

Tekst-API/tekst/resource_types/images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
SchemaOptionalNullable,
2424
SingleLineString,
2525
)
26+
from tekst.utils import ensure
2627

2728

2829
if TYPE_CHECKING:
@@ -122,8 +123,7 @@ async def _export_csv(
122123
contents: list["ImagesContent"],
123124
file_path: Path,
124125
) -> None:
125-
text = await TextDocument.get(resource.text_id)
126-
assert text
126+
text = ensure(await TextDocument.get(resource.text_id))
127127
# construct labels of all locations on the resource's level
128128
full_loc_labels = await text.full_location_labels(resource.level)
129129
sort_num = 0

Tekst-API/tekst/resource_types/location_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
SchemaOptionalNonNullable,
3030
SingleLineString,
3131
)
32+
from tekst.utils import ensure
3233

3334

3435
if TYPE_CHECKING:
@@ -188,8 +189,7 @@ async def _export_csv(
188189
contents: list["LocationMetadataContent"],
189190
file_path: Path,
190191
) -> None:
191-
text = await TextDocument.get(resource.text_id)
192-
assert text
192+
text = ensure(await TextDocument.get(resource.text_id))
193193
# construct labels of all locations on the resource's level
194194
full_loc_labels = await text.full_location_labels(resource.level)
195195
sort_num = 0

Tekst-API/tekst/resource_types/rich_text.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pydantic import Field, StringConstraints, field_validator
77

8+
from tekst.html import get_html_text, sanitize_html
89
from tekst.models.common import CreateBase, ModelBase, ReadBase, make_update_model
910
from tekst.models.content import ContentBase, ContentBaseDocument
1011
from tekst.models.resource import (
@@ -28,7 +29,7 @@
2829
SearchReplacements,
2930
SingleLineString,
3031
)
31-
from tekst.utils.html import get_html_text, sanitize_html
32+
from tekst.utils import ensure
3233

3334

3435
if TYPE_CHECKING:
@@ -128,8 +129,7 @@ async def _export_csv(
128129
contents: list["RichTextContent"],
129130
file_path: Path,
130131
) -> None:
131-
text = await TextDocument.get(resource.text_id)
132-
assert text
132+
text = ensure(await TextDocument.get(resource.text_id))
133133
# construct labels of all locations on the resource's level
134134
full_loc_labels = await text.full_location_labels(resource.level)
135135
sort_num = 0

Tekst-API/tekst/resource_types/text_annotation.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
SchemaOptionalNullable,
3434
SingleLineString,
3535
)
36+
from tekst.utils import ensure
3637

3738

3839
if TYPE_CHECKING:
@@ -282,8 +283,7 @@ async def _export_csv(
282283
contents: list["TextAnnotationContent"],
283284
file_path: Path,
284285
) -> None:
285-
text = await TextDocument.get(resource.text_id)
286-
assert text
286+
text = ensure(await TextDocument.get(resource.text_id))
287287
# construct labels of all locations on the resource's level
288288
full_loc_labels = await text.full_location_labels(resource.level)
289289
sort_num = 0
@@ -561,9 +561,8 @@ async def _ensure_token_ids(self):
561561
for token in content.tokens:
562562
if not token.id:
563563
if not text_slug:
564-
text_doc = await TextDocument.get(self.text_id)
565-
assert text_doc
566-
text_slug = text_doc.slug
564+
text = ensure(await TextDocument.get(self.text_id))
565+
text_slug = text.slug
567566
pre = f"{text_slug}_{self.id}_"
568567
suff = "".join(random.choices(alphabet, k=8))
569568
token.id = pre + suff

Tekst-API/tekst/resources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
ResourceExportFormat,
2929
)
3030
from tekst.models.text import TextDocument
31+
from tekst.utils import ensure
3132

3233

3334
if TYPE_CHECKING:
@@ -278,8 +279,7 @@ async def export_universal_json(
278279
aims to be as comprehensive as possible.
279280
"""
280281
# prepare (root) resource object
281-
text: TextDocument | None = await TextDocument.get(resource.text_id)
282-
assert text
282+
text = ensure(await TextDocument.get(resource.text_id))
283283
res = camelize(
284284
resource.model_dump(
285285
mode="json",
@@ -343,7 +343,7 @@ async def export_universal_json(
343343
)
344344

345345
@classmethod
346-
def resource_model(cls) -> type[ResourceBase]:
346+
def resource_model[T: ResourceBase](cls) -> T:
347347
"""Returns the resource model for this type of resource"""
348348
raise NotImplementedError(
349349
"This method must be implemented by subclasses."

0 commit comments

Comments
 (0)