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

Feature/python typing/list.py #2214

Merged
merged 15 commits into from
Oct 18, 2023
16 changes: 9 additions & 7 deletions nf_core/components/list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
from typing import Dict, List, Optional, Tuple, Union

import rich

Expand All @@ -11,11 +12,11 @@


class ComponentList(ComponentCommand):
def __init__(self, component_type, pipeline_dir, remote=True, remote_url=None, branch=None, no_pull=False):
def __init__(self, component_type, pipeline_dir, remote=True, remote_url=None, branch=None, no_pull=False) -> None:
NovakApis marked this conversation as resolved.
Show resolved Hide resolved
super().__init__(component_type, pipeline_dir, remote_url, branch, no_pull)
self.remote = remote

def list_components(self, keywords=None, print_json=False):
def list_components(self, keywords: Optional[List[str]] = None, print_json=False) -> rich.table.Table:
keywords = keywords or []
"""
Get available modules/subworkflows names from GitHub tree for repo
Expand All @@ -25,11 +26,11 @@ def list_components(self, keywords=None, print_json=False):
# self.check_component_structure(self.component_type)

# Initialise rich table
table = rich.table.Table()
table: rich.table.Table = rich.table.Table()
table.add_column(f"{self.component_type[:-1].capitalize()} Name")
components = []
components: List[str] = []

def pattern_msg(keywords):
def pattern_msg(keywords: List[str]):
if len(keywords) == 0:
return ""
if len(keywords) == 1:
Expand Down Expand Up @@ -78,11 +79,11 @@ def pattern_msg(keywords):
return ""

# Verify that 'modules.json' is consistent with the installed modules
modules_json = ModulesJson(self.dir)
modules_json: ModulesJson = ModulesJson(self.dir)
modules_json.check_up_to_date()

# Filter by keywords
repos_with_comps = {
repos_with_comps: Dict[str, List[Tuple[str, str]]] = {
repo_url: [comp for comp in components if all(k in comp[1] for k in keywords)]
for repo_url, components in modules_json.get_all_components(self.component_type).items()
}
Expand All @@ -101,6 +102,7 @@ def pattern_msg(keywords):
modules_json = modules_json.modules_json

for repo_url, component_with_dir in sorted(repos_with_comps.items()):
repo_entry: Dict[str, Dict[str, Dict[str, Dict[str, Union[str, List[str]]]]]]
repo_entry = modules_json["repos"].get(repo_url, {})
for install_dir, component in sorted(component_with_dir):
repo_modules = repo_entry.get(self.component_type)
Expand Down