Skip to content
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

Add view, keys, limit and offset to get_histories #484

Merged
merged 9 commits into from
Mar 1, 2024
8 changes: 8 additions & 0 deletions bioblend/_tests/TestGalaxyHistories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: check that fields requested are returned
histories_with_keys = self.gi.histories.get_histories(keys=["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
# and get_histories(deleted=True) returns only deleted histories,
Expand Down
42 changes: 42 additions & 0 deletions bioblend/galaxy/histories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
cat-bro marked this conversation as resolved.
Show resolved Hide resolved
view: Optional[Literal["summary", "detailed"]] = None,
keys: Optional[List[str]] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
all: Optional[bool] = False,
cat-bro marked this conversation as resolved.
Show resolved Hide resolved
) -> List[Dict[str, Any]]:
"""
Expand Down Expand Up @@ -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)
Expand All @@ -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,
cat-bro marked this conversation as resolved.
Show resolved Hide resolved
view: Optional[Literal["summary", "detailed"]] = None,
keys: Optional[List[str]] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
all: Optional[bool] = False,
cat-bro marked this conversation as resolved.
Show resolved Hide resolved
) -> List[Dict[str, Any]]:
"""
Expand Down Expand Up @@ -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.

Expand All @@ -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,
Expand Down Expand Up @@ -282,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
Expand All @@ -294,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

Expand All @@ -305,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
Expand Down Expand Up @@ -340,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

Expand All @@ -359,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:
Expand Down
Loading