From e3774a8a56df72463a2785158c401ac0a14d1a3d Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Thu, 13 Oct 2022 12:17:31 +0100 Subject: [PATCH] Add ``name`` and ``owner`` parameters to ``ToolShedRepositoryClient.get_repositories()`` xref. https://github.com/galaxyproject/bioblend/issues/462#issuecomment-1277377160 --- CHANGELOG.md | 3 +++ bioblend/_tests/TestToolshed.py | 7 ++++++- bioblend/toolshed/repositories/__init__.py | 18 +++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43dd557b5..bc2ac3a77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ ``WorkflowClient.invoke_workflow()`` method (thanks to [cat-bro](https://github.com/cat-bro)). +* Added ``name`` and ``owner`` parameters to + ``ToolShedRepositoryClient.get_repositories()``. + * Remove unused methods from ``bioblend.config.Config``. If needed, use the methods inherited from `configparser.ConfigParser` instead. diff --git a/bioblend/_tests/TestToolshed.py b/bioblend/_tests/TestToolshed.py index 3fca4c37f..09fe09de9 100644 --- a/bioblend/_tests/TestToolshed.py +++ b/bioblend/_tests/TestToolshed.py @@ -36,13 +36,18 @@ def test_repositories_client(self): assert len(repositories) > 5000 assert repositories[0]["model_class"] == "Repository" + repositories = self.ts.repositories.get_repositories(name="bam_to_sam", owner="devteam") + assert len(repositories) == 1 + bam_to_sam_repo = repositories[0] + assert bam_to_sam_repo["name"] == "bam_to_sam" + assert bam_to_sam_repo["owner"] == "devteam" + # search_repositories samtools_search = self.ts.repositories.search_repositories("samtools", page_size=5) assert int(samtools_search["total_results"]) > 20 assert len(samtools_search["hits"]) == 5 # show_repository - bam_to_sam_repo = [r for r in repositories if r["name"] == "bam_to_sam"][0] show_bam_to_sam_repo = self.ts.repositories.show_repository(bam_to_sam_repo["id"]) assert "SAM" in show_bam_to_sam_repo["long_description"] diff --git a/bioblend/toolshed/repositories/__init__.py b/bioblend/toolshed/repositories/__init__.py index 5944fc983..c3dad6e58 100644 --- a/bioblend/toolshed/repositories/__init__.py +++ b/bioblend/toolshed/repositories/__init__.py @@ -25,9 +25,16 @@ class ToolShedRepositoryClient(Client): def __init__(self, toolshed_instance: "ToolShedInstance") -> None: super().__init__(toolshed_instance) - def get_repositories(self) -> List[Dict[str, Any]]: + def get_repositories(self, name: Optional[str] = None, owner: Optional[str] = None) -> List[Dict[str, Any]]: """ - Get a list of all the repositories in a Galaxy Tool Shed. + Get all repositories in a Galaxy Tool Shed, or select a subset by + specifying optional arguments for filtering (e.g. a repository name). + + :type name: str + :param name: Repository name to filter on. + + :type owner: str + :param owner: Repository owner to filter on. :rtype: list :return: Returns a list of dictionaries containing information about @@ -54,7 +61,12 @@ def get_repositories(self) -> List[Dict[str, Any]]: Changed method name from ``get_tools`` to ``get_repositories`` to better align with the Tool Shed concepts. """ - return self._get() + params = {} + if name: + params["name"] = name + if owner: + params["owner"] = owner + return self._get(params=params) def search_repositories( self,