Skip to content

Commit fd8fa34

Browse files
Replace field docstring with Pydantic Field Description to appear in schemas
1 parent 8824688 commit fd8fa34

File tree

16 files changed

+636
-235
lines changed

16 files changed

+636
-235
lines changed

pydatalab/schemas/cell.json

Lines changed: 86 additions & 8 deletions
Large diffs are not rendered by default.

pydatalab/schemas/equipment.json

Lines changed: 79 additions & 7 deletions
Large diffs are not rendered by default.

pydatalab/schemas/sample.json

Lines changed: 81 additions & 7 deletions
Large diffs are not rendered by default.

pydatalab/schemas/startingmaterial.json

Lines changed: 94 additions & 7 deletions
Large diffs are not rendered by default.

pydatalab/src/pydatalab/models/cells.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,41 @@ class Cell(Item):
3333

3434
type: Literal["cells"] = "cells"
3535

36-
cell_format: CellFormat | None = None
37-
"""The form factor of the cell, e.g., coin, pouch, in situ or otherwise."""
38-
39-
cell_format_description: str | None = None
40-
"""Additional human-readable description of the cell form factor, e.g., 18650, AMPIX, CAMPIX"""
41-
42-
cell_preparation_description: str | None = None
43-
"""Description of how the cell was prepared."""
44-
45-
characteristic_mass: float | None = None
46-
"""The characteristic mass of the cell in milligrams. Can be used to normalize capacities."""
47-
48-
characteristic_chemical_formula: str | None = None
49-
"""The chemical formula of the active material. Can be used to calculated molar mass in g/mol for normalizing capacities."""
50-
51-
characteristic_molar_mass: float | None = None
52-
"""The molar mass of the active material, in g/mol. Will be inferred from the chemical formula, or can be supplied if it cannot be supplied"""
36+
cell_format: CellFormat | None = Field(
37+
None, description="The form factor of the cell, e.g., coin, pouch, in situ or otherwise."
38+
)
39+
40+
cell_format_description: str | None = Field(
41+
None,
42+
description="Additional human-readable description of the cell form factor, e.g., 18650, AMPIX, CAMPIX",
43+
)
44+
45+
cell_preparation_description: str | None = Field(
46+
None, description="Description of how the cell was prepared."
47+
)
48+
49+
characteristic_mass: float | None = Field(
50+
None,
51+
description="The characteristic mass of the cell in milligrams. Can be used to normalize capacities.",
52+
)
53+
54+
characteristic_chemical_formula: str | None = Field(
55+
None,
56+
description="The chemical formula of the active material. Can be used to calculated molar mass in g/mol for normalizing capacities.",
57+
)
58+
59+
characteristic_molar_mass: float | None = Field(
60+
None,
61+
description="The molar mass of the active material, in g/mol. Will be inferred from the chemical formula, or can be supplied if it cannot be supplied",
62+
)
5363

5464
positive_electrode: list[CellComponent] = Field(default_factory=list)
5565
negative_electrode: list[CellComponent] = Field(default_factory=list)
5666
electrolyte: list[CellComponent] = Field(default_factory=list)
5767

5868
active_ion_charge: float = 1
5969

60-
active_ion: str | None = None
61-
"""The active ion species."""
70+
active_ion: str | None = Field(None, description="The active ion species.")
6271

6372
@field_validator("characteristic_molar_mass", mode="before")
6473
@classmethod

pydatalab/src/pydatalab/models/collections.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@
1313
class Collection(Entry, HasOwner, HasBlocks):
1414
type: Literal["collections"] = "collections"
1515

16-
collection_id: HumanReadableIdentifier = Field(None)
17-
"""A short human-readable/usable name for the collection."""
16+
collection_id: HumanReadableIdentifier = Field(
17+
None, description="A short human-readable/usable name for the collection."
18+
)
1819

19-
title: str | None = None
20-
"""A descriptive title for the collection."""
20+
title: str | None = Field(None, description="A descriptive title for the collection.")
2121

22-
description: str | None = None
23-
"""A description of the collection, either in plain-text or a markup language."""
22+
description: str | None = Field(
23+
None,
24+
description="A description of the collection, either in plain-text or a markup language.",
25+
)
2426

25-
num_items: int | None = Field(None)
26-
"""Inlined number of items associated with this collection."""
27+
num_items: int | None = Field(
28+
None, description="Inlined number of items associated with this collection."
29+
)
2730

2831
@model_validator(mode="before")
2932
@classmethod

pydatalab/src/pydatalab/models/entries.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,23 @@ class Entry(BaseModel, abc.ABC):
1616
1717
"""
1818

19-
type: str
20-
"""The resource type of the entry."""
19+
type: str = Field(description="The resource type of the entry.")
2120

2221
immutable_id: PyObjectId | None = Field(
2322
None,
2423
title="Immutable ID",
2524
alias="_id",
2625
json_schema_extra={"format": "uuid"},
26+
description="The immutable database ID of the entry.",
2727
)
28-
"""The immutable database ID of the entry."""
2928

30-
last_modified: IsoformatDateTime | None = None
31-
"""The timestamp at which the entry was last modified."""
29+
last_modified: IsoformatDateTime | None = Field(
30+
None, description="The timestamp at which the entry was last modified."
31+
)
3232

33-
relationships: list[TypedRelationship] = Field(default_factory=list)
34-
"""A list of related entries and their types."""
33+
relationships: list[TypedRelationship] = Field(
34+
default_factory=list, description="A list of related entries and their types."
35+
)
3536

3637
@model_validator(mode="before")
3738
@classmethod
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import Literal
22

3+
from pydantic import Field
4+
35
from pydatalab.models.items import Item
46

57

@@ -8,14 +10,16 @@ class Equipment(Item):
810

911
type: Literal["equipment"] = "equipment"
1012

11-
serial_numbers: str | None = None
12-
"""A string describing one or more serial numbers for the instrument."""
13+
serial_numbers: str | None = Field(
14+
None, description="A string describing one or more serial numbers for the instrument."
15+
)
1316

14-
manufacturer: str | None = None
15-
"""The manufacturer of this piece of equipment"""
17+
manufacturer: str | None = Field(
18+
None, description="The manufacturer of this piece of equipment"
19+
)
1620

17-
location: str | None = None
18-
"""Place where the equipment is located"""
21+
location: str | None = Field(None, description="Place where the equipment is located")
1922

20-
contact: str | None = None
21-
"""Contact information for equipment (e.g., email address or phone number)."""
23+
contact: str | None = Field(
24+
None, description="Contact information for equipment (e.g., email address or phone number)."
25+
)

pydatalab/src/pydatalab/models/files.py

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,48 @@ class File(Entry, HasOwner, HasRevisionControl):
1212

1313
type: Literal["files"] = "files"
1414

15-
size: int | None = None
16-
"""The size of the file on disk in bytes."""
15+
size: int | None = Field(None, description="The size of the file on disk in bytes.")
1716

18-
last_modified_remote: IsoformatDateTime | None = None
19-
"""The last date/time at which the remote file was modified."""
17+
last_modified_remote: IsoformatDateTime | None = Field(
18+
None, description="The last date/time at which the remote file was modified."
19+
)
2020

21-
item_ids: list[str] = Field(default_factory=list)
22-
"""A list of item IDs associated with this file."""
21+
item_ids: list[str] = Field(
22+
default_factory=list, description="A list of item IDs associated with this file."
23+
)
2324

24-
blocks: list[str] = Field(default_factory=list)
25-
"""A list of block IDs associated with this file."""
25+
blocks: list[str] = Field(
26+
default_factory=list, description="A list of block IDs associated with this file."
27+
)
2628

27-
name: str
28-
"""The filename on disk."""
29+
name: str = Field(description="The filename on disk.")
2930

30-
extension: str
31-
"""The file extension that the file was uploaded with."""
31+
extension: str = Field(description="The file extension that the file was uploaded with.")
3232

33-
original_name: str | None = None
34-
"""The raw filename as uploaded."""
33+
original_name: str | None = Field(None, description="The raw filename as uploaded.")
3534

36-
location: str | None = None
37-
"""The location of the file on disk."""
35+
location: str | None = Field(None, description="The location of the file on disk.")
3836

39-
url_path: str | None = None
40-
"""The path to a remote file."""
37+
url_path: str | None = Field(None, description="The path to a remote file.")
4138

42-
source: str | None = None
43-
"""The source of the file, e.g. 'remote' or 'uploaded'."""
39+
source: str | None = Field(
40+
None, description="The source of the file, e.g. 'remote' or 'uploaded'."
41+
)
4442

45-
time_added: IsoformatDateTime
46-
"""The timestamp for the original file upload."""
43+
time_added: IsoformatDateTime = Field(description="The timestamp for the original file upload.")
4744

48-
metadata: dict[Any, Any] | None = None
49-
"""Any additional metadata."""
45+
metadata: dict[Any, Any] | None = Field(None, description="Any additional metadata.")
5046

5147
representation: Any | None = None
5248

53-
source_server_name: str | None = None
54-
"""The server name at which the file is stored."""
49+
source_server_name: str | None = Field(
50+
None, description="The server name at which the file is stored."
51+
)
5552

56-
source_path: str | None = None
57-
"""The path to the file on the remote resource."""
53+
source_path: str | None = Field(
54+
None, description="The path to the file on the remote resource."
55+
)
5856

59-
is_live: bool
60-
"""Whether or not the file should be watched for future updates."""
57+
is_live: bool = Field(
58+
description="Whether or not the file should be watched for future updates."
59+
)

pydatalab/src/pydatalab/models/items.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,33 @@
2121
class Item(Entry, HasOwner, HasRevisionControl, IsCollectable, HasBlocks, abc.ABC):
2222
"""The generic model for data types that will be exposed with their own named endpoints."""
2323

24-
refcode: Refcode | None = None # type: ignore
25-
"""A globally unique immutable ID comprised of the deployment prefix (e.g., `grey`)
26-
and a locally unique string, ideally created with some consistent scheme.
27-
"""
24+
refcode: Refcode | None = Field(
25+
None,
26+
description="A globally unique immutable ID comprised of the deployment prefix (e.g., `grey`) and a locally unique string, ideally created with some consistent scheme.",
27+
)
2828

29-
item_id: HumanReadableIdentifier
30-
"""A locally unique, human-readable identifier for the entry. This ID is mutable."""
29+
item_id: HumanReadableIdentifier = Field(
30+
description="A locally unique, human-readable identifier for the entry. This ID is mutable."
31+
)
3132

32-
description: str | None = None
33-
"""A description of the item, either in plain-text or a markup language."""
33+
description: str | None = Field(
34+
None, description="A description of the item, either in plain-text or a markup language."
35+
)
3436

35-
date: IsoformatDateTime | None = None
36-
"""A relevant 'creation' timestamp for the entry (e.g., purchase date, synthesis date)."""
37+
date: IsoformatDateTime | None = Field(
38+
None,
39+
description="A relevant 'creation' timestamp for the entry (e.g., purchase date, synthesis date).",
40+
)
3741

38-
name: str | None = None
39-
"""An optional human-readable/usable name for the entry."""
42+
name: str | None = Field(
43+
None, description="An optional human-readable/usable name for the entry."
44+
)
4045

41-
files: list[File] | None = None
42-
"""Any files attached to this sample."""
46+
files: list[File] | None = Field(None, description="Any files attached to this sample.")
4347

44-
file_ObjectIds: list[PyObjectId] = Field(default_factory=list)
45-
"""Links to object IDs of files stored within the database."""
48+
file_ObjectIds: list[PyObjectId] = Field(
49+
default_factory=list, description="Links to object IDs of files stored within the database."
50+
)
4651

4752
@field_validator("refcode", mode="before")
4853
@classmethod

0 commit comments

Comments
 (0)