Skip to content

Commit

Permalink
Merge pull request sequana#7 from ddesvillechabrol/add_snaketools
Browse files Browse the repository at this point in the history
Add snaketools and sequana manager
  • Loading branch information
ddesvillechabrol committed Aug 4, 2021
2 parents 9dfdf96 + 550a170 commit a3723a8
Show file tree
Hide file tree
Showing 37 changed files with 3,054 additions and 312 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
- name: Install dependencies
run: |
pip install coveralls
pip install pytest pytest-cov mock
pip install coveralls pytest-cov
pip install -r requirements_dev.txt
- name: install package itself
run: |
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ lib64/
parts/
sdist/
var/
doc/_build
*.egg-info/
.installed.cfg
*.egg
Expand Down Expand Up @@ -50,4 +51,4 @@ coverage.xml
*.mo
*.pot


.vscode
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ recursive-exclude * __pycache__
recursive-exclude * *pyc
include requirements*txt
include README.rst
prune test
prune tests
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
easydev
parse
ruamel.yaml
3 changes: 3 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
mock
git+https://github.com/sequana/fastqc.git@master#egg=sequana-fastqc
8 changes: 5 additions & 3 deletions sequana_pipetools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import pkg_resources

try:
version = pkg_resources.require("sequana_pipetools")[0].version
except: #pragma: no cover
except pkg_resources.DistributionNotFound: # pragma: no cover
version = ">=0.2.0"


from easydev.logging_tools import Logging

logger = Logging("sequana_pipetools", "WARNING")
# To keep the inheritance/propagation of levels. Logging from easydev will do
# the formatting only.
import colorlog
logger = colorlog.getLogger(logger.name)


logger = colorlog.getLogger(logger.name)

from .snaketools import Module, SequanaConfig
105 changes: 54 additions & 51 deletions sequana_pipetools/completion.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#
# This file is part of Sequana software
#
# Copyright (c) 2016-2021 Sequana Development Team
# Copyright (c) 2016-2021 - 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/sequana
# documentation: http://sequana.readthedocs.io
#
# Website: https://github.com/sequana/sequana
# Documentation: http://sequana.readthedocs.io
# Contributors: https://github.com/sequana/sequana/graphs/contributors
##############################################################################
import sys
import os
import argparse
import shutil
from subprocess import check_call
import subprocess
import pkgutil
import importlib


__all__ = ['Complete']
__all__ = ["Complete"]


class Options(argparse.ArgumentParser):
Expand All @@ -26,28 +27,35 @@ def __init__(self, prog="sequana_completion"):
sequana_completion --name all
"""

super(Options, self).__init__(usage=usage, prog=prog,
super(Options, self).__init__(
usage=usage,
prog=prog,
description="""This tool creates completion script for sequana
pipelines. Each pipeline has its own in .config/sequana/pipelines that you can
source at your convenience""",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

self.add_argument("--force", action="store_true",
help="""overwrite files in sequana config pipeline directory""")
self.add_argument("--name", type=str,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)

self.add_argument(
"--force", action="store_true", help="""overwrite files in sequana config pipeline directory"""
)
self.add_argument(
"--name",
type=str,
help="""Name of a pipelines for which you wish to
create the completion file. Set to a valid name ror to create all
scripts, use --name all """)
scripts, use --name all """,
)


class Complete():
class Complete:

# For the -o default, this was an issue with compgen removing the slashes on
# directrories . Solution was found here:
# directrories . Solution was found here:
# https://stackoverflow.com/questions/12933362/getting-compgen-to-include-slashes-on-directories-when-looking-for-files
# Before using this option, a second directory could not be completed e.g.
# in --databases, only the first argument could be completed, which was
# really annoying.
# really annoying.

# KEEP '#version:' on first line as it it since it is used in
# sequana/pipeline_common.py right now
Expand Down Expand Up @@ -85,6 +93,7 @@ def _set_pipeline_name(self, name):
self._pipeline_name = name
self._init_config_file()
self._init_version()

pipeline_name = property(_get_pipeline_name, _set_pipeline_name)

def save_completion_script(self):
Expand All @@ -96,13 +105,15 @@ def save_completion_script(self):
arguments = self.get_arguments()

with open(output_filename, "w") as fout:
fout.write(self.setup.format(version=self.pipeline_version,
pipeline_name=pipeline_name,
options=" ".join(arguments)))
fout.write(
self.setup.format(
version=self.pipeline_version, pipeline_name=pipeline_name, options=" ".join(arguments)
)
)
for action in self._actions:
option_name = action.option_strings[0]
if action.choices:
option_choices = " ".join(action.choices )
option_choices = " ".join(action.choices)
fout.write(self.set_option_with_choice(option_name, option_choices))
elif option_name.endswith("-directory"):
fout.write(self.set_option_directory(option_name))
Expand All @@ -115,42 +126,38 @@ def save_completion_script(self):
def _init_config_file(self):
# do not import sequana, save time, let us use easydev
from easydev import CustomConfig

configuration = CustomConfig("sequana", verbose=False)
sequana_config_path = configuration.user_config_dir
path = sequana_config_path + os.sep + "pipelines"
if os.path.exists(path):
pass
else: #pragma: no cover
else: # pragma: no cover
os.mkdir(path)
self.config_path = path
return path

def _init_version(self):
import importlib
pname = self.pipeline_name
mod = importlib.import_module('sequana_pipelines.{}'.format(pname))
mod = importlib.import_module('sequana_pipelines.{}.main'.format(pname))
module = sys.modules['sequana_pipelines.{}'.format(self.pipeline_name)]
importlib.import_module("sequana_pipelines.{}".format(self.pipeline_name))
importlib.import_module("sequana_pipelines.{}.main".format(self.pipeline_name))
module = sys.modules["sequana_pipelines.{}".format(self.pipeline_name)]
version = module.version
self.pipeline_version = version

def get_arguments(self):
import importlib
pname = self.pipeline_name
mod = importlib.import_module('sequana_pipelines.{}'.format(pname))
mod = importlib.import_module('sequana_pipelines.{}.main'.format(pname))
module = sys.modules['sequana_pipelines.{}'.format(self.pipeline_name)]
importlib.import_module("sequana_pipelines.{}".format(self.pipeline_name))
importlib.import_module("sequana_pipelines.{}.main".format(self.pipeline_name))
module = sys.modules["sequana_pipelines.{}".format(self.pipeline_name)]

main = module.__getattribute__('main')
main = module.__getattribute__("main")
opt = main.Options()
to_exclude = ["-h", "--help"]
self._actions = [a for a in opt._actions if a.option_strings[0] not in
to_exclude]
self._actions = [a for a in opt._actions if a.option_strings[0] not in to_exclude]
arguments = [a.option_strings[0] for a in self._actions]
return arguments

def set_option_with_choice(self, option_name, option_choices):
data = f"""
data = f"""
{option_name})
local choices="{option_choices}"
COMPREPLY=( $(compgen -W "${{choices}}" -- ${{cur}}) )
Expand Down Expand Up @@ -178,9 +185,6 @@ def set_option_file(self, option_name):
return data





def main(args=None):

if args is None:
Expand All @@ -192,20 +196,20 @@ def main(args=None):
if len(args) == 1:
user_options.parse_args(["prog", "--help"])
else:
options = user_options.parse_args(args[1:])
options = user_options.parse_args(args[1:])

names = []
if options.name == "all":
import pkgutil
import sequana_pipelines
for ff, module_name, valid in pkgutil.iter_modules(sequana_pipelines.__path__):
names.append(module_name)
try:
import sequana_pipelines

names = [module_name for ff, module_name, valid in pkgutil.iter_modules(sequana_pipelines.__path__)]
except ModuleNotFoundError:
pass
else:
names = [options.name]

if options.force is False:
msg = ("This will replace files in ./config/sequana/pipelines. "
"Do you want to proceed y/n: ")
msg = "This will replace files in ./config/sequana/pipelines. " "Do you want to proceed y/n: "
choice = input(msg)
else:
choice = "y"
Expand All @@ -217,10 +221,9 @@ def main(args=None):
c.save_completion_script()
print("source ~/.config/sequana/pipelines/{}.sh".format(name))
print("\nto activate the completion")
else: #pragma: no cover
else: # pragma: no cover
print("Stopping creation of completion scripts")


if __name__ == "__main__": #pragma: no cover
if __name__ == "__main__": # pragma: no cover
main()

23 changes: 13 additions & 10 deletions sequana_pipetools/errors.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
#
# This file is part of Sequana software
#
# Copyright (c) 2016-2021 - Sequana Development Team
# Copyright (c) 2016-2021 - 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/sequana
# documentation: http://sequana.readthedocs.io
#
# Website: https://github.com/sequana/sequana
# Documentation: http://sequana.readthedocs.io
# Contributors: https://github.com/sequana/sequana/graphs/contributors
##############################################################################
import glob

from .slurm import DebugJob


class PipeError():
class PipeError:
def __init__(self, name, **kwars):
self.name = name

def status(self, slurm_directory="./"):
print(f"An error occurred during the execution. Please fix the issue and run the script again (sh {self.name}.sh)")
print(
f"An error occurred during the execution. Please fix the issue and run the script again (sh {self.name}.sh)"
)

filenames = glob.glob(slurm_directory + "slurm*")
if len(filenames): #pragma: no cover
from sequana_pipetools.slurm import DebugJob
if len(filenames): # pragma: no cover
dj = DebugJob(slurm_directory)
print(dj)


16 changes: 5 additions & 11 deletions sequana_pipetools/info.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
# -* coding: utf-8 -*-
#
# This file is part of Sequana software
#
# Copyright (c) 2016-2021 - Sequana Development Team
#
# File author(s):
# Thomas Cokelaer <thomas.cokelaer@pasteur.fr>
# Dimitri Desvillechabrol <dimitri.desvillechabrol@pasteur.fr>,
# <d.desvillechabrol@gmail.com>
# Copyright (c) 2016-2021 - 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/sequana
# documentation: http://sequana.readthedocs.io
#
# Website: https://github.com/sequana/sequana
# Documentation: http://sequana.readthedocs.io
# Contributors: https://github.com/sequana/sequana/graphs/contributors
##############################################################################
""".. rubric:: misc utilities"""

from sequana_pipetools.misc import Colors
from .misc import Colors


__all__ = ["sequana_epilog"]
Expand Down
Loading

0 comments on commit a3723a8

Please sign in to comment.