Skip to content

Commit

Permalink
fix issue with having paths in github repos
Browse files Browse the repository at this point in the history
  • Loading branch information
giannisdoukas committed Jul 20, 2020
1 parent 4c59d1e commit 9dcd53f
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 9 deletions.
12 changes: 10 additions & 2 deletions cwlkernel/CoreExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from cwltool.process import add_sizes
from cwltool.provenance import ResearchObject
from cwltool.stdfsaccess import StdFsAccess
from cwltool.utils import CWLObjectType, visit_class
from cwltool.utils import CWLObjectType, visit_class, DEFAULT_TMP_PREFIX
from ruamel import yaml

from .IOManager import IOFileManager
Expand All @@ -42,9 +42,17 @@ def __init__(self, root_directory: str,
)
self.runtime_context.outdir = root_directory
self.runtime_context.basedir = root_directory
self.runtime_context.default_stdin = DEVNULL
self.runtime_context.default_stdout = DEVNULL
self.runtime_context.default_stderr = DEVNULL
# If on MacOS platform, TMPDIR must be set to be under one of the
# shared volumes in Docker for Mac
# More info: https://dockstore.org/docs/faq
if sys.platform == "darwin":
default_mac_path = "/private/tmp/docker_tmp"
if self.runtime_context.tmp_outdir_prefix == DEFAULT_TMP_PREFIX:
self.runtime_context.tmp_outdir_prefix = default_mac_path
if self.runtime_context.tmpdir_prefix == DEFAULT_TMP_PREFIX:
self.runtime_context.tmpdir_prefix = default_mac_path


class ProvenanceFactory(JupyterFactory):
Expand Down
1 change: 1 addition & 0 deletions cwlkernel/IOManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def read(self, relative_path: str) -> bytes:

def write(self, relative_path: str, binary_data: bytes, metadata=None) -> str:
real_path = os.path.realpath(os.path.join(self.ROOT_DIRECTORY, relative_path))
Path(os.path.dirname(real_path)).mkdir(exist_ok=True, parents=True)
with open(real_path, 'wb') as f:
self._files_registry[real_path] = metadata if metadata is not None else {}
f.write(binary_data)
Expand Down
9 changes: 3 additions & 6 deletions cwlkernel/cwlrepository/cwlrepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ def validate(self, tool: WorkflowComponent):
if 'id' not in output:
raise MissingIdError(f'Missing id for outputs: {output}')

def register_tool(self, tool: WorkflowComponent) -> None:
def register_tool(self, tool: WorkflowComponent, relative_directory: Optional[Path] = None) -> None:
self.validate(tool)
if tool.id in self._registry:
raise KeyError(f'Dublicate key error: {tool.id}')
path = Path(self._file_repository.write(f'{tool.id}.cwl', tool.to_yaml().encode()))
relative_directory = relative_directory.as_posix() if relative_directory is not None else f'{tool.id}.cwl'
path = Path(self._file_repository.write(relative_directory, tool.to_yaml().encode()))
self._registry[tool.id] = (deepcopy(tool), path)

# def register_tools(self, *args):
# for tool in args:
# self.register_tool(tool)

def get_by_id(self, tool_id: str) -> Optional[WorkflowComponent]:
comp = self._registry.get(tool_id, None)
return comp[0] if comp is not None else None
Expand Down
3 changes: 2 additions & 1 deletion cwlkernel/kernel_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ def github_import(kernel: CWLKernel, url: str):
file_data = f.read()
cwl_component = cwl_factory.get_workflow_component(file_data)
cwl_component._id = os.path.splitext(os.path.basename(cwl_file))[0]
kernel.workflow_repository.register_tool(cwl_component)
relative_dir = Path(os.path.relpath(cwl_file, kernel._github_resolver._local_root_directory.as_posix()))
kernel.workflow_repository.register_tool(cwl_component, relative_dir)
kernel.send_response(kernel.iopub_socket, 'stream',
{'name': 'stdout', 'text': f"tool '{cwl_component.id}' registered\n"})

Expand Down

0 comments on commit 9dcd53f

Please sign in to comment.