Skip to content

Commit

Permalink
Add copy_elements parameter to ``HistoryClient.create_dataset_col…
Browse files Browse the repository at this point in the history
…lection()`` and BioBlend.objects ``History.create_dataset_collection()`` methods

Fix tests broken by galaxyproject/galaxy#16717 .
  • Loading branch information
nsoranzo committed Sep 26, 2023
1 parent fe48906 commit c07ed28
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions bioblend/_tests/TestGalaxyDatasetCollections.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_create_list_in_history(self):
dataset_collections.HistoryDatasetElement(name="sample3", id=dataset3_id),
],
),
copy_elements=False,
)
assert collection_response["name"] == "MyDatasetList"
assert collection_response["collection_type"] == "list"
Expand Down Expand Up @@ -70,6 +71,7 @@ def test_create_list_of_paired_datasets_in_history(self):
),
],
),
copy_elements=False,
)
assert collection_response["name"] == "MyListOfPairedDatasets"
assert collection_response["collection_type"] == "list:paired"
Expand Down Expand Up @@ -197,5 +199,6 @@ def _create_pair_in_history(self, history_id: str) -> Dict[str, Any]:
dataset_collections.HistoryDatasetElement(name="reverse", id=dataset2_id),
],
),
copy_elements=False,
)
return collection_response
6 changes: 3 additions & 3 deletions bioblend/_tests/TestGalaxyObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def test_update(self):

def test_create_dataset_collection(self):
self._create_collection_description()
hdca = self.hist.create_dataset_collection(self.collection_description)
hdca = self.hist.create_dataset_collection(self.collection_description, copy_elements=False)
assert isinstance(hdca, wrappers.HistoryDatasetCollectionAssociation)
assert hdca.collection_type == "list"
assert hdca.container is self.hist
Expand All @@ -908,7 +908,7 @@ def test_create_dataset_collection(self):

def test_delete_dataset_collection(self):
self._create_collection_description()
hdca = self.hist.create_dataset_collection(self.collection_description)
hdca = self.hist.create_dataset_collection(self.collection_description, copy_elements=False)
hdca.delete()
assert hdca.deleted

Expand Down Expand Up @@ -1045,7 +1045,7 @@ def test_run_workflow_with_dataset_collection(self):
dataset_collections.HistoryDatasetElement(name="sample2", id=dataset2.id),
],
)
dataset_collection = self.hist.create_dataset_collection(collection_description)
dataset_collection = self.hist.create_dataset_collection(collection_description, copy_elements=False)
assert len(self.hist.content_infos) == 3
input_map = {"0": dataset_collection, "1": dataset1}
inv = self.wf.invoke(input_map, history=self.hist)
Expand Down
10 changes: 9 additions & 1 deletion bioblend/galaxy/histories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,10 @@ def upload_dataset_from_library(self, history_id: str, lib_dataset_id: str) -> D
return self._post(payload, id=history_id, contents=True)

def create_dataset_collection(
self, history_id: str, collection_description: Union["CollectionDescription", Dict[str, Any]]
self,
history_id: str,
collection_description: Union["CollectionDescription", Dict[str, Any]],
copy_elements: bool = True,
) -> Dict[str, Any]:
"""
Create a new dataset collection
Expand All @@ -603,6 +606,10 @@ def create_dataset_collection(
'src': 'hda'}],
'name': 'My collection list'}
:type copy_elements: bool
:param copy_elements: Whether to make a copy of the elements of the
collection being created
:rtype: dict
:return: Information about the new HDCA
"""
Expand All @@ -616,6 +623,7 @@ def create_dataset_collection(
type="dataset_collection",
collection_type=collection_description_dict["collection_type"],
element_identifiers=collection_description_dict["element_identifiers"],
copy_elements=copy_elements,
)
return self._post(payload, id=history_id, contents=True)

Expand Down
12 changes: 10 additions & 2 deletions bioblend/galaxy/objects/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,18 +1475,26 @@ def download(self, jeha_id: str, outf: IO[bytes], chunk_size: int = bioblend.CHU
return self.gi.gi.histories.download_history(self.id, jeha_id, outf, chunk_size=chunk_size)

def create_dataset_collection(
self, collection_description: bioblend.galaxy.dataset_collections.CollectionDescription
self,
collection_description: bioblend.galaxy.dataset_collections.CollectionDescription,
copy_elements: bool = True,
) -> "HistoryDatasetCollectionAssociation":
"""
Create a new dataset collection in the history by providing a collection description.
:type collection_description: bioblend.galaxy.dataset_collections.CollectionDescription
:param collection_description: a description of the dataset collection
:type copy_elements: bool
:param copy_elements: Whether to make a copy of the elements of the
collection being created
:rtype: :class:`~.HistoryDatasetCollectionAssociation`
:return: the new dataset collection
"""
dataset_collection = self.gi.gi.histories.create_dataset_collection(self.id, collection_description)
dataset_collection = self.gi.gi.histories.create_dataset_collection(
self.id, collection_description, copy_elements=copy_elements
)
self.refresh()
return self.get_dataset_collection(dataset_collection["id"])

Expand Down

0 comments on commit c07ed28

Please sign in to comment.