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

Fix linting multiple remotes #2071

Merged
merged 15 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions nf_core/components/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ def init_mod_name(self, component):
components = self.get_components_clone_modules()
else:
components = self.modules_json.get_all_components(self.component_type).get(
self.modules_repo.remote_url
self.modules_repo.remote_url, {}
)
components = [
component if directory == self.modules_repo.repo_path else f"{directory}/{component}"
for directory, component in components
]
if components is None:
if not components:
raise UserWarning(
f"No {self.component_type[:-1]} installed from '{self.modules_repo.remote_url}'"
)
Expand Down
36 changes: 20 additions & 16 deletions nf_core/modules/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,27 @@ def __init__(
if self.repo_type == "pipeline":
modules_json = ModulesJson(self.dir)
modules_json.check_up_to_date()
all_pipeline_modules = modules_json.get_all_components(self.component_type)
if all_pipeline_modules is not None and self.modules_repo.remote_url in all_pipeline_modules:
module_dir = Path(self.dir, "modules", self.modules_repo.repo_path)
self.all_remote_modules = [
NFCoreModule(m[1], self.modules_repo.remote_url, module_dir / m[1], self.repo_type, Path(self.dir))
for m in all_pipeline_modules[self.modules_repo.remote_url]
] # m = (module_dir, module_name)
if not self.all_remote_modules:
raise LookupError(f"No modules from {self.modules_repo.remote_url} installed in pipeline.")
self.all_remote_modules = []
for repo_url, components in modules_json.get_all_components(self.component_type).items():
for org, comp in components:
self.all_remote_modules.append(
NFCoreModule(
comp,
repo_url,
Path(self.dir, self.component_type, org, comp),
self.repo_type,
Path(self.dir),
)
)
local_module_dir = Path(self.dir, "modules", "local")
self.all_local_modules = [
NFCoreModule(m, None, local_module_dir / m, self.repo_type, Path(self.dir), nf_core_module=False)
for m in self.get_local_components()
]

else:
raise LookupError(f"No modules from {self.modules_repo.remote_url} installed in pipeline.")
self.all_local_modules = []
if local_module_dir.exists():
self.all_local_modules = [
NFCoreModule(
m, None, Path(local_module_dir, m), self.repo_type, Path(self.dir), remote_module=False
)
for m in self.get_local_components()
]
else:
module_dir = Path(self.dir, self.default_modules_path)
self.all_remote_modules = [
Expand Down
9 changes: 6 additions & 3 deletions nf_core/modules/lint/module_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import tempfile
from pathlib import Path

import nf_core.modules.modules_repo
from nf_core.modules.modules_differ import ModulesDiffer


Expand Down Expand Up @@ -39,10 +40,12 @@ def module_changes(module_lint_object, module):
return
else:
tempdir = module.module_dir
module.branch = module_lint_object.modules_json.get_component_branch(
"modules", module.module_name, module.repo_url, module.org
)
modules_repo = nf_core.modules.modules_repo.ModulesRepo(remote_url=module.repo_url, branch=module.branch)

for f, same in module_lint_object.modules_repo.module_files_identical(
module.module_name, tempdir, module.git_sha
).items():
for f, same in modules_repo.module_files_identical(module.module_dir, tempdir, module.git_sha).items():
mashehu marked this conversation as resolved.
Show resolved Hide resolved
if same:
module.passed.append(
(
Expand Down
11 changes: 6 additions & 5 deletions nf_core/modules/lint/module_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ def module_version(module_lint_object, module):
"""

modules_json_path = Path(module_lint_object.dir, "modules.json")

# Verify that a git_sha exists in the `modules.json` file for this module
version = module_lint_object.modules_json.get_module_version(
module.module_name, module_lint_object.modules_repo.remote_url, module_lint_object.modules_repo.repo_path
)
version = module_lint_object.modules_json.get_module_version(module.module_name, module.repo_url, module.org)
if version is None:
module.failed.append(("git_sha", "No git_sha entry in `modules.json`", modules_json_path))
return
Expand All @@ -36,7 +33,11 @@ def module_version(module_lint_object, module):

# Check whether a new version is available
try:
modules_repo = nf_core.modules.modules_repo.ModulesRepo()
module.branch = module_lint_object.modules_json.get_component_branch(
"modules", module.module_name, module.repo_url, module.org
)
modules_repo = nf_core.modules.modules_repo.ModulesRepo(remote_url=module.repo_url, branch=module.branch)

module_git_log = modules_repo.get_component_git_log(module.module_name, "modules")
if version == next(module_git_log)["git_sha"]:
module.passed.append(("module_version", "Module is the latest version", module.module_dir))
Expand Down
7 changes: 3 additions & 4 deletions nf_core/modules/modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ def find_correct_commit_sha(self, component_type, component_name, component_path
for commit in modules_repo.get_component_git_log(component_name, component_type, depth=1000)
)
for commit_sha in commit_shas:
if all(modules_repo.module_files_identical(component_name, component_path, commit_sha).values()):
module_dir = modules_repo.get_component_dir(component_name, component_type)
if all(modules_repo.module_files_identical(module_dir, component_path, commit_sha).values()):
return commit_sha
return None

Expand Down Expand Up @@ -926,8 +927,6 @@ def get_all_components(self, component_type):
if component_type in repo_entry:
for dir, components in repo_entry[component_type].items():
self.pipeline_components[repo] = [(dir, m) for m in components]
if self.pipeline_components == {}:
self.pipeline_components = None

return self.pipeline_components

Expand Down Expand Up @@ -977,7 +976,7 @@ def get_component_branch(self, component_type, component, repo_url, install_dir)
Returns:
(str): The branch name
Raises:
LookupError: If their is no branch entry in the `modules.json`
LookupError: If there is no branch entry in the `modules.json`
"""
if self.modules_json is None:
self.load()
Expand Down
3 changes: 1 addition & 2 deletions nf_core/modules/modules_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def install_component(self, component_name, install_dir, commit, component_type)
self.checkout_branch()
return True

def module_files_identical(self, module_name, base_path, commit):
def module_files_identical(self, module_dir, base_path, commit):
"""
Checks whether the module files in a pipeline are identical to the ones in the remote
Args:
Expand All @@ -376,7 +376,6 @@ def module_files_identical(self, module_name, base_path, commit):
else:
self.checkout(commit)
module_files = ["main.nf", "meta.yml"]
module_dir = self.get_component_dir(module_name, "modules")
files_identical = {file: True for file in module_files}
for file in module_files:
try:
Expand Down
7 changes: 4 additions & 3 deletions nf_core/modules/nfcore_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NFCoreModule:
Includes functionality for linting
"""

def __init__(self, module_name, repo_url, module_dir, repo_type, base_dir, nf_core_module=True):
def __init__(self, module_name, repo_url, module_dir, repo_type, base_dir, remote_module=True):
"""
Initialize the object

Expand All @@ -20,7 +20,7 @@ def __init__(self, module_name, repo_url, module_dir, repo_type, base_dir, nf_co
whether the directory is a pipeline or clone
of nf-core/modules.
base_dir (Path): The absolute path to the pipeline base dir
nf_core_module (bool): Whether the module is to be treated as a
remote_module (bool): Whether the module is to be treated as a
nf-core or local module
"""
self.module_name = module_name
Expand All @@ -38,12 +38,13 @@ def __init__(self, module_name, repo_url, module_dir, repo_type, base_dir, nf_co
self.is_patched = False
self.is_patched = None
mashehu marked this conversation as resolved.
Show resolved Hide resolved

if nf_core_module:
if remote_module:
# Initialize the important files
self.main_nf = self.module_dir / "main.nf"
self.meta_yml = self.module_dir / "meta.yml"

repo_dir = self.module_dir.parts[: self.module_dir.parts.index(self.module_name.split("/")[0])][-1]
self.org = repo_dir
self.test_dir = Path(self.base_dir, "tests", "modules", repo_dir, self.module_name)
self.test_yml = self.test_dir / "test.yml"
self.test_main_nf = self.test_dir / "main.nf"
Expand Down