-
Notifications
You must be signed in to change notification settings - Fork 360
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
Python Wrapper: Objects generator #7110
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
|
||
from lakefs.namedtuple import LenientNamedTuple | ||
|
||
_PREFIX = "common_prefix" | ||
_OBJECT = "object" | ||
|
||
|
||
class Commit(LenientNamedTuple): | ||
""" | ||
|
@@ -74,12 +77,11 @@ class ServerStorageConfiguration(LenientNamedTuple): | |
default_namespace_prefix: Optional[str] = None | ||
|
||
|
||
class ObjectStats(LenientNamedTuple): | ||
class ObjectInfo(LenientNamedTuple): | ||
""" | ||
Represent a lakeFS object's stats | ||
""" | ||
path: str | ||
path_type: str | ||
physical_address: str | ||
checksum: str | ||
mtime: int | ||
|
@@ -89,6 +91,13 @@ class ObjectStats(LenientNamedTuple): | |
content_type: Optional[str] = None | ||
|
||
|
||
class CommonPrefix(LenientNamedTuple): | ||
""" | ||
Represents a common prefix in lakeFS | ||
""" | ||
path: str | ||
|
||
Comment on lines
+94
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it's still wanted, but on the initial PRD CommonPrefix has an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, both ObjectInfo and CommonPrefix are data models and do not contain logic. For now it feels redundant providing them with functionality that is accessible via the branch / object level methods. Lets see if there's demand for that and add it as needed |
||
|
||
class RepositoryProperties(LenientNamedTuple): | ||
""" | ||
Represent a lakeFS repository's properties | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,10 @@ | |
|
||
import lakefs_sdk | ||
|
||
from lakefs.models import Commit, Change | ||
from lakefs.models import Commit, Change, CommonPrefix, ObjectInfo, _OBJECT | ||
from lakefs.client import Client, DEFAULT_CLIENT | ||
from lakefs.exceptions import api_exception_handler | ||
from lakefs.object import StoredObject | ||
from lakefs.object_manager import ObjectManager | ||
|
||
|
||
class Reference: | ||
|
@@ -43,12 +42,36 @@ def id(self) -> str: | |
""" | ||
return self._id | ||
|
||
@property | ||
def objects(self) -> ObjectManager: | ||
def objects(self, | ||
max_amount: Optional[int] = None, | ||
after: Optional[str] = None, | ||
prefix: Optional[str] = None, | ||
delimiter: Optional[str] = None, | ||
**kwargs) -> Generator[StoredObject | CommonPrefix]: | ||
""" | ||
Returns a ObjectManager object for this reference | ||
Returns an object generator for this reference | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. object/common_prefix or find a better way to phrase it (even though the name of the method is objects) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add more doc information |
||
|
||
:param max_amount: Stop showing changes after this amount | ||
:param after: Return items after this value | ||
:param prefix: Return items prefixed with this value | ||
:param delimiter: Group common prefixes by this delimiter | ||
:param kwargs: Additional Keyword Arguments to send to the server | ||
:raises: | ||
NotFoundException if this reference or other_ref does not exist | ||
NotAuthorizedException if user is not authorized to perform this operation | ||
ServerException for any other errors | ||
""" | ||
# TODO: Implement | ||
|
||
for res in generate_listing(self._client.sdk_client.objects_api.list_objects, | ||
repository=self._repo_id, | ||
ref=self._id, | ||
max_amount=max_amount, | ||
after=after, | ||
prefix=prefix, | ||
delimiter=delimiter, | ||
**kwargs): | ||
type_class = ObjectInfo if res.path_type == _OBJECT else CommonPrefix | ||
yield type_class(**res.dict()) | ||
|
||
def log(self, max_amount: Optional[int] = None, **kwargs) -> Generator[Commit]: | ||
""" | ||
|
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 know it's not from this PR, but I prefer common_prefix, prefix has a different meaning