Skip to content

Commit 2508e6b

Browse files
authored
[HWORKS-2100] DatasetAPI docs should hide newly added internal functions (#517) (#518)
1 parent e154e7a commit 2508e6b

File tree

2 files changed

+113
-58
lines changed

2 files changed

+113
-58
lines changed

python/auto_doc.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,18 @@
137137
"api/datasets.md": {
138138
"dataset_api_handle": ["hopsworks.project.Project.get_dataset_api"],
139139
"dataset_methods": keras_autodoc.get_methods(
140-
"hopsworks.core.dataset_api.DatasetApi", exclude=EXCLUDE_METHODS
140+
"hopsworks.core.dataset_api.DatasetApi",
141+
exclude=EXCLUDE_METHODS
142+
+ [
143+
"get",
144+
"add",
145+
"get_tags",
146+
"delete",
147+
"path_exists",
148+
"rm",
149+
"list",
150+
"list_files",
151+
],
141152
),
142153
},
143154
"api/kafka_topic.md": {

python/hopsworks_common/core/dataset_api.py

+101-57
Original file line numberDiff line numberDiff line change
@@ -400,25 +400,27 @@ def _upload_request(self, params, path, file_name, chunk):
400400
)
401401

402402
def _get(self, path: str):
403-
"""Get dataset.
403+
"""Get dataset metadata.
404404
405-
:param path: path to check
406-
:type path: str
407-
:return: dataset metadata
408-
:rtype: dict
405+
# Arguments
406+
path: path to check
407+
# Returns
408+
`dict`: dataset metadata
409409
"""
410410
_client = client.get_instance()
411411
path_params = ["project", _client._project_id, "dataset", path]
412412
headers = {"content-type": "application/json"}
413413
return _client._send_request("GET", path_params, headers=headers)
414414

415415
def get(self, path: str):
416-
"""Get dataset.
416+
"""**Deprecated**
417+
418+
Get dataset metadata.
417419
418-
:param path: path to check
419-
:type path: str
420-
:return: dataset metadata
421-
:rtype: dict
420+
# Arguments
421+
path: path to check
422+
# Returns
423+
`dict`: dataset metadata
422424
"""
423425
return self._get(path)
424426

@@ -429,8 +431,6 @@ def exists(self, path: str):
429431
path: path to check
430432
# Returns
431433
`bool`: True if exists, otherwise False
432-
# Raises
433-
`hopsworks.client.exceptions.RestAPIError`: If the backend encounters an error when handling the request
434434
"""
435435
try:
436436
self._get(path)
@@ -439,12 +439,14 @@ def exists(self, path: str):
439439
return False
440440

441441
def path_exists(self, remote_path: str):
442-
"""Check if a path exists in datasets.
442+
"""**Deprecated**, use `exists` instead.
443+
444+
Check if a path exists in datasets.
443445
444-
:param remote_path: path to check
445-
:type remote_path: str
446-
:return: boolean whether path exists
447-
:rtype: bool
446+
# Arguments
447+
remote_path: path to check
448+
# Returns
449+
`bool`: True if exists, otherwise False
448450
"""
449451
return self.exists(remote_path)
450452

@@ -462,7 +464,9 @@ def remove(self, path: str):
462464
return _client._send_request("DELETE", path_params)
463465

464466
def rm(self, remote_path: str):
465-
"""Remove a path in the Hopsworks Filesystem.
467+
"""**Deprecated**, use `remove` instead.
468+
469+
Remove a path in the Hopsworks Filesystem.
466470
467471
# Arguments
468472
remote_path: path to remove
@@ -526,6 +530,7 @@ def copy(self, source_path: str, destination_path: str, overwrite: bool = False)
526530
destination_path: the destination path
527531
overwrite: overwrite destination if exists
528532
# Raises
533+
`hopsworks.client.exceptions.DatasetException`: If the destination path already exists and overwrite is not set to True
529534
`hopsworks.client.exceptions.RestAPIError`: If the backend encounters an error when handling the request
530535
"""
531536
if self.exists(destination_path):
@@ -571,6 +576,7 @@ def move(self, source_path: str, destination_path: str, overwrite: bool = False)
571576
destination_path: the destination path
572577
overwrite: overwrite destination if exists
573578
# Raises
579+
`hopsworks.client.exceptions.DatasetException`: If the destination path already exists and overwrite is not set to True
574580
`hopsworks.client.exceptions.RestAPIError`: If the backend encounters an error when handling the request
575581
"""
576582
if self.exists(destination_path):
@@ -625,7 +631,18 @@ def upload_feature_group(self, feature_group, path, dataframe):
625631
chunk_number += 1
626632

627633
@usage.method_logger
628-
def list_files(self, path, offset, limit):
634+
def list_files(self, path: str, offset: int, limit: int):
635+
"""**Deprecated**
636+
637+
List contents of a directory in the Hopsworks Filesystem.
638+
639+
# Arguments
640+
path: path to the directory to list the contents of.
641+
offset: the number of Inodes to skip.
642+
limit: max number of the returned Inodes.
643+
# Returns
644+
`tuple[int, list[hopsworks.core.inode.Inode]]`: count of Inodes in the directory and the list of them.
645+
"""
629646
_client = client.get_instance()
630647
path_params = [
631648
"project",
@@ -645,21 +662,33 @@ def list_files(self, path, offset, limit):
645662
return inode_lst["count"], inode.Inode.from_response_json(inode_lst)
646663

647664
@usage.method_logger
648-
def list(self, remote_path, sort_by=None, offset=0, limit=1000):
649-
"""List all files in a directory in datasets.
650-
651-
:param remote_path: path to list
652-
:type remote_path: str
653-
:param sort_by: sort string
654-
:type sort_by: str
655-
:param limit: max number of returned files
656-
:type limit: int
665+
def list(
666+
self,
667+
remote_path: str,
668+
sort_by: str | None = None,
669+
offset: int = 0,
670+
limit: int = 1000,
671+
):
672+
"""**Deprecated**
673+
674+
List contents of a directory in the Hopsworks Filesystem.
675+
676+
# Arguments
677+
remote_path: path to the directory to list the contents of.
678+
sort_by: sort string, for example `"ID:asc"`.
679+
offset: the number of entities to skip.
680+
limit: max number of the returned entities.
657681
"""
658682
# this method is probably to be merged with list_files
659683
# they seem to handle paths differently and return different results, which prevents the merge at the moment (2024-09-03), due to the requirement of backwards-compatibility
660684
_client = client.get_instance()
661685
path_params = ["project", _client._project_id, "dataset", remote_path]
662-
query_params = {"action": "listing", "sort_by": sort_by, "limit": limit, "offset": offset}
686+
query_params = {
687+
"action": "listing",
688+
"sort_by": sort_by,
689+
"limit": limit,
690+
"offset": offset,
691+
}
663692
headers = {"content-type": "application/json"}
664693
return _client._send_request(
665694
"GET", path_params, headers=headers, query_params=query_params
@@ -684,13 +713,16 @@ def read_content(self, path: str, dataset_type: str = "DATASET"):
684713

685714
return _client._send_request("GET", path_params, query_params, stream=True)
686715

687-
def chmod(self, remote_path, permissions):
688-
"""Chmod operation on file or directory in datasets.
716+
def chmod(self, remote_path: str, permissions: str):
717+
"""Change permissions of a file or a directory in the Hopsworks Filesystem.
689718
690-
:param remote_path: path to chmod
691-
:type remote_path: str
692-
:param permissions: permissions string, for example u+x
693-
:type permissions: str
719+
# Arguments
720+
remote_path: path to change the permissions of.
721+
permissions: permissions string, for example `"u+x"`.
722+
# Returns
723+
`dict`: the updated dataset metadata
724+
# Raises
725+
`hopsworks.client.exceptions.RestAPIError`: If the backend encounters an error when handling the request
694726
"""
695727
_client = client.get_instance()
696728
path_params = ["project", _client._project_id, "dataset", remote_path]
@@ -721,6 +753,9 @@ def _archive(
721753
722754
# Returns
723755
`bool`: whether the operation completed in the specified timeout; if non-blocking, always returns True.
756+
757+
# Raises
758+
`hopsworks.client.exceptions.RestAPIError`: If the backend encounters an error when handling the request
724759
"""
725760

726761
_client = client.get_instance()
@@ -789,6 +824,9 @@ def unzip(
789824
790825
# Returns
791826
`bool`: whether the operation completed in the specified timeout; if non-blocking, always returns True.
827+
828+
# Raises
829+
`hopsworks.client.exceptions.RestAPIError`: If the backend encounters an error when handling the request
792830
"""
793831
return self._archive(remote_path, block=block, timeout=timeout, action="unzip")
794832

@@ -809,6 +847,9 @@ def zip(
809847
810848
# Returns
811849
`bool`: whether the operation completed in the specified timeout; if non-blocking, always returns True.
850+
851+
# Raises
852+
`hopsworks.client.exceptions.RestAPIError`: If the backend encounters an error when handling the request
812853
"""
813854
return self._archive(
814855
remote_path,
@@ -820,18 +861,18 @@ def zip(
820861

821862
# region Dataset Tags
822863

823-
def add(self, path, name, value):
824-
"""Attach a name/value tag to a model.
864+
def add(self, path: str, name: str, value: str):
865+
"""**Deprecated**
866+
867+
Attach a name/value tag to a model.
825868
826869
A tag consists of a name/value pair. Tag names are unique identifiers.
827870
The value of a tag can be any valid json - primitives, arrays or json objects.
828871
829-
:param path: path to add the tag
830-
:type path: str
831-
:param name: name of the tag to be added
832-
:type name: str
833-
:param value: value of the tag to be added
834-
:type value: str
872+
# Arguments
873+
path: path to add the tag
874+
name: name of the tag to be added
875+
value: value of the tag to be added
835876
"""
836877
_client = client.get_instance()
837878
path_params = [
@@ -847,15 +888,16 @@ def add(self, path, name, value):
847888
json_value = json.dumps(value)
848889
_client._send_request("PUT", path_params, headers=headers, data=json_value)
849890

850-
def delete(self, path, name):
851-
"""Delete a tag.
891+
def delete(self, path: str, name: str):
892+
"""**Deprecated**
893+
894+
Delete a tag.
852895
853896
Tag names are unique identifiers.
854897
855-
:param path: path to delete the tags
856-
:type path: str
857-
:param name: name of the tag to be removed
858-
:type name: str
898+
# Arguments
899+
path: path to delete the tags
900+
name: name of the tag to be removed
859901
"""
860902
_client = client.get_instance()
861903
path_params = [
@@ -869,17 +911,19 @@ def delete(self, path, name):
869911
]
870912
_client._send_request("DELETE", path_params)
871913

872-
def get_tags(self, path, name: str = None):
873-
"""Get the tags.
914+
def get_tags(self, path: str, name: str | None = None):
915+
"""**Deprecated**
916+
917+
Get the tags.
874918
875919
Gets all tags if no tag name is specified.
876920
877-
:param path: path to get the tags
878-
:type path: str
879-
:param name: tag name
880-
:type name: str
881-
:return: dict of tag name/values
882-
:rtype: dict
921+
# Arguments
922+
path: path to get the tags
923+
name: tag name
924+
925+
# Returns
926+
`dict`: tag names and values
883927
"""
884928
_client = client.get_instance()
885929
path_params = [

0 commit comments

Comments
 (0)