Skip to content

Commit

Permalink
WIP: Salad a Schema!
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Dec 2, 2019
1 parent c79b4ec commit b17b984
Show file tree
Hide file tree
Showing 132 changed files with 12,936 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ docs/_build

.venv

java/target
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ flake8: ## check style using flake8 for current Python (faster than lint)
$(IN_VENV) flake8 --max-complexity 11 $(SOURCE_DIR) $(TEST_DIR)

lint: ## check style using tox and flake8 for Python 2 and Python 3
$(IN_VENV) tox -e py27-lint && tox -e py34-lint
$(IN_VENV) tox -e py27-lint && tox -e py35-lint

lint-readme: ## check README formatting for PyPI
$(IN_VENV) python setup.py check -r -s
Expand Down
31 changes: 31 additions & 0 deletions build_schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -x
set -e

PROJECT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"


# Requires schema-salad-doc that recognizes --brandstyle and --brandinverse
for schema in "v19.09";
do
cd schema/"$schema";
python_schema_name=${schema//./_}
schema-salad-tool --codegen python workflow.yml > "${PROJECT_DIRECTORY}/gxformat2/schema/${python_schema_name}.py"

out="../${schema}.html"
schema-salad-doc \
--brandstyle '<link rel="stylesheet" href="https://jamestaylor.org/galaxy-bootstrap/galaxy_bootstrap.css">' \
--brandinverse \
--brand '<img src="icon.png" />' \
--only "https://galaxyproject.org/gxformat2/${schema}#WorkflowDoc" \
--only "https://galaxyproject.org/gxformat2/${schema}#GalaxyWorkflow" \
workflow.yml > "$out"

java_package="${PROJECT_DIRECTORY}/java"
schema-salad-tool --codegen java --codegen-target "$java_package" workflow.yml
cd "$java_package"
mvn test
mvn javadoc:javadoc
cd "${PROJECT_DIRECTORY}"
done
3 changes: 3 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Optional dependencies
schema-salad

# For testing
tox
nose
Expand Down
39 changes: 31 additions & 8 deletions gxformat2/lint.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys

from gxformat2._yaml import ordered_load
Expand All @@ -8,36 +9,60 @@
EXIT_CODE_FILE_PARSE_FAILED = 3


def lint_ga(workflow_dict):
def lint_ga(workflow_dict, path=None):
if workflow_dict.get("format-version") != "0.1":
return EXIT_CODE_FORMAT_ERROR
if workflow_dict.get("a_galaxy_workflow") != "true":
return EXIT_CODE_FORMAT_ERROR

native_steps = workflow_dict.get("steps")
if not native_steps or not isinstance(native_steps, dict):
return EXIT_CODE_FORMAT_ERROR

found_outputs = False
found_output_without_label = False

for step in native_steps.values():
for order_index_str, step in native_steps.items():
if not order_index_str.isdigit():
return EXIT_CODE_FORMAT_ERROR

for workflow_output in step.get("workflow_outputs", []):
found_outputs = True

if not workflow_output.get("label"):
found_output_without_label = True

step_type = step.get("type")
if step_type == "subworkflow":
subworkflow = step.get("subworkflow")
if subworkflow and not isinstance(subworkflow, dict):
return EXIT_CODE_FORMAT_ERROR
lint_subworkflow_ret = lint_ga(subworkflow)
if lint_subworkflow_ret != 0:
return lint_subworkflow_ret

if not found_outputs:
return EXIT_CODE_LINT_FAILED

if found_output_without_label:
return EXIT_CODE_LINT_FAILED

return EXIT_CODE_SUCCESS


def lint_format2(workflow_dict):
def lint_format2(workflow_dict, path=None):
from gxformat2.schema.v19_09 import load_document
from schema_salad.exceptions import SchemaSaladException
try:
load_document("file://" + os.path.normpath(path))
except SchemaSaladException as e:
print(e)
return EXIT_CODE_FORMAT_ERROR

# Lint for outputs...
if not workflow_dict.get("outputs", None):
return EXIT_CODE_LINT_FAILED

return EXIT_CODE_SUCCESS


Expand All @@ -49,10 +74,8 @@ def main(argv):
except Exception:
return EXIT_CODE_FILE_PARSE_FAILED
workflow_class = workflow_dict.get("class")
if workflow_class == "GalaxyWorkflow":
exit_code = lint_format2(workflow_dict)
else:
exit_code = lint_ga(workflow_dict)
lint_func = lint_format2 if workflow_class == "GalaxyWorkflow" else lint_ga
exit_code = lint_func(workflow_dict, path=path)
return exit_code


Expand Down
Empty file added gxformat2/schema/__init__.py
Empty file.
Loading

0 comments on commit b17b984

Please sign in to comment.