diff --git a/nf_core/modules/modules_utils.py b/nf_core/modules/modules_utils.py index a5af06b996..504cb1095d 100644 --- a/nf_core/modules/modules_utils.py +++ b/nf_core/modules/modules_utils.py @@ -1,7 +1,8 @@ import logging import os -import urllib from pathlib import Path +from typing import List, Optional, Tuple +from urllib.parse import urlparse from ..components.nfcore_component import NFCoreComponent @@ -14,31 +15,29 @@ class ModuleException(Exception): pass -def repo_full_name_from_remote(remote_url): +def repo_full_name_from_remote(remote_url: str) -> str: """ Extracts the path from the remote URL See https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS for the possible URL patterns """ # Check whether we have a https or ssh url if remote_url.startswith("https"): - path = urllib.parse.urlparse(remote_url) - path = path.path + path = urlparse(remote_url).path # Remove the intial '/' path = path[1:] # Remove extension path = os.path.splitext(path)[0] else: # Remove the initial `git@`` - path = remote_url.split("@") - path = path[-1] if len(path) > 1 else path[0] - path = urllib.parse.urlparse(path) - path = path.path + split_path: list = remote_url.split("@") + path = split_path[-1] if len(split_path) > 1 else split_path[0] + path = urlparse(path).path # Remove extension path = os.path.splitext(path)[0] return path -def get_installed_modules(dir, repo_type="modules"): +def get_installed_modules(dir: str, repo_type="modules") -> Tuple[List[str], List[str]]: """ Make a list of all modules installed in this repository @@ -52,9 +51,9 @@ def get_installed_modules(dir, repo_type="modules"): returns (local_modules, nfcore_modules) """ # initialize lists - local_modules = [] - nfcore_modules = [] - local_modules_dir = None + local_modules: List[str] = [] + nfcore_modules: List[str] = [] + local_modules_dir: Optional[str] = None nfcore_modules_dir = os.path.join(dir, "modules", "nf-core") # Get local modules @@ -82,7 +81,9 @@ def get_installed_modules(dir, repo_type="modules"): nfcore_modules.append(m) # Make full (relative) file paths and create NFCoreComponent objects - local_modules = [os.path.join(local_modules_dir, m) for m in local_modules] + if local_modules_dir: + local_modules = [os.path.join(local_modules_dir, m) for m in local_modules] + nfcore_modules = [ NFCoreComponent( m,