Skip to content

Commit

Permalink
Merge pull request #2218 from NovakApis/feature/python-typing/modules…
Browse files Browse the repository at this point in the history
…_utils.py

python-typing/modules_utils.py
  • Loading branch information
kedhammar authored Oct 18, 2023
2 parents 3f3486b + b824076 commit 3fddb70
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions nf_core/modules/modules_utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3fddb70

Please sign in to comment.