-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 Class extraction compilation initial approach
- Loading branch information
1 parent
4b0d22a
commit b6a8f6d
Showing
18 changed files
with
1,015 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" | ||
This file contains all the functionality to convert from a compiled `AutoflexFieldInfo` or standard pydantic `FieldInfo` | ||
into a AutoflexPropertyType. This way all the fields and annotations can be compiled into a standardized data type | ||
""" | ||
from autoflex.types import FieldTypes | ||
|
||
def compile_field_into_property( | ||
field: FieldTypes | ||
): | ||
""" | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
from dataclasses import field | ||
from typing import Any, Optional | ||
from pydantic import Field | ||
from autoflex.types import AutoflexFieldInfo, AutoflexParameterTypes | ||
from autoflex.types import PhysicalFieldInfo, UnitTypes, SymbolicTypes | ||
|
||
|
||
def AutoflexField( | ||
def PhysicalField( | ||
default: Any = ..., | ||
*, | ||
autoflex_parameters: Optional[AutoflexParameterTypes] = None, | ||
unit: UnitTypes, | ||
math: SymbolicTypes, | ||
**kwargs | ||
) -> AutoflexFieldInfo: | ||
) -> PhysicalFieldInfo: | ||
""" | ||
A wrapper around pydantic's Field function that returns an instance of AutoflexFieldInfo | ||
instead of FieldInfo. | ||
Args: | ||
default: The default value of the field. | ||
autoflex_parameters: An additional argument specific to AutoflexFieldInfo. | ||
unit: The UnitType to represent. | ||
math: The SymbolicType to represent. | ||
**kwargs: Any other keyword arguments passed to pydantic's Field. | ||
Returns: | ||
AutoflexFieldInfo: Custom field info object. | ||
""" | ||
|
||
field_info = Field(default=default, **kwargs) # Call pydantic's Field internally | ||
# Need to compile this into a FieldInfo in order to extract the correct kwargs. | ||
field_info = Field(default=default, **kwargs) | ||
|
||
# Return an instance of AutoflexFieldInfo instead of the default FieldInfo | ||
return AutoflexFieldInfo( | ||
return PhysicalFieldInfo( | ||
default=default, | ||
autoflex=autoflex_parameters, | ||
**field_info.dict(exclude_none=True) | ||
unit=unit, | ||
math=math, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from autoflex.types.parameters import PhysicalParameter, AutoflexParameterTypes | ||
from autoflex.types.descriptors import Unit, Symbolic, SymbolicTypes | ||
from autoflex.types.field import AutoflexFieldInfo | ||
from autoflex.types.property import PhysicalProperty, Property, PropertyTypes | ||
from autoflex.types.descriptors import Symbolic, SymbolicTypes, Unit, UnitTypes | ||
from autoflex.types.field_info import PhysicalFieldInfo, FieldTypes | ||
from autoflex.types.field_info import PhysicalFieldInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pydantic as pd | ||
from autoflex.types.descriptors import UnitTypes, SymbolicTypes | ||
|
||
class PhysicalFieldInfo(pd.fields.FieldInfo): | ||
""" | ||
Each field should correspond to an individual physical property field that can represent it completely within the documentation. | ||
Note that this compiles into a PhysicalProperty accordingly. | ||
""" | ||
|
||
unit: UnitTypes = "" | ||
""" | ||
""" | ||
|
||
math: SymbolicTypes = "" | ||
""" | ||
""" | ||
|
||
|
||
FieldTypes = PhysicalFieldInfo | pd.fields.FieldInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
from pydantic import Field | ||
from autoflex.types.core import AutoflexBaseModel | ||
from autoflex.types.descriptors import Unit, SymbolicTypes | ||
from autoflex.types.descriptors import UnitTypes, SymbolicTypes | ||
|
||
class PhysicalParameter(AutoflexBaseModel): | ||
class Property(AutoflexBaseModel): | ||
""" | ||
Contains all the information encoded in a standard property. | ||
""" | ||
name: str = "" | ||
types: str = "" | ||
description: str = "" | ||
default: str = "" | ||
|
||
|
||
class PhysicalProperty(Property): | ||
""" | ||
This structure instance is a representation of the relevant information that might want to represent in a parameter | ||
row or in another container. | ||
We need the parameter name, the type definition in a format we might want to represent (or even interact with) | ||
a description which may be | ||
""" | ||
name: str = "" | ||
types: str = "" | ||
description: str = "" | ||
math: SymbolicTypes = Field(..., description="The mathematical representation defining the physical parameter in raw string latex") | ||
unit: Unit = Field(..., description="The unit of the physical parameter") | ||
unit: UnitTypes = Field(..., description="The unit of the physical parameter") | ||
|
||
|
||
AutoflexParameterTypes = PhysicalParameter | ||
PropertyTypes = PhysicalProperty | Property |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from autoflex.types import PropertyTypes | ||
|
||
PropertyCollectionTable = list[PropertyTypes] | ||
""" | ||
A property table can be compiled from a list of compiled AutoflexProperties in a standard data type format. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import pydantic as pd | ||
|
||
def determine_pydantic_version_from_base_model(model: pd.BaseModel): | ||
"""Determine if a BaseModel is from Pydantic v1 or v2.""" | ||
if hasattr(model, 'model_fields'): | ||
return 2 | ||
elif hasattr(model, '__fields__'): | ||
return 1 | ||
else: | ||
raise ValueError("Unknown Pydantic version or incompatible BaseModel class.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .basic_class import BasicClass | ||
from .basic_class import BasicClass, BasicMixedAnnotatedClass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
.. code:: | ||
Oops, something went wrong.