-
Notifications
You must be signed in to change notification settings - Fork 13
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
BAI-1253 Client Datacard Class #1272
Conversation
bw27492
commented
May 14, 2024
- Added new parent 'Entry' class for both models and datacards.
- Moved non-unique methods from existing model class to new parent class.
- Created new datacard class
name=res["name"], | ||
description=res["description"], | ||
) | ||
datacard._Entry__unpack(res) |
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.
Python lacks real access modifiers, although through name mangling will add _Class
to any method with a double underscore these are considered private and shouldn't be accessed by any child classes. Instead it is convention to use a single underscore for protected methods(methods to be accessed by child classes).
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.
Done
|
||
@property | ||
def data_card(self): | ||
return self.card |
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.
I would make self.card
a protected attribute since you're effectively aliasing it here.
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.
Done
|
||
@property | ||
def data_card_version(self): | ||
return self.card_version |
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.
Same with card_version
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.
Done
|
||
@property | ||
def data_card_schema(self): | ||
return self.card_schema |
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.
Same with card_schema
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.
Done
@classmethod | ||
def create( | ||
cls, | ||
client: Client, | ||
name: str, | ||
description: str, | ||
team_id: str, | ||
visibility: ModelVisibility | None = None, | ||
) -> Datacard: | ||
"""Build a datacard from Bailo and upload it. | ||
|
||
:param client: A client object used to interact with Bailo | ||
:param name: Name of datacard | ||
:param description: Description of datacard | ||
:param team_id: A unique team ID | ||
:param visibility: Visibility of datacard, using ModelVisibility enum (e.g Public or Private), defaults to None | ||
:return: Datacard object | ||
""" | ||
res = client.post_model( | ||
name=name, kind=EntryKind.DATACARD, description=description, team_id=team_id, visibility=visibility | ||
) | ||
datacard = cls( | ||
client=client, | ||
datacard_id=res["model"]["id"], | ||
name=name, | ||
description=description, | ||
visibility=visibility, | ||
) | ||
|
||
datacard._Entry__unpack(res["model"]) | ||
|
||
return datacard | ||
|
||
@classmethod | ||
def from_id(cls, client: Client, datacard_id: str) -> Datacard: | ||
"""Return an existing datacard from Bailo. | ||
|
||
:param client: A client object used to interact with Bailo | ||
:param datacard_id: A unique datacard ID | ||
:return: A datacard object | ||
""" | ||
res = client.get_model(model_id=datacard_id)["model"] | ||
datacard = cls( | ||
client=client, | ||
datacard_id=datacard_id, | ||
name=res["name"], | ||
description=res["description"], | ||
) | ||
datacard._Entry__unpack(res) | ||
|
||
datacard.get_card_latest() | ||
|
||
return datacard |
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.
Can use these as protected class methods in the parent class.
@classmethod | ||
def from_id(cls, client: Client, datacard_id: str) -> Datacard: | ||
"""Return an existing datacard from Bailo. | ||
|
||
:param client: A client object used to interact with Bailo | ||
:param datacard_id: A unique datacard ID | ||
:return: A datacard object | ||
""" | ||
res = client.get_model(model_id=datacard_id)["model"] | ||
datacard = cls( | ||
client=client, | ||
datacard_id=datacard_id, | ||
name=res["name"], | ||
description=res["description"], | ||
) | ||
datacard._Entry__unpack(res) | ||
|
||
datacard.get_card_latest() | ||
|
||
return datacard |
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.
What's stopping me from pulling down a Model as a Datacard here. There isn't anything differentiating them apart from their kind.
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.
Fixed
10c3020
to
eb0e7c3
Compare
eb0e7c3
to
10c3020
Compare