-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
499 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import base64 | ||
import os.path | ||
from io import BytesIO | ||
from pathlib import Path | ||
from typing import List, Tuple, Dict | ||
from urllib.parse import urlparse | ||
|
||
import requests | ||
import ruamel.yaml as yaml | ||
from requests.compat import urljoin | ||
|
||
|
||
class CWLGitResolver: | ||
"""CWLGitResolver fetches the required cwl files from a remote git url""" | ||
|
||
def __init__(self, local_directory: Path): | ||
self._local_root_directory = local_directory | ||
self._local_root_directory.mkdir(exist_ok=True) | ||
|
||
def resolve(self, github_url: str) -> List[str]: | ||
github_path = urlparse(github_url).path.split('/') | ||
git_owner = github_path[1] | ||
git_repo = github_path[2] | ||
git_branch = github_path[4] | ||
git_path = '/'.join(github_path[5:]) | ||
workflow_files = set() | ||
root_path = git_path[:git_path.rfind('/')] | ||
search_stack = {git_path} | ||
while len(search_stack) > 0: | ||
current_path = search_stack.pop() | ||
if current_path not in workflow_files: | ||
workflow_filename, workflow = self._resolve_file(current_path, git_owner, git_repo, git_branch) | ||
workflow_files.add(workflow_filename) | ||
if 'steps' in workflow: | ||
for step in workflow['steps']: | ||
if isinstance(workflow['steps'][step]['run'], str): | ||
file = '/'.join([root_path, workflow['steps'][step]['run']]) | ||
if file not in workflow_files and file not in search_stack: | ||
search_stack.add(file) | ||
return list(workflow_files) | ||
|
||
def _resolve_file(self, path: str, git_owner: str, git_repo: str, git_branch: str) -> Tuple[str, Dict]: | ||
url = urljoin(f"https://api.github.com/repos/{git_owner}/{git_repo}/contents/", | ||
f"{path}?ref={git_branch}") | ||
github_response = requests.get(url) | ||
if github_response.status_code != 200: | ||
raise RuntimeError( | ||
f"Error on github api call for: {url}: {github_response.status_code}: {github_response.text}") | ||
github_response = github_response.json() | ||
workflow = yaml.load(BytesIO(base64.b64decode(github_response['content'])), yaml.Loader) | ||
workflow_filename = os.path.join(str(self._local_root_directory), git_owner, git_repo, path) | ||
Path(os.path.dirname(workflow_filename)).mkdir(exist_ok=True, parents=True) | ||
with open(workflow_filename, 'w') as f: | ||
yaml.dump(workflow, f) | ||
return workflow_filename, workflow |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Github Import" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"tool 'threesteps' registered\n", | ||
"tool 'head' registered\n", | ||
"tool 'grep' registered\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"% githubImport https://github.com/giannisdoukas/CWLJNIKernel/blob/dev/tests/cwl/3stepWorkflow.cwl" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Add data in memory" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"application/json": { | ||
"outputfile": { | ||
"basename": "grepoutput.out", | ||
"checksum": "sha1$b0358a00b0d42af80bef65e80097e39ea0aa2790", | ||
"class": "File", | ||
"http://commonwl.org/cwltool#generation": 0, | ||
"id": "outputfile", | ||
"location": "file:///private/tmp/CWLKERNEL_DATA/21a791a2-b2a2-4d75-abfb-20cd5ea2b35b/runtime_data/grepoutput.out", | ||
"nameext": ".out", | ||
"nameroot": "grepoutput", | ||
"size": 70 | ||
}, | ||
"outputfile2": { | ||
"basename": "grepoutput.out", | ||
"checksum": "sha1$66285c44ede6dbac842fda1bf455b339648249f3", | ||
"class": "File", | ||
"http://commonwl.org/cwltool#generation": 0, | ||
"id": "outputfile2", | ||
"location": "file:///private/tmp/CWLKERNEL_DATA/21a791a2-b2a2-4d75-abfb-20cd5ea2b35b/runtime_data/grepoutput.out_2", | ||
"nameext": ".out", | ||
"nameroot": "grepoutput", | ||
"size": 96 | ||
} | ||
}, | ||
"text/plain": [ | ||
"{\"outputfile\": {\"location\": \"file:///private/tmp/CWLKERNEL_DATA/21a791a2-b2a2-4d75-abfb-20cd5ea2b35b/runtime_data/grepoutput.out\", \"basename\": \"grepoutput.out\", \"nameroot\": \"grepoutput\", \"nameext\": \".out\", \"class\": \"File\", \"checksum\": \"sha1$b0358a00b0d42af80bef65e80097e39ea0aa2790\", \"size\": 70, \"http://commonwl.org/cwltool#generation\": 0, \"id\": \"outputfile\"}, \"outputfile2\": {\"location\": \"file:///private/tmp/CWLKERNEL_DATA/21a791a2-b2a2-4d75-abfb-20cd5ea2b35b/runtime_data/grepoutput.out_2\", \"basename\": \"grepoutput.out\", \"nameroot\": \"grepoutput\", \"nameext\": \".out\", \"class\": \"File\", \"checksum\": \"sha1$66285c44ede6dbac842fda1bf455b339648249f3\", \"size\": 96, \"http://commonwl.org/cwltool#generation\": 0, \"id\": \"outputfile2\"}}" | ||
] | ||
}, | ||
"metadata": { | ||
"application/json": { | ||
"expanded": false, | ||
"root": "root" | ||
} | ||
}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"% execute threesteps\n", | ||
"inputfile:\n", | ||
" class: File\n", | ||
" location: /Users/dks/Workspaces/CWLKernel/tests/cwl/3stepWorkflow.cwl\n", | ||
"query: id" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Common Workflow Languages", | ||
"language": "cwl", | ||
"name": "cwlkernel" | ||
}, | ||
"language_info": { | ||
"file_extension": ".cwl", | ||
"mimetype": "text/x-cwl", | ||
"name": "yaml" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ traitlets==4.3.3 | |
uritools==3.0.0 | ||
PyYAML==5.3.1 | ||
pandas==1.0.4 | ||
notebook==6.0.3 | ||
notebook==6.0.3 | ||
requests==2.23.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/grepoutput.out | ||
/grepoutput.out_2 | ||
/*.txt | ||
/*.tar | ||
/*.out |
Oops, something went wrong.