-
Notifications
You must be signed in to change notification settings - Fork 74
[SYNPY-1802] Add DownloadList functions #1347
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
Changes from 11 commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
a07b2ee
add OOP DownloadList class
andrewelamb 5b52a89
update docs and docstring examples
andrewelamb 2baab73
add module-scoped syn class
andrewelamb 2e13576
add comment
andrewelamb fafb10c
various fixes claude found
andrewelamb 27c1307
import methods so they cna be used without the class
andrewelamb 03f64e9
replaced Typing.List with list
andrewelamb 17ee9bf
DownLoadListItem.version_number is now optional
andrewelamb a4f600a
allow DownloadListItem.version number to be null
andrewelamb fed3d6f
removed module level synapse fixture
andrewelamb d5371b3
added back module level syn object
andrewelamb af26caf
Merge branch 'develop' into SYNPY-1802
andrewelamb dced8c7
fix tests were mocking leaked to other tests, and update claude.md file
andrewelamb 4ed83b1
remove uneeded import
andrewelamb 8dafe64
changed link format
andrewelamb f243490
funtion now raises an error when mumberOfFilesAdded is nto returned
andrewelamb 5f8a0e1
added link to API doc
andrewelamb ebb6044
updated docstring
andrewelamb 3d43bc3
now using CsvTableDescriptor class
andrewelamb 868edba
changed link format
andrewelamb 90d100f
add exception and warning
andrewelamb 7d9ea03
added link to API docs
andrewelamb c76e749
PR suggestions
andrewelamb 04badb6
updated docstrings
andrewelamb 167d8f9
remove warning test
andrewelamb 278af37
fix imports
andrewelamb a2354cc
fix docstring
andrewelamb b5a3d07
Merge branch 'develop' into SYNPY-1802
andrewelamb 0052482
redo docs
andrewelamb 0219c58
undo review date change
andrewelamb 7c8e680
uncommit a dir that wasnt supposed to be
andrewelamb 5028295
fix style issues
andrewelamb 85412d6
combined all static methods as functions into one section
andrewelamb 094b8af
added destination parameter
andrewelamb 1ee92b6
created new api service fucntion for download of manifest
andrewelamb 43a3a21
fix stale docstring
andrewelamb 6313ea6
fix unit test error type
andrewelamb da715af
revert claude date
andrewelamb 80cbe11
removed unit tests
andrewelamb f1b322e
added integration tests
andrewelamb 6cbca41
added to docstring
andrewelamb cbcad15
cleaed up and renamed download_row func
andrewelamb 3a30b22
made consistent use of methods
andrewelamb 7b9ed4b
made max_concurrant more consistent
andrewelamb e80aab2
added tests
andrewelamb 3b73e72
remove uneeded parens
andrewelamb b2d5d3d
did some clean up
andrewelamb 7e36cb8
added helper function
andrewelamb a74be07
redid simpler unit tests
andrewelamb 4a55581
refactored tests
andrewelamb 53edf77
added integration test
andrewelamb db854eb
expanded test
andrewelamb ef60977
clarified how versions work in docstrings
andrewelamb b1ac8d1
light refactoring
andrewelamb 861e6ab
add fix for test failing on Mac OS
andrewelamb 8b04266
Merge branch 'develop' into SYNPY-1802
andrewelamb 5c87093
Merge branch 'develop' into SYNPY-1802
andrewelamb 33415e0
fixed tests to work in parallel
andrewelamb 3568ee8
linglings suggestions
andrewelamb 9231112
linglings suggestions
andrewelamb 5d93c23
ran black
andrewelamb a0d5c70
changed class to operations functions
andrewelamb c9aaf13
changed class to operations functions
andrewelamb ed4208e
Merge branch 'develop' into SYNPY-1802
andrewelamb 886e484
added ability to delete null verison files if downloaded
andrewelamb 6197f55
added ability to delete null verison files if downloaded
andrewelamb 16c1a66
linglings suggestions
andrewelamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| [](){ #download-list-reference } | ||
| # Download List | ||
|
|
||
| The Synapse Download List (cart) lets you queue files for bulk download via the Synapse | ||
| web UI or API. Files are downloaded individually rather than packaged into a zip because | ||
| download lists can exceed 100 GB. Successfully downloaded files are removed from the cart | ||
| automatically, so interrupted runs are safely resumable. | ||
|
|
||
| ## Example | ||
|
|
||
| ```python | ||
| from synapseclient import Synapse | ||
| from synapseclient.models import DownloadList | ||
|
|
||
| syn = Synapse() | ||
| syn.login() | ||
|
|
||
| # Download all files in the cart to a local directory | ||
| manifest_path = DownloadList().download_files(download_location="./downloads") | ||
| ``` | ||
|
|
||
| ## API Reference | ||
|
|
||
| ::: synapseclient.models.DownloadList | ||
| options: | ||
| inherited_members: true | ||
| members: | ||
| - download_files | ||
| - get_manifest | ||
| - add_files | ||
| - remove_files | ||
| - clear | ||
|
|
||
| --- | ||
|
|
||
| [](){ #download-list-item-reference } | ||
| ## DownloadListItem | ||
|
|
||
| Identifies a specific file version in the download list. Used as input to | ||
| `add_files` and `remove_files`. | ||
|
|
||
| ::: synapseclient.models.DownloadListItem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """This module is responsible for exposing the services defined at: | ||
| <https://rest-docs.synapse.org/rest/#org.sagebionetworks.repo.web.controller.DownloadListController> | ||
| """ | ||
|
|
||
| import json | ||
| from typing import TYPE_CHECKING, Optional | ||
|
|
||
| if TYPE_CHECKING: | ||
| from synapseclient import Synapse | ||
| from synapseclient.models.download_list import DownloadListItem | ||
|
|
||
|
|
||
| async def clear_download_list_async( | ||
| *, | ||
| synapse_client: Optional["Synapse"] = None, | ||
| ) -> None: | ||
| """Clear all files from the user's Synapse download list. | ||
|
|
||
| [Endpoint](https://rest-docs.synapse.org/rest/DELETE/download/list.html) | ||
|
|
||
| Arguments: | ||
| synapse_client: If not passed in and caching was not disabled by | ||
| `Synapse.allow_client_caching(False)` this will use the last created | ||
| instance from the Synapse class constructor. | ||
| """ | ||
| from synapseclient import Synapse | ||
|
|
||
| client = Synapse.get_client(synapse_client=synapse_client) | ||
| await client.rest_delete_async("/download/list") | ||
|
|
||
|
|
||
| async def add_to_download_list_async( | ||
| files: list["DownloadListItem"], | ||
| *, | ||
| synapse_client: Optional["Synapse"] = None, | ||
| ) -> int: | ||
| """Add a batch of specific file versions to the user's Synapse download list. | ||
|
|
||
| [Endpoint](https://rest-docs.synapse.org/rest/POST/download/list/add.html) | ||
|
|
||
| Arguments: | ||
| files: List of DownloadListItem objects identifying the file versions to add. | ||
| synapse_client: If not passed in and caching was not disabled by | ||
| `Synapse.allow_client_caching(False)` this will use the last created | ||
| instance from the Synapse class constructor. | ||
|
|
||
| Returns: | ||
| The number of files added to the download list. | ||
| """ | ||
| from synapseclient import Synapse | ||
|
|
||
| client = Synapse.get_client(synapse_client=synapse_client) | ||
| batch = [ | ||
| {"fileEntityId": item.file_entity_id, "versionNumber": item.version_number} | ||
| for item in files | ||
| ] | ||
| request_body = {"batchToAdd": batch} | ||
| result = await client.rest_post_async( | ||
| "/download/list/add", body=json.dumps(request_body) | ||
| ) | ||
| return result.get("numberOfFilesAdded", 0) | ||
|
andrewelamb marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| async def remove_from_download_list_async( | ||
| files: list["DownloadListItem"], | ||
| *, | ||
| synapse_client: Optional["Synapse"] = None, | ||
| ) -> int: | ||
| """Remove a batch of specific file versions from the user's Synapse download list. | ||
|
|
||
| [Endpoint](https://rest-docs.synapse.org/rest/POST/download/list/remove.html) | ||
|
|
||
| Arguments: | ||
| files: List of DownloadListItem objects identifying the file versions to remove. | ||
| synapse_client: If not passed in and caching was not disabled by | ||
| `Synapse.allow_client_caching(False)` this will use the last created | ||
| instance from the Synapse class constructor. | ||
|
|
||
| Returns: | ||
| The number of files removed from the download list. | ||
| """ | ||
| from synapseclient import Synapse | ||
|
|
||
| client = Synapse.get_client(synapse_client=synapse_client) | ||
| batch = [ | ||
| {"fileEntityId": item.file_entity_id, "versionNumber": item.version_number} | ||
| for item in files | ||
| ] | ||
| request_body = {"batchToRemove": batch} | ||
| result = await client.rest_post_async( | ||
| "/download/list/remove", body=json.dumps(request_body) | ||
| ) | ||
| return result.get("numberOfFilesRemoved", 0) | ||
|
andrewelamb marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.