Skip to content

Commit a8bfe51

Browse files
authored
Merge pull request #1 from common-workflow-language/restructure
Restructure
2 parents 5022928 + 21f6d16 commit a8bfe51

File tree

13 files changed

+560
-356
lines changed

13 files changed

+560
-356
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.venv/
2+
*.egg-info/
3+
build/
4+
dist/

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: python
2+
matrix:
3+
include:
4+
- env: TARGET=py3
5+
- env: TARGET=pep8
6+
- env: TARGET=mypy
7+
allow_failures:
8+
- env: TARGET=pep8
9+
- env: TARGET=mypy
10+
sudo: required
11+
services:
12+
- docker
13+
install:
14+
- true
15+
script:
16+
- docker build . -f .travis/${TARGET}.docker

.travis/mypy.docker

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM kernsuite/base:5
2+
RUN docker-apt-install python3-pip
3+
RUN pip3 install mypy
4+
ADD . /code
5+
WORKDIR /code
6+
RUN mypy --ignore-missing-imports cwl_utils

.travis/pep8.docker

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM kernsuite/base:5
2+
RUN docker-apt-install python3-pip
3+
RUN pip3 install pycodestyle
4+
ADD . /code
5+
WORKDIR /code
6+
RUN pycodestyle cwl_utils

.travis/py3.docker

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM kernsuite/base:5
2+
RUN docker-apt-install python3-pip
3+
ADD . /code
4+
WORKDIR /code
5+
RUN pip3 install .

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ source venv3.6/bin/activate
77
pip install cwl-utils/docker_cache_pull/requirements.txt
88
python docker_cache_pull/docker-extract.py path_to_my_workflow.cwl
99
```
10+
11+
to regenerate install `schema_salad` package and run:
12+
13+
```
14+
schema-salad-tool --codegen python \
15+
https://raw.githubusercontent.com/common-workflow-language/common-workflow-language/master/v1.0/CommonWorkflowLanguage.yml
16+
```

cwl_utils/__init__.py

Whitespace-only changes.

docker_cache_pull/cite-extract.py renamed to cwl_utils/cite-extract.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/usr/bin/env python3
22
import sys
3-
import CommonWorkflowLanguage as cwl
3+
import cwl_utils.parser_v1_0 as cwl
4+
45

56
def main():
67
top = cwl.load_document(sys.argv[1])
78
traverse(top)
89

10+
911
def extract_software_packages(process: cwl.Process):
1012
for req in extract_software_reqs(process):
1113
print(process.id)
1214
process_software_requirement(req)
1315

16+
1417
def extract_software_reqs(process: cwl.Process):
1518
if process.requirements:
1619
for req in process.requirements:
@@ -22,22 +25,25 @@ def extract_software_reqs(process: cwl.Process):
2225
yield cwl.load_field(req, cwl.SoftwareRequirementLoader,
2326
process.id, process.loadingOptions)
2427

25-
def process_software_requirement(req: cwl.SoftwarePackage):
28+
29+
def process_software_requirement(req: cwl.SoftwareRequirement):
2630
for package in req.packages:
2731
print("Package: {}, version: {}, specs: {}".format(
28-
package.package, package.version, package.specs))
32+
package.package, package.version, package.specs))
2933

3034

3135
def traverse(process: cwl.Process):
3236
extract_software_packages(process)
3337
if isinstance(process, cwl.Workflow):
3438
traverse_workflow(process)
3539

40+
3641
def get_process_from_step(step: cwl.WorkflowStep):
3742
if isinstance(step.run, str):
3843
return cwl.load_document(step.run)
3944
return step.run
4045

46+
4147
def traverse_workflow(workflow: cwl.Workflow):
4248
for step in workflow.steps:
4349
extract_software_packages(step)

docker_cache_pull/docker-extract.py renamed to cwl_utils/docker-extract.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env python3
22
import sys
33
import os
4-
import CommonWorkflowLanguage as cwl
4+
import cwl_utils.parser_v1_0 as cwl
55
import subprocess
66
import argparse
77

88

99
def parse_args():
10-
parser = argparse.ArgumentParser(description='Tool to save docker images from a cwl workflow \n '
11-
'and generate udocker loading commands.')
10+
parser = argparse.ArgumentParser(
11+
description='Tool to save docker images from a cwl workflow \n '
12+
'and generate udocker loading commands.')
1213
parser.add_argument('dir', help='Directory in which to save images')
1314
parser.add_argument('input', help='Input CWL workflow')
1415
return parser.parse_args()
@@ -36,8 +37,17 @@ def load_docker_image(image_name):
3637

3738

3839
def save_docker_image(req, image_name, image_dir):
39-
cmd = ['docker', 'save', '-o', os.path.join(image_dir, image_name), req]
40-
subprocess.run(" ".join(cmd), shell=True, check=True)
40+
cmd_pull = ['docker', 'pull', req]
41+
try:
42+
subprocess.run(cmd_pull, check=True, stdout=subprocess.PIPE,
43+
stderr=subprocess.STDOUT)
44+
except subprocess.CalledProcessError as err:
45+
if err.output:
46+
raise subprocess.SubprocessError(err.output)
47+
raise err
48+
cmd_save = ['docker', 'save', '-o', os.path.join(image_dir, image_name),
49+
req]
50+
subprocess.run(cmd_save, check=True)
4151

4252

4353
def extract_docker_requirements(process: cwl.Process):
@@ -59,12 +69,6 @@ def extract_docker_reqs(process: cwl.Process):
5969
process.id, process.loadingOptions)
6070

6171

62-
def process_docker_requirement(req: cwl.SoftwarePackage):
63-
if ':' not in req.dockerPull:
64-
req.dockerPull += ':latest'
65-
return req.dockerPull
66-
67-
6872
def traverse(process: cwl.Process):
6973
yield from extract_docker_requirements(process)
7074
if isinstance(process, cwl.Workflow):

cwl_utils/parser/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)