From c07ed28d7dad7e195cf009aa5d4a6b39b4e8fd47 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Tue, 26 Sep 2023 19:22:42 +0100 Subject: [PATCH] Add ``copy_elements`` parameter to ``HistoryClient.create_dataset_collection()`` and BioBlend.objects ``History.create_dataset_collection()`` methods Fix tests broken by https://github.com/galaxyproject/galaxy/pull/16717 . --- bioblend/_tests/TestGalaxyDatasetCollections.py | 3 +++ bioblend/_tests/TestGalaxyObjects.py | 6 +++--- bioblend/galaxy/histories/__init__.py | 10 +++++++++- bioblend/galaxy/objects/wrappers.py | 12 ++++++++++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/bioblend/_tests/TestGalaxyDatasetCollections.py b/bioblend/_tests/TestGalaxyDatasetCollections.py index e30f3aeb2..05a3435ef 100644 --- a/bioblend/_tests/TestGalaxyDatasetCollections.py +++ b/bioblend/_tests/TestGalaxyDatasetCollections.py @@ -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" @@ -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" @@ -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 diff --git a/bioblend/_tests/TestGalaxyObjects.py b/bioblend/_tests/TestGalaxyObjects.py index 3610c2617..5335ce0e9 100644 --- a/bioblend/_tests/TestGalaxyObjects.py +++ b/bioblend/_tests/TestGalaxyObjects.py @@ -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 @@ -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 @@ -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) diff --git a/bioblend/galaxy/histories/__init__.py b/bioblend/galaxy/histories/__init__.py index c53f22ff9..403d10d92 100644 --- a/bioblend/galaxy/histories/__init__.py +++ b/bioblend/galaxy/histories/__init__.py @@ -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 @@ -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 """ @@ -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) diff --git a/bioblend/galaxy/objects/wrappers.py b/bioblend/galaxy/objects/wrappers.py index 51e5c1f58..b747149ed 100644 --- a/bioblend/galaxy/objects/wrappers.py +++ b/bioblend/galaxy/objects/wrappers.py @@ -1475,7 +1475,9 @@ 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. @@ -1483,10 +1485,16 @@ def create_dataset_collection( :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"])