Skip to content

Commit

Permalink
implement workunit export-definition
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Jan 22, 2025
1 parent acf91c3 commit 9c76e06
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Versioning currently follows `X.Y.Z` where

## \[Unreleased\]

### Added

- `bfabric-cli workunit export-definition` to export `workunit_definition.yml` files

### Fixed

- `Workunit.parameters` and `Workunit.resources` are optional
Expand Down
2 changes: 2 additions & 0 deletions src/bfabric_scripts/cli/cli_workunit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import cyclopts

from bfabric_scripts.cli.workunit.export_definition import export_definition
from bfabric_scripts.cli.workunit.not_available import list_not_available_proteomics_workunits

app = cyclopts.App()
app.command(list_not_available_proteomics_workunits, name="not-available")
app.command(export_definition, name="export-definition")
21 changes: 21 additions & 0 deletions src/bfabric_scripts/cli/workunit/export_definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pathlib import Path

import yaml

from bfabric import Bfabric
from bfabric.experimental.workunit_definition import WorkunitDefinition
from bfabric_scripts.cli.base import use_client


@use_client
def export_definition(workunit_id: int, target_path: Path | None = None, *, client: Bfabric) -> None:
"""Exports a workunit_definition.yml file for the specified workunit.
:param workunit_id: the workunit ID
:param target_path: the target path for the workunit_definition.yml file (default: workunit_definition.yml)
"""
target_path = target_path if target_path is not None else Path("workunit_definition.yml")
workunit_definition = WorkunitDefinition.from_ref(workunit_id, client=client)
target_path.parent.mkdir(parents=True, exist_ok=True)
data = workunit_definition.model_dump(mode="json")
target_path.write_text(yaml.safe_dump(data))

0 comments on commit 9c76e06

Please sign in to comment.