Skip to content

Commit f04761d

Browse files
committed
pathogens: use top level workflows key
List workflows under a top level `workflows` key in the `nextstrain-pathogen.yaml` file where each workflow has it's own `compatibility` key: ```yaml workflows: ingest: compatibility: nextstrain run: True phylogenetic/all-clades: compatibility: nextstrain run: True snakefile: phylogenetic/Snakefile configfile: phylogenetic/defaults/mpxv/config.yaml ``` The top level `compatibility['nextstrain run']` boolean is still supported for backwards compatibility. From discussion with @victorlin in <#462 (comment)>
1 parent 919ce28 commit f04761d

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

nextstrain/cli/command/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def run(opts):
228228
# Resolve pathogen and workflow names to a local workflow directory.
229229
pathogen = PathogenVersion(opts.pathogen)
230230

231-
if opts.workflow not in pathogen.registered_workflows():
231+
if opts.workflow not in pathogen.compatible_workflows("nextstrain run"):
232232
print(f"The {opts.workflow!r} workflow is not registered as a compatible workflow, but trying to run anyways.")
233233

234234
workflow_files = pathogen.workflow_files(opts.workflow)

nextstrain/cli/command/version.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def run(opts):
7272
if opts.verbose:
7373
print(" " + str(version.path))
7474

75-
if registered_workflows := version.registered_workflows():
76-
print(" " + "Available workflows:")
77-
for workflow in registered_workflows:
75+
if compatible_workflows := version.compatible_workflows("nextstrain run"):
76+
print(" " + "`nextstrain run` compatible workflows:")
77+
for workflow in compatible_workflows:
7878
print(" " + workflow)
7979
else:
8080
print(" " + "No workflows listed, please refer to pathogen docs.")

nextstrain/cli/pathogens.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,32 @@ def __init__(self, name_version_url: str, new_setup: bool = False):
308308
def registered_workflows(self) -> Dict[str, Dict]:
309309
"""
310310
Parses :attr:`.registration` to return a dict of registered
311-
compatible workflows, where the keys are workflow names.
311+
workflows, where the keys are workflow names.
312312
"""
313313
if self.registration is None:
314314
debug("pathogen does not have a registration")
315315
return {}
316316

317-
workflows = self.registration.get("compatibility", {}).get("nextstrain run")
317+
workflows = self.registration.get("workflows")
318318
if not isinstance(workflows, dict):
319-
debug(f"pathogen registration.compatibility['nextstrain runs'] is not a dict (got a {type(workflows).__name__})")
319+
debug(f"pathogen registration.workflows is not a dict (got a {type(workflows).__name__})")
320320
return {}
321321

322322
return workflows
323323

324324

325+
def compatible_workflows(self, feature: str) -> Dict[str, Dict]:
326+
"""
327+
Parses registered workflows to return a subset of workflows that are
328+
compatible with the provided *feature*.
329+
"""
330+
return {
331+
workflow: workflow_config
332+
for workflow, workflow_config in self.registered_workflows().items()
333+
if workflow_config.get("compatibility", {}).get(feature, False)
334+
}
335+
336+
325337
def workflow_path(self, workflow: str) -> Path:
326338
return self.path / workflow
327339

@@ -501,20 +513,19 @@ def test_compatibility() -> SetupTestResult:
501513
if self.registration is None:
502514
return msg + "\n(couldn't read registration)", False
503515

516+
if compatible_workflows := self.compatible_workflows("nextstrain run"):
517+
return msg + f"\nCompatible workflows: {list(compatible_workflows.keys())}", True
518+
519+
# If no compatible workflows are listed, then check for the top level
520+
# boolean compatibility declaration
504521
try:
505522
compatibility = self.registration["compatibility"]["nextstrain run"]
506523
except (KeyError, IndexError, TypeError):
507524
if DEBUGGING:
508525
traceback.print_exc()
509526
return msg + "\n(couldn't find 'compatibility: nextstrain run: …' field)", False
510527

511-
if compatibility:
512-
if workflows := self.registered_workflows():
513-
msg += f"\nAvailable workflows: {list(workflows.keys())}"
514-
else:
515-
msg += f"\nNo workflows listed, please refer to pathogen docs."
516-
517-
return msg, bool(compatibility)
528+
return msg + "\nNo compatible workflows listed, please refer to pathogen docs.", bool(compatibility)
518529

519530
return [
520531
('downloaded',

0 commit comments

Comments
 (0)