[SYNPY-1351, SYNPY-1613] Implement 'Wiki2' model into OOP#1206
[SYNPY-1351, SYNPY-1613] Implement 'Wiki2' model into OOP#1206
Conversation
|
@BryanFauble @thomasyu888 I put this draft PR to show tentative interface of the wiki2 service. Protocol, tutorials and test scripts are wip. Feel free to leave comments if you envision it differently. |
|
A tutorial should be created showing how to use the Wiki objects: |
BryanFauble
left a comment
There was a problem hiding this comment.
This is a great start to the changes!
Feel free to reach out to me with questions, and re-request review when you'd like me to take a look at this PR again.
synapseclient/models/wiki.py
Outdated
| @classmethod | ||
| @otel_trace_method( | ||
| method_to_trace_name=lambda self, **kwargs: f"Get_Wiki_History for Owner ID {kwargs['owner_id']}, Wiki ID {kwargs['id']}" | ||
| ) | ||
| async def get_async( | ||
| cls, | ||
| owner_id: str = None, | ||
| id: str = None, | ||
| *, | ||
| offset: int = 0, | ||
| limit: int = 20, | ||
| synapse_client: Optional["Synapse"] = None, | ||
| ) -> List["WikiHistorySnapshot"]: | ||
| """ | ||
| Get the history of a wiki page as a list of WikiHistorySnapshot objects. | ||
|
|
||
| Arguments: | ||
| owner_id: The Synapse ID of the owner entity. | ||
| id: The ID of the wiki page. | ||
| offset: The index of the pagination offset. | ||
| limit: Limits the size of the page returned. | ||
| synapse_client: Optionally provide a Synapse client. | ||
| Returns: | ||
| A list of WikiHistorySnapshot objects for the wiki page. | ||
|
|
||
| Example: Get the history of a wiki page | ||
| history = await WikiHistorySnapshot.get_async(owner_id=project.id, id=wiki_page.id) | ||
| print(f"History: {history}") | ||
| """ | ||
| if not owner_id: | ||
| raise ValueError("Must provide owner_id to get wiki history.") | ||
| if not id: | ||
| raise ValueError("Must provide id to get wiki history.") | ||
| snapshots = [] | ||
| async for item in get_wiki_history( | ||
| owner_id=owner_id, | ||
| wiki_id=id, # use id instead of wiki_id to match other classes | ||
| offset=offset, | ||
| limit=limit, | ||
| synapse_client=synapse_client, | ||
| ): | ||
| snapshots.append(cls().fill_from_dict(item)) | ||
| return snapshots |
There was a problem hiding this comment.
Are there cases where this could return hundreds/thousands of results?
If there is I would consider swapping this to be a generator instead of getting all results.
There was a problem hiding this comment.
It depends on how many versions a wiki page can have. I will tweak it.
synapseclient/models/wiki.py
Outdated
| not attachment.endswith(".gz") | ||
| and not attachment.endswith(".png") | ||
| and not attachment.endswith(".jpg") | ||
| and not attachment.endswith(".jpeg") |
There was a problem hiding this comment.
Is there a list of these somewhere, or is this derived from documentation on the rest-docs? I am curious if there are additional image formats to add here.
There was a problem hiding this comment.
This is a list I found online, and I couldn’t find corresponding documentation in the REST docs. I added because I noticed that images are handled differently from other file types.
tests/integration/synapseclient/models/async/test_wiki_async.py
Outdated
Show resolved
Hide resolved
| assert os.path.exists(downloaded_path) | ||
| assert os.path.basename(downloaded_path) == "preview.txt" | ||
|
|
||
| @pytest.mark.skipif( |
BryanFauble
left a comment
There was a problem hiding this comment.
Thank you for this round. There are a few things to patch up, but this is in a great place
…works/synapsePythonClient into synpy-1351-oop-wiki2 merge upstream changes
BryanFauble
left a comment
There was a problem hiding this comment.
Thanks for your hard work on this. It looks good to me!
…works/synapsePythonClient into synpy-1351-oop-wiki2 merge upstream changes

Problem:
Solution:
Testing:
Integration tests and unit tests are added to both asynchronous and synchronous models.