Skip to content

Commit

Permalink
Merge pull request #1314 from lldelisle/add_creator_dockstore
Browse files Browse the repository at this point in the history
Add creator dockstore
  • Loading branch information
mvdbeek committed Nov 3, 2022
2 parents 50cfe73 + cf0cf2a commit 337f0cc
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
46 changes: 43 additions & 3 deletions planemo/workflow_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Union,
)

import requests
import yaml
from bioblend import toolshed
from bioblend.toolshed import ToolShedInstance
Expand Down Expand Up @@ -61,21 +62,60 @@ class WorkflowLintContext(LintContext):

def generate_dockstore_yaml(directory: str, publish: bool = True) -> str:
workflows = []
for workflow_path in find_workflow_descriptions(directory):
all_workflow_paths = list(find_workflow_descriptions(directory))
for workflow_path in all_workflow_paths:
test_parameter_path = f"{workflow_path.rsplit('.', 1)[0]}-tests.yml"
workflow_entry: Dict[str, Any] = {
# TODO: support CWL
"name": "main" if len(all_workflow_paths) == 1 else os.path.basename(workflow_path).split(".ga")[0],
"subclass": "Galaxy",
"publish": publish,
"name": "main",
"primaryDescriptorPath": f"/{os.path.relpath(workflow_path, directory)}",
}
if os.path.exists(test_parameter_path):
workflow_entry["testParameterFiles"] = [f"/{os.path.relpath(test_parameter_path, directory)}"]

with open(workflow_path) as f:
workflow_dict = ordered_load(f)

# add author
if len(workflow_dict.get("creator", [])) > 0:
creators = workflow_dict["creator"]
authors = []
for creator in creators:
author = {}
# Put name first
if "name" in creator:
author["name"] = creator["name"]
for field, value in creator.items():
if field in ["class", "name"]:
continue
if field == "identifier":
# Check if it is an orcid:
orcid = re.findall(r"(?:\d{4}-){3}\d{3}", value)
if len(orcid) > 0:
# Check the orcid is valid
if (
requests.get(
f"https://orcid.org/{orcid[0]}", headers={"Accept": "application/xml"}
).status_code
== 200
):
author["orcid"] = orcid[0]
else:
# If it is not put as identifier
author["identifier"] = value
else:
author["identifier"] = value
else:
author[field] = value
authors.append(author)
workflow_entry["authors"] = authors

workflows.append(workflow_entry)
# Force version to the top of file but serializing rest of config separately
contents = "version: %s\n" % DOCKSTORE_REGISTRY_CONF_VERSION
contents += yaml.dump({"workflows": workflows})
contents += yaml.dump({"workflows": workflows}, sort_keys=False)
return contents


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"a_galaxy_workflow": "true",
"annotation": "",
"creator": [
{
"class": "Person",
"identifier": "https://orcid.org/0000-0002-1964-4960",
"name": "Lucille Delisle"
}
],
"format-version": "0.1",
"name": "Workflow with unexisting tool",
"steps": {
Expand Down
13 changes: 13 additions & 0 deletions tests/test_cmd_dockstore_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,16 @@ def run_dockstore_init(self, publish: Optional[bool] = None):
assert dockstore_config["workflows"][0]["publish"] == expect_published
workflow_lint_cmd = ["workflow_lint", "--fail_level", "error", f]
self._check_exit_code(workflow_lint_cmd)

def run_dockstore_init_with_creator(self):
with self._isolate_with_test_data("wf_repos/autoupdate_tests/workflow_with_unexisting_version_of_tool.ga") as f:
init_cmd = ["dockstore_init", f]
self._check_exit_code(init_cmd)
with open(".dockstore.yml") as fh:
dockstore_config = yaml.safe_load(fh)
assert str(dockstore_config["version"]) == "1.2"
assert "workflows" in dockstore_config
assert len(dockstore_config["workflows"]) == 1
assert "authors" in dockstore_config["workflows"]
workflow_lint_cmd = ["workflow_lint", "--skip", "tool_ids", "--fail_level", "error", f]
self._check_exit_code(workflow_lint_cmd)

0 comments on commit 337f0cc

Please sign in to comment.