Skip to content

Feature/sync async compatible #3

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

Merged
merged 26 commits into from
Mar 4, 2020
Merged

Conversation

vishes-shell
Copy link
Owner

Attempt to combine async and sync interface under the same roof.

on_http_error should work with sync functions that return coroutines and
handle errors when coroutines will be awaited
Also provide async and sync interface to interact with GitlabList
Provide base of gitlab client along with implementations of sync and
async interface
Basic principle is that we won't use constructor to create object,
instead classmethod would be used that return either object or corotine
that returns object
@vishes-shell
Copy link
Owner Author

Edge cases that are require resolve:

path = "%s/all" % self.path
obj = self.gitlab.http_list(path, **kwargs)
return [self._obj_cls(self, item) for item in obj]  # TODO???
obj = self.gitlab.http_list(path, **data)  # TODO: ???
if isinstance(obj, list):
    return [self._obj_cls(self, item) for item in obj]
else:
    return base.RESTObjectList(self, self._obj_cls, obj)
self._check_missing_create_attrs(data)
server_data = self.gitlab.http_post(self.path, post_data=data, **kwargs)
source_issue = ProjectIssue(self._parent.manager, server_data["source_issue"])
target_issue = ProjectIssue(self._parent.manager, server_data["target_issue"])
return source_issue, target_issue  # TODO: ???
id = self.get_id().replace("/", "%2F")
path = "%s/%s/release" % (self.manager.path, id)
data = {"description": description}
if self.release is None:
    try:
        server_data = self.manager.gitlab.http_post(
            path, post_data=data, **kwargs
        )
    except exc.GitlabHttpError as e:
        raise exc.GitlabCreateError(e.response_code, e.error_message)
else:
    try:
        server_data = self.manager.gitlab.http_put(
            path, post_data=data, **kwargs
        )
    except exc.GitlabHttpError as e:
        raise exc.GitlabUpdateError(e.response_code, e.error_message)
self.release = server_data  # TODO: ???
path = "%s/%s/closes_issues" % (self.manager.path, self.get_id())
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
manager = ProjectIssueManager(self.manager.gitlab, parent=self.manager._parent)
return RESTObjectList(manager, ProjectIssue, data_list)  # TODO: ???
if filepath is None and filedata is None:
    raise GitlabUploadError("No file contents or path specified")

if filedata is not None and filepath is not None:
    raise GitlabUploadError("File contents and file path specified")

if filepath is not None:
    with open(filepath, "rb") as f:
        filedata = f.read()

url = "/projects/%(id)s/uploads" % {"id": self.id}
file_info = {"file": (filename, filedata)}
data = self.manager.gitlab.http_post(url, files=file_info)

return {
    "alt": data["alt"],
    "url": data["url"],
    "markdown": data["markdown"],
}  # TODO: ???

Those are have some sort of post-process logic. We need to deal with it in most gentle way.

Implement decorator that deals with possible awaitable object and run
function that is passed as callback and return awaitable or data
Decorate all edge cases with postprocessing in v4 objects with
awaitable_postprocess
Since _update_attrs is some sort of postprocess then we decorated it so
Hence changed interface we now can explicitly user self._update_attrs
but be sure that we return it, since it's awaitable
@vishes-shell vishes-shell marked this pull request as ready for review March 4, 2020 10:17
@vishes-shell vishes-shell merged commit d8f3dec into master Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant