Skip to content

Commit

Permalink
Merge pull request #55 from PMCC-BioinformaticsCore/apply-prejanis-hook
Browse files Browse the repository at this point in the history
Apply prejanis hook
  • Loading branch information
junyk authored Apr 30, 2021
2 parents 571601f + b51402a commit d3df241
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions janis_assistant/containers/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import abstractmethod, ABC
from enum import Enum
from typing import Dict
from typing import Dict, Optional


class ContainerType(Enum):
Expand Down Expand Up @@ -41,7 +41,7 @@ def get_container_type():

@staticmethod
@abstractmethod
def test_available_by_getting_version() -> str:
def test_available_by_getting_version(command: Optional[str] = None) -> str:
"""
Test if the container environment is available, raise the ContainerEnvNotFound if not.
:return:
Expand Down
4 changes: 2 additions & 2 deletions janis_assistant/containers/docker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import subprocess
from typing import Dict
from typing import Dict, Optional

from janis_core import Logger

Expand Down Expand Up @@ -31,7 +31,7 @@ def get_container_type():
return ContainerType.docker

@staticmethod
def test_available_by_getting_version() -> str:
def test_available_by_getting_version(command: Optional[str] = None) -> str:
try:
return subprocess.check_output(["docker", "-v"]).decode()
except subprocess.CalledProcessError as e:
Expand Down
18 changes: 14 additions & 4 deletions janis_assistant/containers/singularity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import subprocess

from typing import Dict
from typing import Dict, Optional

from janis_core import Logger

Expand Down Expand Up @@ -41,7 +41,7 @@ def get_build_instructions_for(containerlocation: str, docker: str):
return ["singularity", "pull", containerlocation, "docker://" + docker]

@staticmethod
def test_available_by_getting_version() -> str:
def test_available_by_getting_version(command: Optional[str] = None) -> str:
try:
version = subprocess.check_output(["singularity", "--version"]).decode()
import re
Expand All @@ -58,8 +58,18 @@ def test_available_by_getting_version() -> str:
)

return version
except subprocess.CalledProcessError as e:
raise Container.ContainerEnvNotFound("singularity", e)
# except subprocess.CalledProcessError as e:
# raise Container.ContainerEnvNotFound("singularity", e)
except Exception as e:

if command is not None:
try:
Logger.info("Trying to load singularity")
subprocess.run(command, shell=True)
except Exception as e:
raise Container.ContainerEnvNotFound("singularity", e)
else:
raise Container.ContainerEnvNotFound("singularity", e)

def start_container(self):

Expand Down
1 change: 1 addition & 0 deletions janis_assistant/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import sys
import time
import subprocess
from datetime import datetime
from inspect import isclass
from textwrap import dedent
Expand Down
7 changes: 6 additions & 1 deletion janis_assistant/management/workflowmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ def start_or_submit(self, run_in_background, watch=False):

jc = metadb.prepared_job
PreparedJob._instance = jc

metadb.containertype = jc._container.__name__
metadb.containerversion = jc._container.test_available_by_getting_version()
metadb.containerversion = jc._container.test_available_by_getting_version(jc.template.template.setup_container_command())

self.database.submission_metadata.save_changes()

Expand All @@ -310,6 +311,10 @@ def start_or_submit(self, run_in_background, watch=False):
"--foreground",
self.execution_dir,
]

if jc.template.template.prejanis_hook() is not None:
command = [f"{jc.template.template.prejanis_hook()};"] + command

scriptdir = self.get_path_for_component(self.WorkflowManagerPath.configuration)
logdir = self.get_path_for_component(self.WorkflowManagerPath.logs)

Expand Down
4 changes: 4 additions & 0 deletions janis_assistant/templates/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import os
from abc import ABC, abstractmethod
from datetime import datetime
from typing import Type, Optional, List, Dict
Expand Down Expand Up @@ -223,6 +224,9 @@ def prepare_run_test_command(self, test_command: List[str]) -> Optional[List]:
"""
return test_command

def setup_container_command(self):
return None


class SingularityEnvironmentTemplate(EnvironmentTemplate, ABC):
def __init__(
Expand Down
3 changes: 3 additions & 0 deletions janis_assistant/templates/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,6 @@ def submit_detatched_resume(
logsdir=logsdir,
**kwargs,
)

def setup_container_command(self):
return self.singularity_load_instructions

0 comments on commit d3df241

Please sign in to comment.