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
15 changes: 15 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
import versionix.registry as _registry


@pytest.fixture(autouse=True)
def _inject_test_registry_entries():
"""Inject test-only entries into the registry for the duration of each test."""
test_entries = {
"for_testing_empty_parsers": {"options": "", "parsers": []},
"for_testing_no_parsers": {"options": ""},
}
_registry.metadata.update(test_entries)
yield
for key in test_entries:
_registry.metadata.pop(key, None)
14 changes: 13 additions & 1 deletion test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def test_script(fp, mocker):
print(result)

runner.invoke(main, ["--registered"])
runner.invoke(main, ["--stats"])
runner.invoke(
main,
)
Expand All @@ -121,6 +120,19 @@ def test_DESeq2_error(fp, mocker):
assert True


def test_DESeq2_uses_rscript_caller(fp, mocker):
# DESeq2 is registered with a Rscript caller; the PATH check should look for Rscript, not DESeq2
def which_side_effect(cmd):
return "/usr/bin/Rscript" if cmd == "Rscript" else None

mocker.patch("versionix.parser.shutil.which", side_effect=which_side_effect)
fp.register(
'Rscript -e "library(DESeq2);packageVersion(\'DESeq2\')"',
stdout=["[1] '1.42.0'"],
)
assert get_version("DESeq2") == "1.42.0"


def test_empty_parsers(fp, mocker):
try:
mocker.patch("shutil.which", return_value=True)
Expand Down
20 changes: 14 additions & 6 deletions versionix/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _get_container_runner(container):
sys.exit(1)


def get_version(standalone, verbose=True, R=False, container=None):
def get_version(standalone, verbose=True, container=None):
"""Main entry point that returns the version of an existing executable"""
# we should use check_output in case the standalone opens a GUI (e.g. fastqc --WRONG pops up the GUI)

Expand All @@ -135,10 +135,18 @@ def get_version(standalone, verbose=True, R=False, container=None):
standalone.startswith("singularity") or standalone.startswith("apptainer") or standalone.startswith("docker")
): # pragma: no cover
pass
elif shutil.which(standalone) is None:
if verbose:
logger.error(f"{standalone} command not found in your environment")
sys.exit(1)
else:
# For registered tools with a custom caller, check the caller binary rather than
# the standalone name (e.g. DESeq2 is invoked via `Rscript`, not a `DESeq2` binary).
if standalone in metadata:
caller = metadata[standalone].get("caller", standalone)
check_cmd = shlex.split(caller)[0]
else:
check_cmd = standalone
if shutil.which(check_cmd) is None:
if verbose:
logger.error(f"{check_cmd} command not found in your environment")
sys.exit(1)

# is it registered ?
if standalone in metadata.keys():
Expand Down Expand Up @@ -174,7 +182,7 @@ def search_registered(standalone, container_runner=None):
raise ValueError(f"parsers for {standalone} is incorrect. Must be a list of valid parsers")

try:
cmd = f"{caller} {options}"
cmd = f"{caller} {options}".strip()
if container_runner:
cmd = f"{container_runner} {cmd}"
p = subprocess.run(cmd, capture_output=True, universal_newlines=True, shell=True)
Expand Down
6 changes: 1 addition & 5 deletions versionix/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"circlator": {"options": "version", "parsers": [lambda x: x.stdout.strip()]},
"DESeq2": {
"caller": "Rscript -e \"library(DESeq2);packageVersion('DESeq2')\"",
"parsers": [lambda x: x.stdout.split()[1].strip("’‘")],
"parsers": [lambda x: x.stdout.split()[1].strip("'")],
},
# dot -v hangs so we need to register this command.
"dot": {"options": "-V", "parsers": [lambda x: x.stderr.split()[4].strip()]},
Expand All @@ -45,8 +45,4 @@
# # "parser": parser_split_2
# },
# "vt": {"options": "--version", "parser": parser_split_2_strip_v},
"for_testing_empty_parsers": {"options": "", "parsers": []},
"for_testing_no_parsers": {
"options": "",
},
}
38 changes: 13 additions & 25 deletions versionix/scripts.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
###########################################################################
# Versionix is a project to manage reproducible containers #
# #
# Authors: see CONTRIBUTORS.rst #
# Copyright © 2023 Sequana dev team #
# See the COPYRIGHT file for details #
# #
# Versionix is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# Versionix is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program (COPYING file). #
# If not, see <http://www.gnu.org/licenses/>. #
###########################################################################
""".. rubric:: Standalone application dedicated to Damona"""
#
# This file is part of Versionix software
#
# Copyright (c) 2023 - Sequana Dev Team (https://sequana.readthedocs.io)
#
# Distributed under the terms of the 3-clause BSD license.
# The full license is in the LICENSE file, distributed with this software.
#
# Website: https://github.com/sequana/versionix
# Contributors: https://github.com/sequana/versionix/graphs/contributors
##############################################################################
""".. rubric:: Standalone application (CLI entry point) for Versionix"""
import sys

import colorlog
Expand All @@ -32,9 +22,7 @@

CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])

click.rich_click.USE_MARKDOWN = True
click.rich_click.SHOW_METAVARS_COLUMN = True
click.rich_click.APPEND_METAVARS_HELP = True
click.rich_click.TEXT_MARKUP = "markdown"
click.rich_click.STYLE_ERRORS_SUGGESTION = "magenta italic"
click.rich_click.SHOW_ARGUMENTS = True

Expand Down
Loading