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

Substitute ModulesCommand and SubworkflowsCommand by ComponentsCommand #2000

Merged
merged 14 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions nf_core/components/components_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,22 @@ def load_lint_config(self):
except FileNotFoundError:
log.debug(f"No lint config file found: {config_fn}")

def check_component_structure(self, component_name):
def check_modules_structure(self):
awgymer marked this conversation as resolved.
Show resolved Hide resolved
mirpedrol marked this conversation as resolved.
Show resolved Hide resolved
"""
Check that the structure of the modules/subworkflow directory in a pipeline is the correct one:
modules/nf-core/TOOL/SUBTOOL | subworkflows/nf-core/SUBWORKFLOW
Check that the structure of the modules directory in a pipeline is the correct one:
modules/nf-core/TOOL/SUBTOOL

Prior to nf-core/tools release 2.6 the directory structure had an additional level of nesting:
modules/nf-core/modules/TOOL/SUBTOOL
"""
if self.repo_type == "pipeline":
wrong_location_modules = []
for directory, _, files in os.walk(Path(self.dir, component_name)):
for directory, _, files in os.walk(Path(self.dir, "modules")):
if "main.nf" in files:
module_path = Path(directory).relative_to(Path(self.dir, component_name))
module_path = Path(directory).relative_to(Path(self.dir, "modules"))
parts = module_path.parts
# Check that there are modules installed directly under the 'modules' directory
if parts[1] == component_name:
if parts[1] == "modules":
wrong_location_modules.append(module_path)
# If there are modules installed in the wrong location
if len(wrong_location_modules) > 0:
Expand All @@ -185,12 +185,43 @@ def check_component_structure(self, component_name):
)
# Move wrong modules to the right directory
for module in wrong_location_modules:
modules_dir = Path(component_name).resolve()
modules_dir = Path("modules").resolve()
correct_dir = Path(modules_dir, self.modules_repo.repo_path, Path(*module.parts[2:]))
wrong_dir = Path(modules_dir, module)
shutil.move(wrong_dir, correct_dir)
log.info(f"Moved {wrong_dir} to {correct_dir}.")
shutil.rmtree(Path(self.dir, component_name, self.modules_repo.repo_path, component_name))
shutil.rmtree(Path(self.dir, "modules", self.modules_repo.repo_path, "modules"))
# Regenerate modules.json file
modules_json = ModulesJson(self.dir)
modules_json.check_up_to_date()

def check_patch_paths(self, patch_path, module_name):
awgymer marked this conversation as resolved.
Show resolved Hide resolved
"""
Check that paths in patch files are updated to the new modules path
"""
if patch_path.exists():
log.info(f"Modules {module_name} contains a patch file.")
rewrite = False
with open(patch_path, "r") as fh:
lines = fh.readlines()
for index, line in enumerate(lines):
# Check if there are old paths in the patch file and replace
if f"modules/{self.modules_repo.repo_path}/modules/{module_name}/" in line:
rewrite = True
lines[index] = line.replace(
f"modules/{self.modules_repo.repo_path}/modules/{module_name}/",
f"modules/{self.modules_repo.repo_path}/{module_name}/",
)
if rewrite:
log.info(f"Updating paths in {patch_path}")
with open(patch_path, "w") as fh:
for line in lines:
fh.write(line)
# Update path in modules.json if the file is in the correct format
modules_json = ModulesJson(self.dir)
modules_json.load()
if modules_json.has_git_url_and_modules():
modules_json.modules_json["repos"][self.modules_repo.remote_url]["modules"][
self.modules_repo.repo_path
][module_name]["patch"] = str(patch_path.relative_to(Path(self.dir).resolve()))
modules_json.dump()
5 changes: 4 additions & 1 deletion nf_core/components/components_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from nf_core.components.components_command import ComponentCommand
mirpedrol marked this conversation as resolved.
Show resolved Hide resolved


class ComponentsTest(ComponentCommand):
"""
Class to run module pytests.
Expand Down Expand Up @@ -38,7 +41,7 @@ def __init__(
self.no_prompts = no_prompts
self.pytest_args = pytest_args

super().__init__(".", remote_url, branch, no_pull)
super().__init__("component_type", ".", remote_url, branch, no_pull)
mirpedrol marked this conversation as resolved.
Show resolved Hide resolved

def run(self):
"""Run test steps"""
Expand Down
2 changes: 0 additions & 2 deletions nf_core/components/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import nf_core.modules.modules_utils
from nf_core.components.components_command import ComponentCommand
from nf_core.modules.modules_json import ModulesJson

# from .modules_command import ModulesRepo
from nf_core.modules.modules_repo import ModulesRepo

log = logging.getLogger(__name__)
Expand Down
7 changes: 3 additions & 4 deletions nf_core/modules/bump_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@

import nf_core.modules.modules_utils
import nf_core.utils
from nf_core.components.components_command import ComponentCommand
from nf_core.utils import plural_s as _s
from nf_core.utils import rich_force_colors

from .modules_command import ModuleCommand

log = logging.getLogger(__name__)


class ModuleVersionBumper(ModuleCommand):
class ModuleVersionBumper(ComponentCommand):
def __init__(self, pipeline_dir, remote_url=None, branch=None, no_pull=False):
super().__init__(pipeline_dir, remote_url, branch, no_pull)
super().__init__("modules", pipeline_dir, remote_url, branch, no_pull)

self.up_to_date = None
self.updated = None
Expand Down
9 changes: 4 additions & 5 deletions nf_core/modules/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
import nf_core.components.components_create
import nf_core.modules.modules_utils
import nf_core.utils

from .modules_command import ModuleCommand
from nf_core.components.components_command import ComponentCommand

log = logging.getLogger(__name__)


class ModuleCreate(ModuleCommand):
class ModuleCreate(ComponentCommand):
def __init__(
self,
directory=".",
Expand All @@ -36,7 +35,7 @@ def __init__(
conda_version=None,
repo_type=None,
):
super().__init__(directory)
super().__init__("modules", directory)
self.directory = directory
self.tool = tool
self.author = author
Expand Down Expand Up @@ -157,7 +156,7 @@ def create(self):
pytest_modules_yml = dict(sorted(pytest_modules_yml.items()))
with open(os.path.join(self.directory, "tests", "config", "pytest_modules.yml"), "w") as fh:
yaml.dump(pytest_modules_yml, fh, sort_keys=True, Dumper=nf_core.utils.custom_yaml_dumper())
except FileNotFoundError as e:
except FileNotFoundError:
raise UserWarning("Could not open 'tests/config/pytest_modules.yml' file!")

new_files = list(self.file_paths.values())
Expand Down
7 changes: 3 additions & 4 deletions nf_core/modules/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
from rich.text import Text

import nf_core.utils
from nf_core.components.components_command import ComponentCommand
from nf_core.modules.modules_json import ModulesJson

from .modules_command import ModuleCommand
from .modules_repo import NF_CORE_MODULES_REMOTE
from .modules_utils import get_repo_type

log = logging.getLogger(__name__)


class ModuleInfo(ModuleCommand):
class ModuleInfo(ComponentCommand):
"""
Class to print information of a module.

Expand Down Expand Up @@ -56,7 +56,7 @@ class ModuleInfo(ModuleCommand):
"""

def __init__(self, pipeline_dir, tool, remote_url, branch, no_pull):
super().__init__(pipeline_dir, remote_url, branch, no_pull)
super().__init__("modules", pipeline_dir, remote_url, branch, no_pull)
self.meta = None
self.local_path = None
self.remote_location = None
Expand Down Expand Up @@ -139,7 +139,6 @@ def get_local_yaml(self):

if self.repo_type == "pipeline":
# Try to find and load the meta.yml file
repo_name = self.modules_repo.repo_path
module_base_path = os.path.join(self.dir, "modules")
# Check that we have any modules installed from this repo
modules = self.modules_json.get_all_modules().get(self.modules_repo.remote_url)
Expand Down
6 changes: 3 additions & 3 deletions nf_core/modules/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import nf_core.utils
from nf_core.modules.modules_json import ModulesJson

from .modules_command import ModuleCommand
from nf_core.components.components_command import ComponentCommand

log = logging.getLogger(__name__)


class ModuleInstall(ModuleCommand):
class ModuleInstall(ComponentCommand):
def __init__(
self,
pipeline_dir,
Expand All @@ -23,7 +23,7 @@ def __init__(
no_pull=False,
installed_by=False,
):
super().__init__(pipeline_dir, remote_url, branch, no_pull)
super().__init__("modules", pipeline_dir, remote_url, branch, no_pull)
self.force = force
self.prompt = prompt
self.sha = sha
Expand Down
7 changes: 3 additions & 4 deletions nf_core/modules/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

import nf_core.modules.modules_utils
import nf_core.utils
from nf_core.components.components_command import ComponentCommand
from nf_core.lint_utils import console
from nf_core.modules.modules_command import ModuleCommand
from nf_core.modules.modules_json import ModulesJson
from nf_core.modules.modules_repo import ModulesRepo
from nf_core.modules.nfcore_module import NFCoreModule
from nf_core.utils import plural_s as _s

Expand All @@ -48,7 +47,7 @@ def __init__(self, mod, lint_test, message, file_path):
self.module_name = mod.module_name


class ModuleLint(ModuleCommand):
class ModuleLint(ComponentCommand):
"""
An object for linting modules either in a clone of the 'nf-core/modules'
repository or in any nf-core pipeline directory
Expand All @@ -73,7 +72,7 @@ def __init__(
no_pull=False,
hide_progress=False,
):
super().__init__(dir=dir, remote_url=remote_url, branch=branch, no_pull=no_pull, hide_progress=False)
super().__init__("modules", dir=dir, remote_url=remote_url, branch=branch, no_pull=no_pull, hide_progress=False)

self.fail_warned = fail_warned
self.passed = []
Expand Down
86 changes: 0 additions & 86 deletions nf_core/modules/modules_command.py

This file was deleted.

6 changes: 3 additions & 3 deletions nf_core/modules/modules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

import nf_core.modules.modules_utils
import nf_core.utils
from nf_core.modules.modules_command import ModuleCommand
from nf_core.components.components_command import ComponentCommand
from nf_core.modules.modules_json import ModulesJson

log = logging.getLogger(__name__)


class ModulesTest(ModuleCommand):
class ModulesTest(ComponentCommand):
"""
Class to run module pytests.

Expand Down Expand Up @@ -61,7 +61,7 @@ def __init__(
self.no_prompts = no_prompts
self.pytest_args = pytest_args

super().__init__(".", remote_url, branch, no_pull)
super().__init__("modules", ".", remote_url, branch, no_pull)

def run(self):
"""Run test steps"""
Expand Down
6 changes: 3 additions & 3 deletions nf_core/modules/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
import questionary

import nf_core.utils
from nf_core.components.components_command import ComponentCommand

from .modules_command import ModuleCommand
from .modules_differ import ModulesDiffer
from .modules_json import ModulesJson

log = logging.getLogger(__name__)


class ModulePatch(ModuleCommand):
class ModulePatch(ComponentCommand):
def __init__(self, dir, remote_url=None, branch=None, no_pull=False):
super().__init__(dir, remote_url, branch, no_pull)
super().__init__("modules", dir, remote_url, branch, no_pull)

self.modules_json = ModulesJson(dir)

Expand Down
7 changes: 5 additions & 2 deletions nf_core/modules/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import questionary

import nf_core.utils
from nf_core.components.components_command import ComponentCommand

from .modules_command import ModuleCommand
from .modules_json import ModulesJson

log = logging.getLogger(__name__)


class ModuleRemove(ModuleCommand):
class ModuleRemove(ComponentCommand):
def __init__(self, pipeline_dir):
super().__init__("modules", pipeline_dir)

def remove(self, module):
"""
Remove an already installed module
Expand Down
Loading