Skip to content

Move created_by/updated_by to Identifiable #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ addopts = [
"--durations=10",
"--durations-min=1.0",
]
filterwarnings = [
"error::pydantic.warnings.PydanticDeprecatedSince20"
]

[tool.ruff]
line-length = 100
Expand Down
2 changes: 1 addition & 1 deletion src/entitysdk/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Models for entitysdk."""

from entitysdk.models.agent import Organization, Person
from entitysdk.models.asset import Asset
from entitysdk.models.brain_location import BrainLocation
from entitysdk.models.brain_region import BrainRegion
from entitysdk.models.brain_region_hierarchy import BrainRegionHierarchy
from entitysdk.models.circuit import Circuit
from entitysdk.models.classification import ETypeClassification, MTypeClassification
from entitysdk.models.contribution import Contribution, Role
from entitysdk.models.core import Organization, Person
from entitysdk.models.electrical_cell_recording import ElectricalCellRecording
from entitysdk.models.emodel import EModel
from entitysdk.models.ion_channel_model import IonChannelModel, NeuronBlock, UseIon
Expand Down
71 changes: 0 additions & 71 deletions src/entitysdk/models/agent.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/entitysdk/models/contribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from pydantic import Field

from entitysdk.models.agent import AgentUnion
from entitysdk.models.core import Identifiable
from entitysdk.models.core import AgentUnion, Identifiable


class Role(Identifiable):
Expand Down
88 changes: 83 additions & 5 deletions src/entitysdk/models/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Core models."""

from datetime import datetime
from typing import Annotated
from typing import Annotated, Literal

from pydantic import Field

Expand All @@ -22,17 +22,95 @@ class Identifiable(BaseModel):
description="The primary key identifier of the resource.",
),
] = None
update_date: Annotated[
creation_date: Annotated[
datetime | None,
Field(
examples=[datetime(2025, 1, 1)],
description="The date and time the resource was last updated.",
description="The date and time the resource was created.",
),
] = None
creation_date: Annotated[
update_date: Annotated[
datetime | None,
Field(
examples=[datetime(2025, 1, 1)],
description="The date and time the resource was created.",
description="The date and time the resource was last updated.",
),
] = None
created_by: Annotated[
"Person | None",
Field(description="The agent that created this entity."),
] = None
updated_by: Annotated[
"Person | None",
Field(
description="The agent that updated this entity.",
),
] = None


class Agent(Identifiable):
"""Agent model."""

type: Annotated[
str,
Field(
description="The type of this agent.",
),
]
pref_label: Annotated[
str,
Field(
description="The preferred label of the agent.",
),
]


class Person(Agent):
"""Person model."""

type: Annotated[
Literal["person"],
Field(
description="The type of this agent. Should be 'agent'",
),
] = "person"
given_name: Annotated[
str | None,
Field(
examples=["John", "Jane"],
description="The given name of the person.",
),
] = None
family_name: Annotated[
str | None,
Field(
examples=["Doe", "Smith"],
description="The family name of the person.",
),
] = None


# update forward reference in Identifiable's created_by/uodated_by
Identifiable.model_rebuild()


class Organization(Agent):
"""Organization model."""

type: Annotated[
Literal["organization"],
Field(
default="organization",
description="The organization type. Should be 'organization'",
),
] = "organization"
alternative_name: Annotated[
str | None,
Field(
examples=["Open Brain Institute"],
description="The alternative name of the organization.",
),
] = None


AgentUnion = Annotated[Person | Organization, Field(discriminator="type")]
11 changes: 0 additions & 11 deletions src/entitysdk/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pydantic import Field

from entitysdk.mixin import HasAssets
from entitysdk.models.agent import AgentUnion
from entitysdk.models.core import Identifiable
from entitysdk.types import ID

Expand Down Expand Up @@ -35,16 +34,6 @@ class Entity(Identifiable, HasAssets):
description="The type of this Entity.",
),
] = None
created_by: Annotated[
AgentUnion | None,
Field(description="The agent that created this entity."),
] = None
updated_by: Annotated[
AgentUnion | None,
Field(
description="The agent that updated this entity.",
),
] = None
authorized_public: Annotated[
bool,
Field(
Expand Down
8 changes: 4 additions & 4 deletions src/entitysdk/models/memodelcalibrationresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ class MEModelCalibrationResult(Entity):
float,
Field(
description="The holding current to apply to the simulatable neuron, in nA.",
example=-0.016,
examples=-0.016,
),
]
threshold_current: Annotated[
float,
Field(
description="The minimal amount of current needed to make "
"the simulatable neuron spike, in nA.",
example=0.1,
examples=0.1,
),
]
rin: Annotated[
float | None,
Field(
description="The input resistance of the simulatable neuron, in MOhm.",
example=0.1,
examples=0.1,
),
] = None
calibrated_entity_id: Annotated[
ID,
Field(
description="ID of the calibrated entity.",
example="85663316-a7ff-4107-9eb9-236de8868c5c",
examples="85663316-a7ff-4107-9eb9-236de8868c5c",
),
]
6 changes: 3 additions & 3 deletions src/entitysdk/models/validation_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ class ValidationResult(Entity):
bool,
Field(
description="True if the validation passed, False otherwise.",
example=True,
examples=True,
),
]
name: Annotated[
str,
Field(
description="Name of the validation.",
example="Neuron spiking validation",
examples="Neuron spiking validation",
),
]
validated_entity_id: Annotated[
ID,
Field(
description="ID of the validated entity.",
example="85663316-a7ff-4107-9eb9-236de8868c5c",
examples="85663316-a7ff-4107-9eb9-236de8868c5c",
),
]
16 changes: 12 additions & 4 deletions tests/unit/models/data/circuit.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"type": "person",
"pref_label": "Admin User",
"given_name": null,
"family_name": null
"family_name": null,
"created_by": null,
"updated_by": null
},
"updated_by": {
"id": "e8997b32-0183-42c8-b11f-1a61da933a89",
Expand All @@ -22,7 +24,9 @@
"type": "person",
"pref_label": "Admin User",
"given_name": null,
"family_name": null
"family_name": null,
"created_by": null,
"updated_by": null
},
"authorized_public": false,
"authorized_project_id": "0dbced5f-cc3d-488a-8c7f-cfb8ea039dc6",
Expand Down Expand Up @@ -56,7 +60,9 @@
"update_date": null,
"creation_date": null,
"name": "Mus musculus",
"taxonomy_id": "NCBITaxon:10090"
"taxonomy_id": "NCBITaxon:10090",
"created_by": null,
"updated_by": null
}
},
"brain_region": {
Expand All @@ -68,7 +74,9 @@
"acronym": "CB",
"parent_structure_id": "7f22cd12-07b6-408e-aac1-ca75afb918c8",
"hierarchy_id": "f728b4fa-4248-4e3a-8a5d-2f346baa9455",
"color_hex_triplet": "F0F080"
"color_hex_triplet": "F0F080",
"created_by": null,
"updated_by": null
},
"license": null,
"has_morphologies": false,
Expand Down
Loading