Skip to content

Commit e701c24

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: compatibility: nextstrain run: True ``` The top level `compatibility['nextstrain run']` boolean is still supported for backwards compatibility. From discussion with @victorlin in <#462 (comment)>
1 parent 172b072 commit e701c24

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ development source code and as such may not be routinely kept up to date.
1818
* `nextstrain setup <pathogen>` and `nextstrain version --pathogens` now list
1919
the available workflows for a pathogen if the pathogen lists the workflows
2020
in the top-level `nextstrain-pathogen.yaml` file.
21-
([#461](https://github.com/nextstrain/cli/pull/461))
21+
([#461](https://github.com/nextstrain/cli/pull/461), [#472](https://github.com/nextstrain/cli/pull/472))
2222

2323
* Snakemake's storage support downloaded files (stored in `.snakemake/storage/`)
2424
are now downloaded from AWS Batch builds by default.

doc/changes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ development source code and as such may not be routinely kept up to date.
2222
* `nextstrain setup <pathogen>` and `nextstrain version --pathogens` now list
2323
the available workflows for a pathogen if the pathogen lists the workflows
2424
in the top-level `nextstrain-pathogen.yaml` file.
25-
([#461](https://github.com/nextstrain/cli/pull/461))
25+
([#461](https://github.com/nextstrain/cli/pull/461), [#472](https://github.com/nextstrain/cli/pull/472))
2626

2727
* Snakemake's storage support downloaded files (stored in `.snakemake/storage/`)
2828
are now downloaded from AWS Batch builds by default.

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_directory = pathogen.workflow_path(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

@@ -481,20 +493,19 @@ def test_compatibility() -> SetupTestResult:
481493
if self.registration is None:
482494
return msg + "\n(couldn't read registration)", False
483495

496+
if compatible_workflows := self.compatible_workflows("nextstrain run"):
497+
return msg + f"\nCompatible workflows: {list(compatible_workflows.keys())}", True
498+
499+
# If no compatible workflows are listed, then check for the top level
500+
# boolean compatibility declaration
484501
try:
485502
compatibility = self.registration["compatibility"]["nextstrain run"]
486503
except (KeyError, IndexError, TypeError):
487504
if DEBUGGING:
488505
traceback.print_exc()
489506
return msg + "\n(couldn't find 'compatibility: nextstrain run: …' field)", False
490507

491-
if compatibility:
492-
if workflows := self.registered_workflows():
493-
msg += f"\nAvailable workflows: {list(workflows.keys())}"
494-
else:
495-
msg += f"\nNo workflows listed, please refer to pathogen docs."
496-
497-
return msg, bool(compatibility)
508+
return msg + "\nNo compatible workflows listed, please refer to pathogen docs.", bool(compatibility)
498509

499510
return [
500511
('downloaded',

0 commit comments

Comments
 (0)