Skip to content

Commit

Permalink
-o
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Jan 31, 2022
1 parent 35d566d commit 12ae896
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
12 changes: 10 additions & 2 deletions WDL/Bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
from . import Tree, Error


def build(doc: Tree.Document, input: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
def build(
doc: Tree.Document,
input: Optional[Dict[str, Any]] = None,
meta: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
"""
Bundle the WDL document and all its imports, along with optional input JSON
"""
Expand All @@ -40,7 +44,11 @@ def build_layout(doc, ref=None):
layout["imports"] = imports
return layout

ans: Dict[str, Any] = {} if not input else {"input": input}
ans: Dict[str, Any] = {}
if meta:
ans["meta"] = meta
if input:
ans["input"] = input
ans["layout"] = build_layout(doc)

# strip common prefix from all abspaths, making bundle reproducible across machines
Expand Down
26 changes: 22 additions & 4 deletions WDL/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -1955,13 +1955,20 @@ def fill_bundle_subparser(subparsers):
)
bundle_parser.add_argument(
"wdlfile",
metavar="JSON_OR_FILE",
metavar="FILE",
help="top-level WDL to bundle",
)
bundle_parser.add_argument(
"-o",
"--output",
metavar="FILE",
default="-",
help="write bundle to file instead of standard output",
)
bundle_parser.add_argument(
"--input",
"-i",
metavar="FILE",
metavar="JSON_OR_FILE",
help="input JSON to include as defaults",
)
bundle_parser.add_argument(
Expand All @@ -1974,6 +1981,7 @@ def fill_bundle_subparser(subparsers):

def bundle(
wdlfile,
output="-",
input=None,
compress=False,
check_quant=True,
Expand Down Expand Up @@ -2009,10 +2017,20 @@ def bundle(
else:
input = sync_await(read_source(Bundle.READ_BUNDLE_INPUT, [], None))

meta = None
miniwdl_version = pkg_version()
if miniwdl_version:
meta = {"miniwdl": {"version": "v" + miniwdl_version}}

# build bundle
bundle = Bundle.build(doc, input=input)
bundle = Bundle.build(doc, input=input, meta=meta)
bundle = Bundle.encode(bundle, compress=compress)
print(bundle)

if not output or output == "-":
print(bundle)
else:
with open(output, "w") as outfile:
print(bundle, file=outfile)


def pkg_version(pkg="miniwdl"):
Expand Down
2 changes: 1 addition & 1 deletion tests/bundle.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ plan tests 11

$miniwdl bundle wdl/wf/outer.wdl --input ' {"w.who": "Alice"}' > my_bundle
is "$?" "0" "build bundle"
$miniwdl bundle wdl/wf/outer.wdl --input ' {"w.who": "Alice"}' --compress > compressed_bundle
$miniwdl bundle wdl/wf/outer.wdl --input ' {"w.who": "Alice"}' --compress -o compressed_bundle
is "$?" "0" "compress bundle"
$miniwdl check my_bundle
is "$?" "0" "check bundle"
Expand Down

0 comments on commit 12ae896

Please sign in to comment.