Skip to content

Commit

Permalink
refact: Move constants to new file and use MRepo
Browse files Browse the repository at this point in the history
Moves constants from component_utils to constants.py
so that ModulesRepo can be used from inside of component_utils,
thereby avoiding a circular import
  • Loading branch information
jvfe committed Dec 16, 2024
1 parent f4cc0fe commit c0a7a00
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
subworkflows_test,
subworkflows_update,
)
from nf_core.components.components_utils import NF_CORE_MODULES_REMOTE
from nf_core.components.constants import NF_CORE_MODULES_REMOTE
from nf_core.pipelines.download import DownloadError
from nf_core.utils import check_if_outdated, nfcore_logo, rich_force_colors, setup_nfcore_dir

Expand Down
21 changes: 7 additions & 14 deletions nf_core/components/components_utils.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import logging
import re
from pathlib import Path
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
from typing import Dict, List, Optional, Tuple, Union

import questionary
import requests
import rich.prompt
import yaml

if TYPE_CHECKING:
from nf_core.modules.modules_repo import ModulesRepo

import nf_core.utils
from nf_core.modules.modules_repo import ModulesRepo

log = logging.getLogger(__name__)

# Constants for the nf-core/modules repo used throughout the module files
NF_CORE_MODULES_NAME = "nf-core"
NF_CORE_MODULES_REMOTE = "https://github.com/nf-core/modules.git"
NF_CORE_MODULES_DEFAULT_BRANCH = "master"


def get_repo_info(directory: Path, use_prompt: Optional[bool] = True) -> Tuple[Path, Optional[str], str]:
"""
Expand Down Expand Up @@ -181,14 +174,14 @@ def get_components_to_install(
for component in components:
if isinstance(component, dict):
component_name = list(component.keys())[0].lower()
git_remote = component[component_name]["git_remote"]
org_path = Path(subworkflow_dir).parent.stem
branch = component[component_name].get("branch")
modules_repo = ModulesRepo(component[component_name]["git_remote"], branch)
current_comp_dict = subworkflows if component_name in subworkflows else modules

component_dict = {
"org_path": org_path,
"git_remote": git_remote,
"branch": component[component_name].get("branch"),
"org_path": modules_repo.repo_path,
"git_remote": modules_repo.remote_url,
"branch": branch,
}

current_comp_dict[component_name].update(component_dict)
Expand Down
4 changes: 4 additions & 0 deletions nf_core/components/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Constants for the nf-core/modules repo used throughout the module files
NF_CORE_MODULES_NAME = "nf-core"
NF_CORE_MODULES_REMOTE = "https://github.com/nf-core/modules.git"
NF_CORE_MODULES_DEFAULT_BRANCH = "master"
2 changes: 1 addition & 1 deletion nf_core/components/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import nf_core.utils
from nf_core.components.components_command import ComponentCommand
from nf_core.components.components_utils import NF_CORE_MODULES_REMOTE
from nf_core.components.constants import NF_CORE_MODULES_REMOTE
from nf_core.modules.modules_json import ModulesJson

log = logging.getLogger(__name__)
Expand Down
7 changes: 2 additions & 5 deletions nf_core/components/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
import nf_core.modules.modules_utils
import nf_core.utils
from nf_core.components.components_command import ComponentCommand
from nf_core.components.components_utils import (
NF_CORE_MODULES_NAME,
get_components_to_install,
prompt_component_version_sha,
)
from nf_core.components.components_utils import get_components_to_install, prompt_component_version_sha
from nf_core.components.constants import NF_CORE_MODULES_NAME
from nf_core.modules.modules_json import ModulesJson
from nf_core.modules.modules_repo import ModulesRepo

Expand Down
3 changes: 2 additions & 1 deletion nf_core/modules/modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from typing_extensions import NotRequired, TypedDict # for py<3.11

import nf_core.utils
from nf_core.components.components_utils import NF_CORE_MODULES_NAME, NF_CORE_MODULES_REMOTE, get_components_to_install
from nf_core.components.components_utils import get_components_to_install
from nf_core.components.constants import NF_CORE_MODULES_NAME, NF_CORE_MODULES_REMOTE
from nf_core.modules.modules_repo import ModulesRepo
from nf_core.pipelines.lint_utils import dump_json_with_prettier

Expand Down
2 changes: 1 addition & 1 deletion nf_core/modules/modules_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import nf_core.modules.modules_json
import nf_core.modules.modules_utils
from nf_core.components.components_utils import NF_CORE_MODULES_NAME, NF_CORE_MODULES_REMOTE
from nf_core.components.constants import NF_CORE_MODULES_NAME, NF_CORE_MODULES_REMOTE
from nf_core.synced_repo import RemoteProgressbar, SyncedRepo
from nf_core.utils import NFCORE_CACHE_DIR, NFCORE_DIR, load_tools_config

Expand Down
2 changes: 1 addition & 1 deletion nf_core/synced_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import git
from git.exc import GitCommandError

from nf_core.components.components_utils import (
from nf_core.components.constants import (
NF_CORE_MODULES_NAME,
NF_CORE_MODULES_REMOTE,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/test_modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil
from pathlib import Path

from nf_core.components.components_utils import (
from nf_core.components.constants import (
NF_CORE_MODULES_DEFAULT_BRANCH,
NF_CORE_MODULES_NAME,
NF_CORE_MODULES_REMOTE,
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import yaml

import nf_core.utils
from nf_core.components.components_utils import NF_CORE_MODULES_NAME, NF_CORE_MODULES_REMOTE
from nf_core.components.constants import NF_CORE_MODULES_NAME, NF_CORE_MODULES_REMOTE
from nf_core.modules.install import ModuleInstall
from nf_core.modules.modules_json import ModulesJson
from nf_core.modules.patch import ModulePatch
Expand Down
2 changes: 1 addition & 1 deletion tests/subworkflows/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import yaml

import nf_core.utils
from nf_core.components.components_utils import NF_CORE_MODULES_NAME, NF_CORE_MODULES_REMOTE
from nf_core.components.constants import NF_CORE_MODULES_NAME, NF_CORE_MODULES_REMOTE
from nf_core.modules.modules_json import ModulesJson
from nf_core.modules.update import ModuleUpdate
from nf_core.subworkflows.install import SubworkflowInstall
Expand Down

0 comments on commit c0a7a00

Please sign in to comment.