Skip to content

Commit 7b4731f

Browse files
Quick pass at filling in missing docstrings (#367)
* Quick pass at filling in missing docstrings * More punctuation
1 parent cd5e82a commit 7b4731f

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

firebase_admin/mlkit.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def __init__(self, display_name=None, tags=None, model_format=None):
196196

197197
@classmethod
198198
def from_dict(cls, data, app=None):
199+
"""Create an instance of the object from a dict."""
199200
data_copy = dict(data)
200201
tflite_format = None
201202
tflite_format_data = data_copy.pop('tfliteModel', None)
@@ -223,13 +224,16 @@ def __ne__(self, other):
223224

224225
@property
225226
def model_id(self):
227+
"""The model's ID, unique to the project."""
226228
if not self._data.get('name'):
227229
return None
228230
_, model_id = _validate_and_parse_name(self._data.get('name'))
229231
return model_id
230232

231233
@property
232234
def display_name(self):
235+
"""The model's display name, used to refer to the model in code and in
236+
the Firebase console."""
233237
return self._data.get('displayName')
234238

235239
@display_name.setter
@@ -239,7 +243,7 @@ def display_name(self, display_name):
239243

240244
@property
241245
def create_time(self):
242-
"""Returns the creation timestamp"""
246+
"""The time the model was created."""
243247
seconds = self._data.get('createTime', {}).get('seconds')
244248
if not isinstance(seconds, numbers.Number):
245249
return None
@@ -248,7 +252,7 @@ def create_time(self):
248252

249253
@property
250254
def update_time(self):
251-
"""Returns the last update timestamp"""
255+
"""The time the model was last updated."""
252256
seconds = self._data.get('updateTime', {}).get('seconds')
253257
if not isinstance(seconds, numbers.Number):
254258
return None
@@ -257,22 +261,28 @@ def update_time(self):
257261

258262
@property
259263
def validation_error(self):
264+
"""Validation error message."""
260265
return self._data.get('state', {}).get('validationError', {}).get('message')
261266

262267
@property
263268
def published(self):
269+
"""True if the model is published and available for clients to
270+
download."""
264271
return bool(self._data.get('state', {}).get('published'))
265272

266273
@property
267274
def etag(self):
275+
"""The entity tag (ETag) of the model resource."""
268276
return self._data.get('etag')
269277

270278
@property
271279
def model_hash(self):
280+
"""SHA256 hash of the model binary."""
272281
return self._data.get('modelHash')
273282

274283
@property
275284
def tags(self):
285+
"""Tag strings, used for filtering query results."""
276286
return self._data.get('tags')
277287

278288
@tags.setter
@@ -282,6 +292,7 @@ def tags(self, tags):
282292

283293
@property
284294
def locked(self):
295+
"""True if the Model object is locked by an active operation."""
285296
return bool(self._data.get('activeOperations') and
286297
len(self._data.get('activeOperations')) > 0)
287298

@@ -307,6 +318,8 @@ def wait_for_unlocked(self, max_time_seconds=None):
307318

308319
@property
309320
def model_format(self):
321+
"""The model's ``ModelFormat`` object, which represents the model's
322+
format and storage location."""
310323
return self._model_format
311324

312325
@model_format.setter
@@ -317,6 +330,7 @@ def model_format(self, model_format):
317330
return self
318331

319332
def as_dict(self, for_upload=False):
333+
"""Returns a serializable representation of the object."""
320334
copy = dict(self._data)
321335
if self._model_format:
322336
copy.update(self._model_format.as_dict(for_upload=for_upload))
@@ -326,6 +340,7 @@ def as_dict(self, for_upload=False):
326340
class ModelFormat(object):
327341
"""Abstract base class representing a Model Format such as TFLite."""
328342
def as_dict(self, for_upload=False):
343+
"""Returns a serializable representation of the object."""
329344
raise NotImplementedError
330345

331346

@@ -344,6 +359,7 @@ def __init__(self, model_source=None):
344359

345360
@classmethod
346361
def from_dict(cls, data):
362+
"""Create an instance of the object from a dict."""
347363
data_copy = dict(data)
348364
model_source = None
349365
gcs_tflite_uri = data_copy.pop('gcsTfliteUri', None)
@@ -366,6 +382,7 @@ def __ne__(self, other):
366382

367383
@property
368384
def model_source(self):
385+
"""The TF Lite model's location."""
369386
return self._model_source
370387

371388
@model_source.setter
@@ -377,9 +394,11 @@ def model_source(self, model_source):
377394

378395
@property
379396
def size_bytes(self):
397+
"""The size in bytes of the TF Lite model."""
380398
return self._data.get('sizeBytes')
381399

382400
def as_dict(self, for_upload=False):
401+
"""Returns a serializable representation of the object."""
383402
copy = dict(self._data)
384403
if self._model_source:
385404
copy.update(self._model_source.as_dict(for_upload=for_upload))
@@ -389,6 +408,7 @@ def as_dict(self, for_upload=False):
389408
class TFLiteModelSource(object):
390409
"""Abstract base class representing a model source for TFLite format models."""
391410
def as_dict(self, for_upload=False):
411+
"""Returns a serializable representation of the object."""
392412
raise NotImplementedError
393413

394414

@@ -415,6 +435,7 @@ def _parse_gcs_tflite_uri(uri):
415435

416436
@staticmethod
417437
def upload(bucket_name, model_file_name, app):
438+
"""Upload a model file to the specified Storage bucket."""
418439
_CloudStorageClient._assert_gcs_enabled()
419440
bucket = storage.bucket(bucket_name, app=app)
420441
blob_name = _CloudStorageClient.BLOB_NAME.format(model_file_name)
@@ -531,6 +552,7 @@ def from_keras_model(cls, keras_model, bucket_name=None, app=None):
531552

532553
@property
533554
def gcs_tflite_uri(self):
555+
"""URI of the model file in Cloud Storage."""
534556
return self._gcs_tflite_uri
535557

536558
@gcs_tflite_uri.setter
@@ -542,6 +564,7 @@ def _get_signed_gcs_tflite_uri(self):
542564
return TFLiteGCSModelSource._STORAGE_CLIENT.sign_uri(self._gcs_tflite_uri, self._app)
543565

544566
def as_dict(self, for_upload=False):
567+
"""Returns a serializable representation of the object."""
545568
if for_upload:
546569
return {'gcsTfliteUri': self._get_signed_gcs_tflite_uri()}
547570

@@ -578,11 +601,12 @@ def list_filter(self):
578601

579602
@property
580603
def next_page_token(self):
604+
"""Token identifying the next page of results."""
581605
return self._list_response.get('nextPageToken', '')
582606

583607
@property
584608
def has_next_page(self):
585-
"""A boolean indicating whether more pages are available."""
609+
"""True if more pages are available."""
586610
return bool(self.next_page_token)
587611

588612
def get_next_page(self):

0 commit comments

Comments
 (0)