Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 10 additions & 6 deletions nf_core/module-template/modules/meta.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/yaml-schema.json
name: "{{ component_name_underscore }}"
{% if not_empty_template -%}
## TODO nf-core: Add a description of the module and list keywords
{% endif -%}
description: write your description here
keywords:
- sort
- example
- genomics
tools:
- "{{ component }}":
{% if not_empty_template -%}
Expand Down Expand Up @@ -32,9 +36,9 @@ input:
## TODO nf-core: Delete / customise this example input
{%- endif %}
- {{ 'bam:' if not_empty_template else "input:" }}
type: file
description: {{ 'Sorted BAM/CRAM/SAM file' if not_empty_template else "" }}
pattern: {{ '"*.{bam,cram,sam}"' if not_empty_template else "" }}
type: file
description: {{ 'Sorted BAM/CRAM/SAM file' if not_empty_template else "" }}
pattern: {{ '"*.{bam,cram,sam}"' if not_empty_template else "" }}

{% if not_empty_template -%}
## TODO nf-core: Add a description of all of the variables used as output
Expand All @@ -55,9 +59,9 @@ output:
## TODO nf-core: Delete / customise this example output
{%- endif %}
- {{ 'bam:' if not_empty_template else "output:" }}
type: file
description: {{ 'Sorted BAM/CRAM/SAM file' if not_empty_template else "" }}
pattern: {{ '"*.{bam,cram,sam}"' if not_empty_template else "" }}
type: file
description: {{ 'Sorted BAM/CRAM/SAM file' if not_empty_template else "" }}
pattern: {{ '"*.{bam,cram,sam}"' if not_empty_template else "" }}

authors:
- "{{ author }}"
46 changes: 28 additions & 18 deletions nf_core/modules/lint/meta_yml.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
from pathlib import Path

import jsonschema.validators
import yaml

from nf_core.modules.modules_differ import ModulesDiffer
Expand All @@ -10,17 +12,15 @@ def meta_yml(module_lint_object, module):
Lint a ``meta.yml`` file

The lint test checks that the module has
a ``meta.yml`` file and that it contains
the required keys: ``name``, input`` and
``output``.
a ``meta.yml`` file and that it follows the
JSON schema defined in the ``modules/yaml-schema.json``
file in the nf-core/modules repository.

In addition it checks that the module name
and module input is consistent between the
``meta.yml`` and the ``main.nf``.

"""
required_keys = ["name", "output"]
required_keys_lists = ["input", "output"]
# Check if we have a patch file, get original file in that case
meta_yaml = None
if module.is_patched:
Expand All @@ -42,21 +42,31 @@ def meta_yml(module_lint_object, module):
module.failed.append(("meta_yml_exists", "Module `meta.yml` does not exist", module.meta_yml))
return

# Confirm that all required keys are given
contains_required_keys = True
all_list_children = True
for rk in required_keys:
if rk not in meta_yaml.keys():
module.failed.append(("meta_required_keys", f"`{rk}` not specified in YAML", module.meta_yml))
contains_required_keys = False
elif rk in meta_yaml.keys() and not isinstance(meta_yaml[rk], list) and rk in required_keys_lists:
module.failed.append(("meta_required_keys", f"`{rk}` is not a list", module.meta_yml))
all_list_children = False
if contains_required_keys:
module.passed.append(("meta_required_keys", "`meta.yml` contains all required keys", module.meta_yml))
# Confirm that the meta.yml file is valid according to the JSON schema
valid_meta_yml = True
try:
with open(Path(module_lint_object.modules_repo.local_repo_dir, "modules/yaml-schema.json"), "r") as fh:
schema = json.load(fh)
jsonschema.validators.validate(instance=meta_yaml, schema=schema)
module.passed.append(("meta_yml_valid", "Module `meta.yml` is valid", module.meta_yml))
except jsonschema.exceptions.ValidationError as e:
valid_meta_yml = False
hint = ""
if len(e.path) > 0:
hint = f"\nCheck the entry for `{e.path[0]}`."
if e.message.startswith("None is not of type 'object'") and len(e.path) > 2:
hint = f"\nCheck that the child entries of {e.path[0]+'.'+e.path[2]} are indented correctly."
module.failed.append(
(
"meta_yml_valid",
f"The `meta.yml` of the module {module.module_name} is not valid: {e.message}.{hint}",
module.meta_yml,
)
)
return

# Confirm that all input and output channels are specified
if contains_required_keys and all_list_children:
if valid_meta_yml:
if "input" in meta_yaml:
meta_input = [list(x.keys())[0] for x in meta_yaml["input"]]
for input in module.inputs:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nf_core/subworkflow-template/subworkflows/meta.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/subworkflows/yaml-schema.json
name: "{{ subworkflow_name }}"
## TODO nf-core: Add a description of the subworkflow and list keywords
description: Sort SAM/BAM/CRAM file
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_modules_lint_empty(self):


def test_modules_lint_new_modules(self):
"""lint all modules in nf-core/modules repo clone"""
"""lint a new module"""
module_lint = nf_core.modules.ModuleLint(dir=self.nfcore_modules)
module_lint.lint(print_results=True, all_modules=True)
assert len(module_lint.failed) == 0, f"Linting failed with {[x.__dict__ for x in module_lint.failed]}"
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""

ORG_SHA = "002623ccc88a3b0cb302c7d8f13792a95354d9f2"
CORRECT_SHA = "63fd3cdb1be733041db74c15542a7b5b8f4095ed"
CORRECT_SHA = "0245a9277d51a47c8aa68d264d294cf45312fab8"
SUCCEED_SHA = "ba15c20c032c549d77c5773659f19c2927daf48e"
FAIL_SHA = "67b642d4471c4005220a342cad3818d5ba2b5a73"
BISMARK_ALIGN = "bismark/align"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ def create_modules_repo_dummy(tmp_dir):
with requests_cache.disabled():
module_create.create()

# Remove doi from meta.yml which makes lint fail
meta_yml = os.path.join(root_dir, "modules", "nf-core", "bpipe", "test", "meta.yml")
with open(meta_yml, "r") as fh:
lines = fh.readlines()
for line_index in range(len(lines)):
if "doi" in lines[line_index]:
to_pop = line_index
lines.pop(to_pop)
with open(meta_yml, "w") as fh:
fh.writelines(lines)

return root_dir


Expand Down
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def mock_anaconda_api_calls(rsps: responses.RequestsMock, module, version):
anaconda_mock = {
"latest_version": version.split("--")[0],
"summary": "",
"doc_url": "",
"dev_url": "",
"doc_url": "http://test",
"dev_url": "http://test",
"files": [{"version": version.split("--")[0]}],
"license": "",
}
Expand Down