Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:nf-core/tools into support-update-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikDanielsson committed Aug 1, 2022
2 parents 3607093 + d070fc6 commit 46f60d7
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 44 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,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 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:
```
2 changes: 1 addition & 1 deletion nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,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
1 change: 1 addition & 0 deletions nf_core/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,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
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)
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
13 changes: 6 additions & 7 deletions nf_core/modules/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def init_mod_name(self, module):
Args:
module: str: Module name to check
"""
if module is not None:
return module
else:
if module is None:
local = questionary.confirm(
"Is the module locally installed?", style=nf_core.utils.nfcore_question_style
).unsafe_ask()
Expand All @@ -68,7 +66,8 @@ def init_mod_name(self, module):
module = questionary.autocomplete(
"Please select a new module", choices=modules, style=nf_core.utils.nfcore_question_style
).unsafe_ask()
return module

return module

def get_module_info(self):
"""Given the name of a module, parse meta.yml and print usage help."""
Expand All @@ -82,7 +81,7 @@ def get_module_info(self):
self.meta = self.get_remote_yaml()

# Could not find the meta
if self.meta == False:
if self.meta is False:
raise UserWarning(f"Could not find module '{self.module}'")

return self.generate_module_info_help()
Expand Down Expand Up @@ -113,7 +112,6 @@ def get_local_yaml(self):
return yaml.safe_load(fh)

log.debug(f"Module '{self.module}' meta.yml not found locally")
return None
else:
module_base_path = os.path.join(self.dir, "modules")
if self.module in os.listdir(module_base_path):
Expand All @@ -125,7 +123,8 @@ def get_local_yaml(self):
self.local_path = mod_dir
return yaml.safe_load(fh)
log.debug(f"Module '{self.module}' meta.yml not found locally")
return None

return None

def get_remote_yaml(self):
"""Attempt to get the meta.yml file from a remote repo.
Expand Down
17 changes: 15 additions & 2 deletions nf_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def check_if_outdated(current_version=None, remote_version=None, source_url="htt
if os.environ.get("NFCORE_NO_VERSION_CHECK", False):
return True
# Set and clean up the current version string
if current_version == None:
if current_version is None:
current_version = nf_core.__version__
current_version = re.sub(r"[^0-9\.]", "", current_version)
# Build the URL to check against
source_url = os.environ.get("NFCORE_VERSION_URL", source_url)
source_url = f"{source_url}?v={current_version}"
# Fetch and clean up the remote version
if remote_version == None:
if remote_version is None:
response = requests.get(source_url, timeout=3)
remote_version = re.sub(r"[^0-9\.]", "", response.text)
# Check if we have an available update
Expand Down Expand Up @@ -993,3 +993,16 @@ def plural_es(list_or_int):
"""Return a 'es' if the input is not one or has not the length of one."""
length = list_or_int if isinstance(list_or_int, int) else len(list_or_int)
return "es" * (length != 1)


# From Stack Overflow: https://stackoverflow.com/a/14693789/713980
# Placed at top level as to only compile it once
ANSI_ESCAPE_RE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")


def strip_ansi_codes(string, replace_with=""):
"""Strip ANSI colouring codes from a string to return plain text.
From Stack Overflow: https://stackoverflow.com/a/14693789/713980
"""
return ANSI_ESCAPE_RE.sub(replace_with, string)
6 changes: 3 additions & 3 deletions tests/test_bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_bump_pipeline_version(datafiles, tmp_path):
# Get a workflow and configs
test_pipeline_dir = os.path.join(tmp_path, "nf-core-testpipeline")
create_obj = nf_core.create.PipelineCreate(
"testpipeline", "This is a test pipeline", "Test McTestFace", outdir=test_pipeline_dir, plain=True
"testpipeline", "This is a test pipeline", "Test McTestFace", no_git=True, outdir=test_pipeline_dir, plain=True
)
create_obj.init_pipeline()
pipeline_obj = nf_core.utils.Pipeline(test_pipeline_dir)
Expand All @@ -38,7 +38,7 @@ def test_dev_bump_pipeline_version(datafiles, tmp_path):
# Get a workflow and configs
test_pipeline_dir = os.path.join(tmp_path, "nf-core-testpipeline")
create_obj = nf_core.create.PipelineCreate(
"testpipeline", "This is a test pipeline", "Test McTestFace", outdir=test_pipeline_dir, plain=True
"testpipeline", "This is a test pipeline", "Test McTestFace", no_git=True, outdir=test_pipeline_dir, plain=True
)
create_obj.init_pipeline()
pipeline_obj = nf_core.utils.Pipeline(test_pipeline_dir)
Expand All @@ -57,7 +57,7 @@ def test_bump_nextflow_version(datafiles, tmp_path):
# Get a workflow and configs
test_pipeline_dir = os.path.join(tmp_path, "nf-core-testpipeline")
create_obj = nf_core.create.PipelineCreate(
"testpipeline", "This is a test pipeline", "Test McTestFace", outdir=test_pipeline_dir, plain=True
"testpipeline", "This is a test pipeline", "Test McTestFace", no_git=True, outdir=test_pipeline_dir, plain=True
)
create_obj.init_pipeline()
pipeline_obj = nf_core.utils.Pipeline(test_pipeline_dir)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ def test_wf_use_local_configs(self, tmp_path):
# Get a workflow and configs
test_pipeline_dir = os.path.join(tmp_path, "nf-core-testpipeline")
create_obj = nf_core.create.PipelineCreate(
"testpipeline", "This is a test pipeline", "Test McTestFace", outdir=test_pipeline_dir, plain=True
"testpipeline",
"This is a test pipeline",
"Test McTestFace",
no_git=True,
outdir=test_pipeline_dir,
plain=True,
)
create_obj.init_pipeline()

Expand Down
8 changes: 0 additions & 8 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ def test_wrap_quotes(self):
md = self.lint_obj._wrap_quotes(["one", "two", "three"])
assert md == "`one` or `two` or `three`"

def test_strip_ansi_codes(self):
"""Check that we can make rich text strings plain
String prints ls examplefile.zip, where examplefile.zip is red bold text
"""
stripped = self.lint_obj._strip_ansi_codes("ls \x1b[00m\x1b[01;31mexamplefile.zip\x1b[00m\x1b[01;31m")
assert stripped == "ls examplefile.zip"

def test_sphinx_md_files(self):
"""Check that we have .md files for all lint module code,
and that there are no unexpected files (eg. deleted lint tests)"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def setUp(self):
self.template_dir = os.path.join(root_repo_dir, "nf_core", "pipeline-template")
self.pipeline_dir = os.path.join(self.tmp_dir, "mypipeline")
nf_core.create.PipelineCreate(
"mypipeline", "it is mine", "me", outdir=self.pipeline_dir, plain=True
"mypipeline", "it is mine", "me", no_git=True, outdir=self.pipeline_dir, plain=True
).init_pipeline()
# Set up install objects
print("Setting up install objects")
Expand Down
16 changes: 15 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
from .utils import with_temporary_folder


def test_strip_ansi_codes():
"""Check that we can make rich text strings plain
String prints ls examplefile.zip, where examplefile.zip is red bold text
"""
stripped = nf_core.utils.strip_ansi_codes("ls \x1b[00m\x1b[01;31mexamplefile.zip\x1b[00m\x1b[01;31m")
assert stripped == "ls examplefile.zip"


class TestUtils(unittest.TestCase):
"""Class for utils tests"""

Expand All @@ -29,7 +38,12 @@ def setUp(self):
self.tmp_dir = tempfile.mkdtemp()
self.test_pipeline_dir = os.path.join(self.tmp_dir, "nf-core-testpipeline")
self.create_obj = nf_core.create.PipelineCreate(
"testpipeline", "This is a test pipeline", "Test McTestFace", outdir=self.test_pipeline_dir, plain=True
"testpipeline",
"This is a test pipeline",
"Test McTestFace",
no_git=True,
outdir=self.test_pipeline_dir,
plain=True,
)
self.create_obj.init_pipeline()
# Base Pipeline object on this directory
Expand Down

0 comments on commit 46f60d7

Please sign in to comment.