Skip to content

Commit

Permalink
Merge branch 'dev' into update-module
Browse files Browse the repository at this point in the history
  • Loading branch information
mirpedrol authored Aug 1, 2022
2 parents 775afe4 + b7f44d3 commit dee98e6
Show file tree
Hide file tree
Showing 46 changed files with 1,233 additions and 307 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Add `CITATION.cff` [#361](https://github.com/nf-core/tools/issues/361)
- Add Gitpod and Mamba profiles to the pipeline template ([#1673](https://github.com/nf-core/tools/pull/1673))
- Remove call to `getGenomeAttribute` in `main.nf` when running `nf-core create` without iGenomes ([#1670](https://github.com/nf-core/tools/issues/1670))
- Make `nf-core create` fail if Git default branch name is dev or TEMPLATE ([#1705](https://github.com/nf-core/tools/pull/1705))

### Linting

Expand Down Expand Up @@ -39,6 +40,9 @@
- Allow customization of the `nf-core` pipeline template when using `nf-core create` ([#1548](https://github.com/nf-core/tools/issues/1548))
- Add Refgenie integration: updating of nextflow config files with a refgenie database ([#1090](https://github.com/nf-core/tools/pull/1090))
- Fix `--key` option in `nf-core lint` when supplying a module lint test name ([#1681](https://github.com/nf-core/tools/issues/1681))
- Add `no_git=True` when creating a new pipeline and initialising a git repository is not needed in `nf-core lint` and `nf-core bump-version` ([#1709](https://github.com/nf-core/tools/pull/1709))
- Move `strip_ansi_code` function in lint to `utils.py`
- Simplify control flow and don't use equality comparison for `None` and booleans

### Modules

Expand All @@ -53,6 +57,11 @@
- Fix inconsistencies in the `--save-diff` flag `nf-core modules update`. Refactor `nf-core modules update` ([#1536](https://github.com/nf-core/tools/pull/1536))
- Fix bug in `ModulesJson.check_up_to_date` causing it to ask for the remote of local modules
- Handle errors when updating module version with `nf-core modules update --fix-version` ([#1671](https://github.com/nf-core/tools/pull/1671))
- Make `nf-core modules update --save-diff` work when files were created or removed ([#1694](https://github.com/nf-core/tools/issues/1694))
- Get the latest common build for Docker and Singularity containers of a module ([#1702](https://github.com/nf-core/tools/pull/1702))
- Add short option for `--no-pull` option in `nf-core modules`
- Add `nf-core modules patch` command ([#1312](https://github.com/nf-core/tools/issues/1312))
- Add support for patch in `nf-core modules update` command ([#1312](https://github.com/nf-core/tools/issues/1312))

## [v2.4.1 - Cobolt Koala Patch](https://github.com/nf-core/tools/releases/tag/2.4) - [2022-05-16]

Expand Down
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,49 @@ INFO Removing star/align

You can pass the module name as an optional argument to `nf-core modules remove` instead of using the cli prompt, eg: `nf-core modules remove fastqc`. To specify the pipeline directory, use `--dir <pipeline_dir>`.

### Create a patch file for minor local changes in a module

If you want to make a minor change to a module but still keep it up date with the remote version, you can create a patch file using `nf-core modules patch`.

```console
$ nf-core modules patch
,--./,-.
___ __ __ __ ___ /,-._.--~\
|\ | |__ __ / ` / \ |__) |__ } {
| \| | \__, \__/ | \ |___ \`-._,-`-,
`._,._,'
nf-core/tools version 2.5.dev0 - https://nf-co.re
? Tool: bismark/align
INFO Changes in module 'nf-core/modules/bismark/align'
INFO Changes in 'bismark/align/main.nf':
--- modules/nf-core/modules/bismark/align/main.nf
+++ modules/nf-core/modules/bismark/align/main.nf
@@ -19,8 +19,7 @@
}
input:
- tuple val(meta), path(reads)
- path index
+ tuple val(meta), path(reads), path index
output:
tuple val(meta), path("*bam") , emit: bam
INFO 'modules/nf-core/modules/bismark/align/functions.nf' is unchanged
INFO 'modules/nf-core/modules/bismark/align/meta.yml' is unchanged
INFO Patch file of 'nf-core/modules/bismark/align' written to 'modules/nf-core/modules/bismark/align/bismark-align.diff'
```

The generated patches work with `nf-core modules update`: when you install a new version of the module, the command tries to apply
the patch automatically. The patch application fails if the new version of the module modifies the same lines as the patch. In this case,
the patch new version is installed but the old patch file is preversed.

### Create a new module

This command creates a new nf-core module from the nf-core module template.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/_src/api/lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ See the [Lint Tests](../pipeline_lint_tests/index.md) docs for information about
```{eval-rst}
.. autoclass:: nf_core.lint.PipelineLint
:members: _lint_pipeline
:private-members: _print_results, _get_results_md, _save_json_results, _wrap_quotes, _strip_ansi_codes
:private-members: _print_results, _get_results_md, _save_json_results, _wrap_quotes
:show-inheritance:
```
39 changes: 35 additions & 4 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
""" nf-core: Helper tools for use with nf-core Nextflow pipelines. """
import logging
import os
import re
import sys
from email.policy import default

import rich.console
import rich.logging
Expand Down Expand Up @@ -49,7 +47,7 @@
"nf-core modules": [
{
"name": "For pipelines",
"commands": ["list", "info", "install", "update", "remove"],
"commands": ["list", "info", "install", "update", "remove", "patch"],
},
{
"name": "Developing new modules",
Expand Down Expand Up @@ -191,7 +189,7 @@ def launch(pipeline, id, revision, command_only, params_in, params_out, save_all
launcher = nf_core.launch.Launch(
pipeline, revision, command_only, params_in, params_out, save_all, show_hidden, url, id
)
if launcher.launch_pipeline() == False:
if not launcher.launch_pipeline():
sys.exit(1)


Expand Down Expand Up @@ -350,6 +348,7 @@ def lint(dir, release, fix, key, show_passed, fail_ignored, fail_warned, markdow
)
@click.option("-b", "--branch", type=str, default=None, help="Branch of git repository hosting modules.")
@click.option(
"-N",
"--no-pull",
is_flag=True,
default=False,
Expand Down Expand Up @@ -539,6 +538,38 @@ def update(ctx, tool, dir, force, prompt, sha, all, preview, save_diff):
sys.exit(1)


# nf-core modules patch
@modules.command()
@click.pass_context
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
@click.option(
"-d",
"--dir",
type=click.Path(exists=True),
default=".",
help=r"Pipeline directory. [dim]\[default: current working directory][/]",
)
def patch(ctx, tool, dir):
"""
Create a patch file for minor changes in a module
Checks if a module has been modified locally and creates a patch file
describing how the module has changed from the remote version
"""
try:
module_patch = nf_core.modules.ModulePatch(
dir,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
ctx.obj["modules_repo_base_path"],
)
module_patch.patch(tool)
except (UserWarning, LookupError) as e:
log.error(e)
sys.exit(1)


# nf-core modules remove
@modules.command()
@click.pass_context
Expand Down
1 change: 0 additions & 1 deletion nf_core/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging
import os
import re
import sys

import rich.console

Expand Down
20 changes: 19 additions & 1 deletion nf_core/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Creates a nf-core pipeline matching the current
organization's specification based on a template.
"""
import configparser
import imghdr
import logging
import os
Expand Down Expand Up @@ -490,7 +491,24 @@ def download_pipeline_logo(self, url, img_fn):
break

def git_init_pipeline(self):
"""Initialises the new pipeline as a Git repository and submits first commit."""
"""Initialises the new pipeline as a Git repository and submits first commit.
Raises:
UserWarning: if Git default branch is set to 'dev' or 'TEMPLATE'.
"""
# Check that the default branch is not dev
try:
default_branch = git.config.GitConfigParser().get_value("init", "defaultBranch")
except configparser.Error:
default_branch = None
log.debug("Could not read init.defaultBranch")
if default_branch == "dev" or default_branch == "TEMPLATE":
raise UserWarning(
f"Your Git defaultBranch is set to '{default_branch}', which is incompatible with nf-core.\n"
"This can be modified with the command [white on grey23] git config --global init.defaultBranch <NAME> [/]\n"
"Pipeline git repository is not initialised."
)
# Initialise pipeline
log.info("Initialising pipeline git repository")
repo = git.Repo.init(self.outdir)
repo.git.add(A=True)
Expand Down
2 changes: 1 addition & 1 deletion nf_core/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import webbrowser

import questionary
import requests
from rich.console import Console
from rich.markdown import Markdown
from rich.prompt import Confirm
Expand Down Expand Up @@ -182,6 +181,7 @@ def launch_pipeline(self):
# Build and launch the `nextflow run` command
self.build_command()
self.launch_workflow()
return True

def get_pipeline_schema(self):
"""Load and validate the schema from the supplied pipeline"""
Expand Down
1 change: 0 additions & 1 deletion nf_core/licences.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json
import logging
import os
import re

import requests
import rich.console
Expand Down
29 changes: 11 additions & 18 deletions nf_core/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from nf_core import __version__
from nf_core.lint_utils import console
from nf_core.utils import plural_s as _s
from nf_core.utils import strip_ansi_codes

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -458,7 +459,7 @@ def _get_results_md(self):
"\n".join(
[
f"* [{eid}](https://nf-co.re/tools-docs/lint_tests/{eid}.html) - "
f"{self._strip_ansi_codes(msg, '`')}"
f"{strip_ansi_codes(msg, '`')}"
for eid, msg in self.failed
]
)
Expand All @@ -472,7 +473,7 @@ def _get_results_md(self):
"\n".join(
[
f"* [{eid}](https://nf-co.re/tools-docs/lint_tests/{eid}.html) - "
f"{self._strip_ansi_codes(msg, '`')}"
f"{strip_ansi_codes(msg, '`')}"
for eid, msg in self.ignored
]
)
Expand All @@ -486,7 +487,7 @@ def _get_results_md(self):
"\n".join(
[
f"* [{eid}](https://nf-co.re/tools-docs/lint_tests/{eid}.html) - "
f"{self._strip_ansi_codes(msg, '`')}"
f"{strip_ansi_codes(msg, '`')}"
for eid, msg in self.fixed
]
)
Expand All @@ -500,7 +501,7 @@ def _get_results_md(self):
"\n".join(
[
f"* [{eid}](https://nf-co.re/tools-docs/lint_tests/{eid}.html) - "
f"{self._strip_ansi_codes(msg, '`')}"
f"{strip_ansi_codes(msg, '`')}"
for eid, msg in self.warned
]
)
Expand All @@ -515,7 +516,7 @@ def _get_results_md(self):
[
(
f"* [{eid}](https://nf-co.re/tools-docs/lint_tests/{eid}.html)"
f" - {self._strip_ansi_codes(msg, '`')}"
f" - {strip_ansi_codes(msg, '`')}"
)
for eid, msg in self.passed
]
Expand Down Expand Up @@ -553,11 +554,11 @@ def _save_json_results(self, json_fn):
results = {
"nf_core_tools_version": nf_core.__version__,
"date_run": now.strftime("%Y-%m-%d %H:%M:%S"),
"tests_pass": [[idx, self._strip_ansi_codes(msg)] for idx, msg in self.passed],
"tests_ignored": [[idx, self._strip_ansi_codes(msg)] for idx, msg in self.ignored],
"tests_fixed": [[idx, self._strip_ansi_codes(msg)] for idx, msg in self.fixed],
"tests_warned": [[idx, self._strip_ansi_codes(msg)] for idx, msg in self.warned],
"tests_failed": [[idx, self._strip_ansi_codes(msg)] for idx, msg in self.failed],
"tests_pass": [[idx, strip_ansi_codes(msg)] for idx, msg in self.passed],
"tests_ignored": [[idx, strip_ansi_codes(msg)] for idx, msg in self.ignored],
"tests_fixed": [[idx, strip_ansi_codes(msg)] for idx, msg in self.fixed],
"tests_warned": [[idx, strip_ansi_codes(msg)] for idx, msg in self.warned],
"tests_failed": [[idx, strip_ansi_codes(msg)] for idx, msg in self.failed],
"num_tests_pass": len(self.passed),
"num_tests_ignored": len(self.ignored),
"num_tests_fixed": len(self.fixed),
Expand Down Expand Up @@ -590,11 +591,3 @@ def _wrap_quotes(self, files):
files = [files]
bfiles = [f"`{f}`" for f in files]
return " or ".join(bfiles)

def _strip_ansi_codes(self, string, replace_with=""):
"""Strip ANSI colouring codes from a string to return plain text.
Solution found on Stack Overflow: https://stackoverflow.com/a/14693789/713980
"""
ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
return ansi_escape.sub(replace_with, string)
1 change: 0 additions & 1 deletion nf_core/lint/actions_schema_validation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import glob
import json
import logging
import os

Expand Down
2 changes: 1 addition & 1 deletion nf_core/lint/files_unchanged.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def files_unchanged(self):

test_pipeline_dir = os.path.join(tmp_dir, f"{prefix}-{short_name}")
create_obj = nf_core.create.PipelineCreate(
None, None, None, outdir=test_pipeline_dir, template_yaml_path=template_yaml_path
None, None, None, no_git=True, outdir=test_pipeline_dir, template_yaml_path=template_yaml_path
)
create_obj.init_pipeline()

Expand Down
2 changes: 0 additions & 2 deletions nf_core/lint/modules_json.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python

from logging import warn

from nf_core.modules.modules_command import ModuleCommand
from nf_core.modules.modules_json import ModulesJson

Expand Down
2 changes: 0 additions & 2 deletions nf_core/lint/schema_description.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python

from logging import warn

import nf_core.schema


Expand Down
2 changes: 0 additions & 2 deletions nf_core/lint/schema_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import logging

import jsonschema

import nf_core.schema


Expand Down
1 change: 1 addition & 0 deletions nf_core/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .modules_json import ModulesJson
from .modules_repo import ModulesRepo
from .mulled import MulledImageNameGenerator
from .patch import ModulePatch
from .remove import ModuleRemove
from .test_yml_builder import ModulesTestYmlBuilder
from .update import ModuleUpdate
1 change: 0 additions & 1 deletion nf_core/modules/bump_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from __future__ import print_function

import logging
import os
import re

import questionary
Expand Down
Loading

0 comments on commit dee98e6

Please sign in to comment.