-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Re-use core models in SDK #104
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #104 +/- ##
==========================================
- Coverage 75.95% 75.94% -0.01%
==========================================
Files 32 32
Lines 2429 2428 -1
==========================================
- Hits 1845 1844 -1
Misses 584 584 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
for f in class_files: | ||
mod_path = str(f.with_suffix("")).removeprefix(str(root.parent)) | ||
mod = get_module(mod_path) | ||
if mod.startswith("galileo_core.testing"): | ||
continue | ||
module = importlib.import_module(mod) | ||
|
||
print(">>", mod) | ||
for item in dir(module): | ||
ic = getattr(module, item) | ||
if not item.startswith("__") and inspect.isclass(ic) and ic.__module__.startswith("galileo"): | ||
print(" >>", item, camel_to_snake(item)) | ||
with open(f"{MODEL_LOCATION_PREFIX}/{camel_to_snake(item)}.py", "w") as f: | ||
f.write(basemodel_dict_template.render({"unified_file_name": unified_file_name, "item": item})) | ||
mod_import_list.append((mod, item)) | ||
elif ( | ||
not item.startswith("__") | ||
and "__class__" in dir(ic) | ||
and ic.__class__ == typing._AnnotatedAlias | ||
and item not in {"UUID4"} | ||
): | ||
mod_other_list.append((mod, item)) | ||
print() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Core module iteration + class creation + linkage
if issubclass(GalileoCoreMessageClass, BaseModel): | ||
|
||
class Message(GalileoCoreMessageClass): | ||
def to_dict(self) -> dict[str, Any]: | ||
return self.model_dump(exclude_none=True) | ||
|
||
@classmethod | ||
def from_dict(cls, src_dict: dict[str, Any]) -> "Message": | ||
return cls.model_validate(src_dict) | ||
|
||
Message.model_rebuild() | ||
else: | ||
Message = GalileoCoreMessageClass | ||
|
||
|
||
if issubclass(GalileoCoreMessageRoleClass, BaseModel): | ||
|
||
class MessageRole(GalileoCoreMessageRoleClass): | ||
def to_dict(self) -> dict[str, Any]: | ||
return self.model_dump(exclude_none=True) | ||
|
||
@classmethod | ||
def from_dict(cls, src_dict: dict[str, Any]) -> "MessageRole": | ||
return cls.model_validate(src_dict) | ||
|
||
MessageRole.model_rebuild() | ||
else: | ||
MessageRole = GalileoCoreMessageRoleClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generated class wrappers with model rebuilds.
return str(self.value) | ||
# flake: noqa: F401 | ||
# ruff: noqa: F401 | ||
from ..models.all_galileo_core_models import MessageRole |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link individual model file to import the right definition from all model file to ensure generated clients can still use these models.
Summary
Proposed solution and thought process documentation : Link