Skip to content
Snippets Groups Projects
Commit e7c9e8fd authored by Blaise Li's avatar Blaise Li
Browse files

Changed module list generation.

parent e215bb81
No related branches found
No related tags found
No related merge requests found
__copyright__ = "Copyright (C) 2020 Blaise Li"
__licence__ = "GNU GPLv3"
__version__ = 0.5
__version__ = 0.6
from .libworkflows import (
SHELL_FUNCTIONS, cleanup_and_backup, column_converter,
ensure_relative, envmod,
ensure_relative, envmods,
file_len, feature_orientation2stranded, filter_combinator, get_chrom_sizes,
last_lines, make_id_list_getter,
partial_format,
......
......@@ -23,6 +23,7 @@ from shutil import rmtree
import warnings
from collections.abc import Mapping
from contextlib import contextmanager
from itertools import chain
from subprocess import Popen, PIPE
from re import compile as rcompile, sub
from textwrap import indent
......@@ -218,12 +219,12 @@ def run_with_modules(
return (real_cmd, generic_shell_commands)
def envmod(
def envmods(
mod_name,
module_versions,
dependency=None):
"""
Generate the string representing the module to be loaded.
Generate a list of string representing the modules to be loaded.
*mod_name* will be used as a key in the *module_versions*
dictionary in order to get the associated version number.
......@@ -233,9 +234,13 @@ def envmod(
for module *mod_name* (including *mod_name* itself) where
*dependency* will be found as a key.
"""
if isinstance(module_versions[mod_name], Mapping):
return list(chain.from_iterable(
envmods(mod_name, module_versions, dependency=dependency)
for dependency in module_versions[mod_name]))
if dependency is None:
return f"{mod_name}/{module_versions[mod_name]}"
return f"{dependency}/{module_versions[mod_name][dependency]}"
return [f"{mod_name}/{module_versions[mod_name]}"]
return [f"{dependency}/{module_versions[mod_name][dependency]}"]
def run_and_write_methods(
......@@ -265,17 +270,12 @@ def run_and_write_methods(
try:
# Only one module, whose dependencies
# are assumed to be defined as a sub-dictionary of module_versions
[main_module] = params.modules
if isinstance(module_versions[main_module], Mapping):
modules = [
envmod(main_module, module_versions, dependency=module)
for module in module_versions[main_module]]
else:
modules = [envmod(main_module, module_versions)]
[mod_name] = params.modules
modules = envmods(mod_name, module_versions)
except ValueError:
modules = [
envmod(module, module_versions)
for module in params.modules]
modules = list(chain.from_iterable(
envmods(mod_name, module_versions)
for mod_name in params.modules))
cmd = run_with_modules(
cmd,
generic_shell_commands=generic_cmd,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment