From 4150d796a73957364952af7685167bdd5f61ebce Mon Sep 17 00:00:00 2001 From: cat-bro Date: Thu, 29 Feb 2024 16:36:59 +1100 Subject: [PATCH 1/9] Add view, keys, limit and offset to get_histories --- bioblend/_tests/TestGalaxyHistories.py | 8 ++++++ bioblend/galaxy/histories/__init__.py | 34 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/bioblend/_tests/TestGalaxyHistories.py b/bioblend/_tests/TestGalaxyHistories.py index 6dff33588..556e98799 100644 --- a/bioblend/_tests/TestGalaxyHistories.py +++ b/bioblend/_tests/TestGalaxyHistories.py @@ -85,6 +85,14 @@ def test_get_histories(self): ) assert len(old_histories) == 0 + # Test detailed view: check for presence of "size" field + histories_detailed = self.gi.histories.get_histories(view="detailed") + assert "size" in histories_detailed[0] + + # Test keys + histories_with_keys = self.gi.histories.get_histories(keys=["id", "user_id", "size"]) + assert set([key for key in histories_with_keys[0]]) == set(["id", "user_id", "size"]) + # TODO: check whether deleted history is returned correctly # At the moment, get_histories() returns only not-deleted histories # and get_histories(deleted=True) returns only deleted histories, diff --git a/bioblend/galaxy/histories/__init__.py b/bioblend/galaxy/histories/__init__.py index 4fac2b195..52a5b76d4 100644 --- a/bioblend/galaxy/histories/__init__.py +++ b/bioblend/galaxy/histories/__init__.py @@ -93,6 +93,10 @@ def _get_histories( create_time_max: Optional[str] = None, update_time_min: Optional[str] = None, update_time_max: Optional[str] = None, + view: Optional[str] = "summary", + keys: Optional[List[str]] = None, + limit: Optional[int] = None, + offset: Optional[int] = None, all: Optional[bool] = False, ) -> List[Dict[str, Any]]: """ @@ -124,6 +128,14 @@ def _get_histories( params.setdefault("qv", []).append(update_time_max) if all: params["all"] = True + if view: + params["view"] = view + if keys: + params["keys"] = ",".join(keys) + if limit: + params["limit"] = limit + if offset: + params["offset"] = offset url = "/".join((self._make_url(), "published")) if get_all_published else None histories = self._get(url=url, params=params) @@ -143,6 +155,10 @@ def get_histories( create_time_max: Optional[str] = None, update_time_min: Optional[str] = None, update_time_max: Optional[str] = None, + view: Optional[str] = 'summary', + keys: Optional[List[str]] = None, + limit: Optional[int] = None, + offset: Optional[int] = None, all: Optional[bool] = False, ) -> List[Dict[str, Any]]: """ @@ -187,6 +203,20 @@ def get_histories( parameter works only on Galaxy 20.01 or later and can be specified only if the user is a Galaxy admin. + :type view: str + :param view: Options are 'summary' or 'detailed'. This defaults to 'summary'. + Setting view to 'detailed' results in a larger number of fields returned. + + :type keys: List[str] + :param keys: List of fields to return + + :type limit: int + :param limit: How many items to return (upper bound). + + :type offset: int + :param offset: skip the first ( offset - 1 ) items and begin returning + at the Nth item. + :rtype: list :return: List of history dicts. @@ -205,6 +235,10 @@ def get_histories( get_all_published=False, slug=slug, all=all, + view=view, + keys=keys, + limit=limit, + offset=offset, create_time_min=create_time_min, create_time_max=create_time_max, update_time_min=update_time_min, From abf8f19305fe3de7bcfad74b43bf02224ac7c668 Mon Sep 17 00:00:00 2001 From: cat-bro Date: Thu, 29 Feb 2024 18:14:34 +1100 Subject: [PATCH 2/9] Also add keys to show_history --- bioblend/galaxy/histories/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bioblend/galaxy/histories/__init__.py b/bioblend/galaxy/histories/__init__.py index 52a5b76d4..f7799eaa9 100644 --- a/bioblend/galaxy/histories/__init__.py +++ b/bioblend/galaxy/histories/__init__.py @@ -93,7 +93,7 @@ def _get_histories( create_time_max: Optional[str] = None, update_time_min: Optional[str] = None, update_time_max: Optional[str] = None, - view: Optional[str] = "summary", + view: Optional[str] = None, keys: Optional[List[str]] = None, limit: Optional[int] = None, offset: Optional[int] = None, @@ -155,7 +155,7 @@ def get_histories( create_time_max: Optional[str] = None, update_time_min: Optional[str] = None, update_time_max: Optional[str] = None, - view: Optional[str] = 'summary', + view: Optional[str] = None, keys: Optional[List[str]] = None, limit: Optional[int] = None, offset: Optional[int] = None, @@ -205,7 +205,7 @@ def get_histories( :type view: str :param view: Options are 'summary' or 'detailed'. This defaults to 'summary'. - Setting view to 'detailed' results in a larger number of fields returned. + Setting view to 'detailed' results in a larger number of fields returned. :type keys: List[str] :param keys: List of fields to return @@ -316,6 +316,7 @@ def show_history( visible: Optional[bool] = None, details: Optional[str] = None, types: Optional[List[str]] = None, + keys: Optional[List[str]] = None, ) -> List[Dict[str, Any]]: ... # Fallback in case the caller provides a regular bool as contents @@ -328,6 +329,7 @@ def show_history( visible: Optional[bool] = None, details: Optional[str] = None, types: Optional[List[str]] = None, + keys: Optional[List[str]] = None, ) -> Union[Dict[str, Any], List[Dict[str, Any]]]: pass @@ -339,6 +341,7 @@ def show_history( visible: Optional[bool] = None, details: Optional[str] = None, types: Optional[List[str]] = None, + keys: Optional[List[str]] = None, ) -> Union[Dict[str, Any], List[Dict[str, Any]]]: """ Get details of a given history. By default, just get the history meta @@ -374,6 +377,9 @@ def show_history( ``['dataset_collection']``, return only dataset collections. If not set, no filtering is applied. + :type keys: List[str] + :param keys: List of fields to return + :rtype: dict or list of dicts :return: details of the given history or list of dataset info @@ -393,6 +399,8 @@ def show_history( params["visible"] = visible if types is not None: params["types"] = types + if keys: + params["keys"] = ",".join(keys) return self._get(id=history_id, contents=contents, params=params) def delete_dataset(self, history_id: str, dataset_id: str, purge: bool = False) -> None: From b493cf5e3e7ef155b88053b8b1133847d32ff5cb Mon Sep 17 00:00:00 2001 From: cat-bro Date: Thu, 29 Feb 2024 23:40:29 +1100 Subject: [PATCH 3/9] try to fix get_histories keys test --- bioblend/_tests/TestGalaxyHistories.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bioblend/_tests/TestGalaxyHistories.py b/bioblend/_tests/TestGalaxyHistories.py index 556e98799..a088916fb 100644 --- a/bioblend/_tests/TestGalaxyHistories.py +++ b/bioblend/_tests/TestGalaxyHistories.py @@ -89,9 +89,9 @@ def test_get_histories(self): histories_detailed = self.gi.histories.get_histories(view="detailed") assert "size" in histories_detailed[0] - # Test keys + # Test keys: check that fields requested are returned histories_with_keys = self.gi.histories.get_histories(keys=["id", "user_id", "size"]) - assert set([key for key in histories_with_keys[0]]) == set(["id", "user_id", "size"]) + assert {key for key in histories_with_keys[0]} >= {"id", "user_id", "size"} # TODO: check whether deleted history is returned correctly # At the moment, get_histories() returns only not-deleted histories From c47a37ae5602d9f79e5bfd4c2ce9cc7661b68023 Mon Sep 17 00:00:00 2001 From: cat-bro Date: Fri, 1 Mar 2024 08:06:59 +1100 Subject: [PATCH 4/9] Update bioblend/galaxy/histories/__init__.py Co-authored-by: Nicola Soranzo --- bioblend/galaxy/histories/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bioblend/galaxy/histories/__init__.py b/bioblend/galaxy/histories/__init__.py index f7799eaa9..e3daf8677 100644 --- a/bioblend/galaxy/histories/__init__.py +++ b/bioblend/galaxy/histories/__init__.py @@ -93,7 +93,7 @@ def _get_histories( create_time_max: Optional[str] = None, update_time_min: Optional[str] = None, update_time_max: Optional[str] = None, - view: Optional[str] = None, + view: Optional[Literal["summary", "detailed"]] = None, keys: Optional[List[str]] = None, limit: Optional[int] = None, offset: Optional[int] = None, From ccd41352b98e4fabefcde5f7b8488910d703a6b1 Mon Sep 17 00:00:00 2001 From: cat-bro Date: Fri, 1 Mar 2024 08:07:08 +1100 Subject: [PATCH 5/9] Update bioblend/galaxy/histories/__init__.py Co-authored-by: Nicola Soranzo --- bioblend/galaxy/histories/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bioblend/galaxy/histories/__init__.py b/bioblend/galaxy/histories/__init__.py index e3daf8677..e43080c84 100644 --- a/bioblend/galaxy/histories/__init__.py +++ b/bioblend/galaxy/histories/__init__.py @@ -155,7 +155,7 @@ def get_histories( create_time_max: Optional[str] = None, update_time_min: Optional[str] = None, update_time_max: Optional[str] = None, - view: Optional[str] = None, + view: Optional[Literal["summary", "detailed"]] = None, keys: Optional[List[str]] = None, limit: Optional[int] = None, offset: Optional[int] = None, From 2bb96fdfec5e7ac9fac150bd93195a4c795476ce Mon Sep 17 00:00:00 2001 From: cat-bro Date: Fri, 1 Mar 2024 10:55:12 +1100 Subject: [PATCH 6/9] Update bioblend/galaxy/histories/__init__.py Co-authored-by: Nicola Soranzo --- bioblend/galaxy/histories/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bioblend/galaxy/histories/__init__.py b/bioblend/galaxy/histories/__init__.py index e43080c84..750ed7c03 100644 --- a/bioblend/galaxy/histories/__init__.py +++ b/bioblend/galaxy/histories/__init__.py @@ -155,6 +155,7 @@ def get_histories( create_time_max: Optional[str] = None, update_time_min: Optional[str] = None, update_time_max: Optional[str] = None, + all: Optional[bool] = False, view: Optional[Literal["summary", "detailed"]] = None, keys: Optional[List[str]] = None, limit: Optional[int] = None, From 26981f1d5ad570f9d29644f7b10ca3b691593751 Mon Sep 17 00:00:00 2001 From: cat-bro Date: Fri, 1 Mar 2024 10:55:18 +1100 Subject: [PATCH 7/9] Update bioblend/galaxy/histories/__init__.py Co-authored-by: Nicola Soranzo --- bioblend/galaxy/histories/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bioblend/galaxy/histories/__init__.py b/bioblend/galaxy/histories/__init__.py index 750ed7c03..64e9d6ac4 100644 --- a/bioblend/galaxy/histories/__init__.py +++ b/bioblend/galaxy/histories/__init__.py @@ -160,7 +160,6 @@ def get_histories( keys: Optional[List[str]] = None, limit: Optional[int] = None, offset: Optional[int] = None, - all: Optional[bool] = False, ) -> List[Dict[str, Any]]: """ Get all histories, or select a subset by specifying optional arguments From 9450cc972731883baf8772b43946c49804a46ec6 Mon Sep 17 00:00:00 2001 From: cat-bro Date: Fri, 1 Mar 2024 10:55:25 +1100 Subject: [PATCH 8/9] Update bioblend/galaxy/histories/__init__.py Co-authored-by: Nicola Soranzo --- bioblend/galaxy/histories/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bioblend/galaxy/histories/__init__.py b/bioblend/galaxy/histories/__init__.py index 64e9d6ac4..df06f0a28 100644 --- a/bioblend/galaxy/histories/__init__.py +++ b/bioblend/galaxy/histories/__init__.py @@ -97,7 +97,6 @@ def _get_histories( keys: Optional[List[str]] = None, limit: Optional[int] = None, offset: Optional[int] = None, - all: Optional[bool] = False, ) -> List[Dict[str, Any]]: """ Hidden method to be used by both get_histories() and get_published_histories() From 8dd8893ed95e8c3eba998d98e66c9fac76f2cf9d Mon Sep 17 00:00:00 2001 From: cat-bro Date: Fri, 1 Mar 2024 10:55:45 +1100 Subject: [PATCH 9/9] Update bioblend/galaxy/histories/__init__.py Co-authored-by: Nicola Soranzo --- bioblend/galaxy/histories/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bioblend/galaxy/histories/__init__.py b/bioblend/galaxy/histories/__init__.py index df06f0a28..bcad72e74 100644 --- a/bioblend/galaxy/histories/__init__.py +++ b/bioblend/galaxy/histories/__init__.py @@ -93,6 +93,7 @@ def _get_histories( create_time_max: Optional[str] = None, update_time_min: Optional[str] = None, update_time_max: Optional[str] = None, + all: Optional[bool] = False, view: Optional[Literal["summary", "detailed"]] = None, keys: Optional[List[str]] = None, limit: Optional[int] = None,