Skip to content

Commit 369cc40

Browse files
Make all models available under entitysdk.models (#46)
1 parent 45886a8 commit 369cc40

File tree

9 files changed

+194
-125
lines changed

9 files changed

+194
-125
lines changed

examples/01_searching.ipynb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
"\n",
1414
"from entitysdk.client import Client\n",
1515
"from entitysdk.common import ProjectContext\n",
16-
"from entitysdk.models.agent import Organization, Person\n",
17-
"from entitysdk.models.contribution import Role\n",
18-
"from entitysdk.models.morphology import (\n",
16+
"from entitysdk.models import (\n",
17+
" MTypeClass,\n",
18+
" Organization,\n",
19+
" Person,\n",
1920
" ReconstructionMorphology,\n",
21+
" Role,\n",
2022
" Species,\n",
2123
" Strain,\n",
2224
")\n",
23-
"from entitysdk.models.mtype import MTypeClass\n",
2425
"\n",
2526
"entitycore_api_url = \"http://127.0.0.1:8000\"\n",
2627
"project_context = ProjectContext(\n",

examples/02_morphology.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"\n",
1717
"from entitysdk.client import Client\n",
1818
"from entitysdk.common import ProjectContext\n",
19-
"from entitysdk.models.morphology import (\n",
19+
"from entitysdk.models import (\n",
2020
" BrainLocation,\n",
2121
" BrainRegion,\n",
2222
" ReconstructionMorphology,\n",

examples/03_contribution.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
"\n",
1414
"from entitysdk.client import Client\n",
1515
"from entitysdk.common import ProjectContext\n",
16-
"from entitysdk.models.agent import Organization\n",
17-
"from entitysdk.models.contribution import Contribution, Role\n",
18-
"from entitysdk.models.morphology import ReconstructionMorphology\n",
16+
"from entitysdk.models import Contribution, Organization, ReconstructionMorphology, Role\n",
1917
"\n",
2018
"entitycore_api_url = \"http://127.0.0.1:8000\"\n",
2119
"project_context = ProjectContext(\n",

src/entitysdk/models/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
11
"""Models for entitysdk."""
2+
3+
from entitysdk.models.agent import Organization, Person
4+
from entitysdk.models.asset import Asset
5+
from entitysdk.models.brain_location import BrainLocation
6+
from entitysdk.models.brain_region import BrainRegion
7+
from entitysdk.models.contribution import Contribution, Role
8+
from entitysdk.models.entity import Entity
9+
from entitysdk.models.ion_channel_model import IonChannelModel, NeuronBlock, UseIon
10+
from entitysdk.models.morphology import ReconstructionMorphology
11+
from entitysdk.models.mtype import MTypeClass
12+
from entitysdk.models.taxonomy import Species, Strain, Taxonomy
13+
14+
__all__ = [
15+
"Asset",
16+
"BrainLocation",
17+
"BrainRegion",
18+
"Contribution",
19+
"Entity",
20+
"IonChannelModel",
21+
"MTypeClass",
22+
"NeuronBlock",
23+
"Organization",
24+
"Person",
25+
"ReconstructionMorphology",
26+
"Role",
27+
"Species",
28+
"Strain",
29+
"Taxonomy",
30+
"UseIon",
31+
]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Brain location model."""
2+
3+
from typing import Annotated
4+
5+
from pydantic import Field
6+
7+
from entitysdk.models.core import Struct
8+
9+
10+
class BrainLocation(Struct):
11+
"""BrainLocation model."""
12+
13+
x: Annotated[
14+
float,
15+
Field(
16+
examples=[1.0, 2.0, 3.0],
17+
description="The x coordinate of the brain location.",
18+
),
19+
]
20+
y: Annotated[
21+
float,
22+
Field(
23+
examples=[1.0, 2.0, 3.0],
24+
description="The y coordinate of the brain location.",
25+
),
26+
]
27+
z: Annotated[
28+
float,
29+
Field(
30+
examples=[1.0, 2.0, 3.0],
31+
description="The z coordinate of the brain location.",
32+
),
33+
]

src/entitysdk/models/license.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""License model."""
2+
3+
from typing import Annotated
4+
5+
from pydantic import Field
6+
7+
from entitysdk.models.entity import Entity
8+
9+
10+
class License(Entity):
11+
"""License model."""
12+
13+
name: Annotated[
14+
str,
15+
Field(
16+
examples=["Apache 2.0"],
17+
description="The name of the license.",
18+
),
19+
]
20+
description: Annotated[
21+
str,
22+
Field(
23+
examples=["The 2.0 version of the Apache License"],
24+
description="The description of the license.",
25+
),
26+
]
27+
label: Annotated[
28+
str,
29+
Field(
30+
examples=["Apache 2.0"],
31+
description="The label of the license.",
32+
),
33+
]

src/entitysdk/models/morphology.py

Lines changed: 3 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -5,127 +5,13 @@
55
from pydantic import Field
66

77
from entitysdk.mixin import HasAssets
8+
from entitysdk.models.brain_location import BrainLocation
89
from entitysdk.models.brain_region import BrainRegion
910
from entitysdk.models.contribution import Contribution
10-
from entitysdk.models.core import Struct
1111
from entitysdk.models.entity import Entity
12+
from entitysdk.models.license import License
1213
from entitysdk.models.mtype import MTypeClass
13-
from entitysdk.typedef import ID
14-
15-
16-
class License(Entity):
17-
"""License model."""
18-
19-
name: Annotated[
20-
str,
21-
Field(
22-
examples=["Apache 2.0"],
23-
description="The name of the license.",
24-
),
25-
]
26-
description: Annotated[
27-
str,
28-
Field(
29-
examples=["The 2.0 version of the Apache License"],
30-
description="The description of the license.",
31-
),
32-
]
33-
label: Annotated[
34-
str,
35-
Field(
36-
examples=["Apache 2.0"],
37-
description="The label of the license.",
38-
),
39-
]
40-
41-
42-
class BrainLocation(Struct):
43-
"""BrainLocation model."""
44-
45-
x: Annotated[
46-
float,
47-
Field(
48-
examples=[1.0, 2.0, 3.0],
49-
description="The x coordinate of the brain location.",
50-
),
51-
]
52-
y: Annotated[
53-
float,
54-
Field(
55-
examples=[1.0, 2.0, 3.0],
56-
description="The y coordinate of the brain location.",
57-
),
58-
]
59-
z: Annotated[
60-
float,
61-
Field(
62-
examples=[1.0, 2.0, 3.0],
63-
description="The z coordinate of the brain location.",
64-
),
65-
]
66-
67-
68-
class Taxonomy(Entity):
69-
"""Taxonomy model."""
70-
71-
name: Annotated[
72-
str,
73-
Field(
74-
examples=["Homo sapiens"],
75-
description="The name of the taxonomy.",
76-
),
77-
]
78-
pref_label: Annotated[
79-
str,
80-
Field(
81-
examples=["Homo sapiens"],
82-
description="The preferred label of the taxonomy.",
83-
),
84-
]
85-
86-
87-
class Species(Entity):
88-
"""Species model."""
89-
90-
name: Annotated[
91-
str,
92-
Field(
93-
examples=["Mus musculus"],
94-
description="The name of the species.",
95-
),
96-
]
97-
taxonomy_id: Annotated[
98-
str,
99-
Field(
100-
examples=["1"],
101-
description="The taxonomy id of the species.",
102-
),
103-
]
104-
105-
106-
class Strain(Entity):
107-
"""Strain model."""
108-
109-
name: Annotated[
110-
str,
111-
Field(
112-
examples=["C57BL/6J"],
113-
description="The name of the strain.",
114-
),
115-
]
116-
taxonomy_id: Annotated[
117-
str,
118-
Field(
119-
examples=["1"],
120-
description="The taxonomy id of the strain.",
121-
),
122-
]
123-
species_id: Annotated[
124-
ID,
125-
Field(
126-
description="The species id of the strain.",
127-
),
128-
]
14+
from entitysdk.models.taxonomy import Species, Strain
12915

13016

13117
class ReconstructionMorphology(HasAssets, Entity):

src/entitysdk/models/taxonomy.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""License model."""
2+
3+
from typing import Annotated
4+
5+
from pydantic import Field
6+
7+
from entitysdk.models.entity import Entity
8+
from entitysdk.typedef import ID
9+
10+
11+
class Species(Entity):
12+
"""Species model."""
13+
14+
name: Annotated[
15+
str,
16+
Field(
17+
examples=["Mus musculus"],
18+
description="The name of the species.",
19+
),
20+
]
21+
taxonomy_id: Annotated[
22+
str,
23+
Field(
24+
examples=["1"],
25+
description="The taxonomy id of the species.",
26+
),
27+
]
28+
29+
30+
class Strain(Entity):
31+
"""Strain model."""
32+
33+
name: Annotated[
34+
str,
35+
Field(
36+
examples=["C57BL/6J"],
37+
description="The name of the strain.",
38+
),
39+
]
40+
taxonomy_id: Annotated[
41+
str,
42+
Field(
43+
examples=["1"],
44+
description="The taxonomy id of the strain.",
45+
),
46+
]
47+
species_id: Annotated[
48+
ID,
49+
Field(
50+
description="The species id of the strain.",
51+
),
52+
]
53+
54+
55+
class Taxonomy(Entity):
56+
"""Taxonomy model."""
57+
58+
name: Annotated[
59+
str,
60+
Field(
61+
examples=["Homo sapiens"],
62+
description="The name of the taxonomy.",
63+
),
64+
]
65+
pref_label: Annotated[
66+
str,
67+
Field(
68+
examples=["Homo sapiens"],
69+
description="The preferred label of the taxonomy.",
70+
),
71+
]

tests/unit/models/test_init.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import inspect
2+
3+
from entitysdk import models
4+
5+
6+
def test_models_all():
7+
"""Ensure that the models imported in enttysdk.models.__init__.py are consistent with __all__"""
8+
imported_names = sorted(
9+
name for name, element in inspect.getmembers(models) if inspect.isclass(element)
10+
)
11+
all_dict_names = sorted(models.__all__)
12+
13+
assert imported_names == all_dict_names, (
14+
"Imported classes and __all__ in entitysdk.models.__init__.py are not consistent.\n"
15+
f"Imported models : {imported_names}\n"
16+
f"Names in __all__:"
17+
)

0 commit comments

Comments
 (0)