Skip to content

Commit

Permalink
Merge pull request #1 from cokelaer/main
Browse files Browse the repository at this point in the history
some cleanup and add singularity/seqtk cases
  • Loading branch information
cokelaer committed Jun 27, 2023
2 parents 8ad58a4 + 0f659e8 commit d0ab1e3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 43 deletions.
19 changes: 8 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,20 @@ jobs:
sudo apt install -y apptainer
singularity version
- name: install tools
run: |
sudo apt install -y bwa bedtools
sudo apt install -y fastqc
- name: Set up Python 3.X
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Install Versionix using pip
run: |
pip install .[testing]
pip install .
pip install pytest pytest-cov coverage coveralls
- name: Install Damona using pip
run: |
Expand All @@ -60,18 +66,9 @@ jobs:
damona
echo " source ~/.config/damona/damona.sh" >> ~/.bashrc
- name: install some tools for testing
- name: testing
run: |
damona create TEST
damona activate TEST
damona install bwa
damona install fastqc
pytest --cov-report term --cov=versionix
env:
DAMONA_EXE: /usr/share/miniconda/bin/damona
DAMONA_PATH: /home/runner/.config/damona
DAMONA_SINGULARITY_OPTIONS: ""
- name: coveralls
run: |
Expand Down
10 changes: 9 additions & 1 deletion test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@




def test_version():
get_version("ls")

assert get_version("ls")
assert get_version("singularity")


# stable versions can be checked
assert get_version("bwa") == "0.7.17-r1188"
assert get_version("bedtools").startswith("v2")
67 changes: 43 additions & 24 deletions versionix/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@
import sys



def parse_click():
"""versionix, version 0.1.0"""
"""one liner output
versionix, version 0.1.0
"""
raise NotImplementedError


def parse_standalone_version_version(stdout: str):
"""one liner output
singularity version 3.6.2+12-gad3457a9a
"""
return stdout.strip().split()


def parser_Version_column_version(stdout: str, *args):
"""
Expand All @@ -35,32 +47,23 @@ def parser_Version_column_version(stdout: str, *args):
def parser_standalone_version(stdout: str, standalone, *args):
"""
STANDALONE: 1.0.0
STANDALONE 1.0.0
"""
for line in stdout.split("\n"):
if line.startswith(f"{standalone}"):
return line.strip().split()[1].strip()


metadata = {
"default": {"caller": "--version", "parser": None, "citation": "undefined"},
"bwa": {"caller": "stderr", "parser": parser_Version_column_version, "citation": "undefined"},
"bamtools": {"caller": "--version", "parser": parser_standalone_version}
# "art_454":{
# "caller": "stdout",
# "parser": parser_name_Version_version
# }
"seqtk": {"caller": "stderr", "parser": parser_Version_column_version, "citation": "undefined"},
"bamtools": {"caller": "--version", "parser": parser_standalone_version},
"singularity": {"caller": "version", "parser": None},
"bedtools": {"caller": "--version", "parser": parser_standalone_version}
}


def base_version_parser(stdout: str):
"""{NAME}: v1.0.0"""
return stdout.split("\n", 1)[0].split()[-1]


def seqtk_version_parser(stderr: str):
return stderr.strip().split("\n")[1].split()[-1]


def get_version_method_long_argument(standalone):
Expand All @@ -72,10 +75,6 @@ def get_version_method_long_argument(standalone):
return output

except subprocess.CalledProcessError as e:
# --version flag not available, try other flags
# error_message = e.stderr.strip()
# if error_message:
# return error_message
pass


Expand All @@ -92,7 +91,7 @@ def get_version_method_short_argument(standalone):

def get_version_method_subcommand(standalone):

# Try -v flag
# Try subcommand
try:
command = [standalone, "version"]
output = subprocess.check_output(command, stderr=subprocess.PIPE, universal_newlines=True)
Expand All @@ -116,8 +115,9 @@ def get_version(standalone, debug=False):

meta = metadata.get(standalone, metadata.get("default"))


# Case when the standalone prints information on stderr
# e.g. bwa
# e.g. bwa, seqtk
if meta["caller"] == "stderr":
command = [standalone]
try:
Expand All @@ -127,9 +127,28 @@ def get_version(standalone, debug=False):
except subprocess.CalledProcessError as e:
print(e)
pass

elif meta['caller'] == 'version':
version = get_version_method_subcommand(standalone)
if meta["parser"]:
return meta["parser"](version)
elif version:
return version
elif meta['caller'] == '--version':
version = get_version_method_long_argument(standalone)
if meta["parser"]:
return meta["parser"](version, standalone)
elif version:
return version
elif meta['caller'] == 'standalone':
version = get_version_method_subcommand(standalone)
if meta["parser"]:
return meta["parser"](version)
elif version:
return version


#if caller is not define fallback on --version / -v / version cases
# bamtools hides the --version and then prints somewhere: "bamtools 1.0.0"
#
version = get_version_method_long_argument(standalone)
if meta["parser"]:
return meta["parser"](version, standalone)
Expand Down
9 changes: 2 additions & 7 deletions versionix/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
###########################################################################
""".. rubric:: Standalone application dedicated to Damona"""
import click
import time
import sys
import pathlib
import os


from versionix import version
Expand All @@ -35,8 +31,8 @@

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

@click.command()

@click.command()
@click.argument("standalone", required=True, type=click.STRING)
@click.version_option(version)
def main(**kwargs):
Expand All @@ -45,5 +41,4 @@ def main(**kwargs):
versionix fastqc
"""

print(get_version(kwargs["standalone"])) # frmt=kwargs["format"]))
print(get_version(kwargs["standalone"]))

0 comments on commit d0ab1e3

Please sign in to comment.