generated from childmindresearch/template-python-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
807 additions
and
343 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Command line interface for styx.""" | ||
|
||
import argparse | ||
import json | ||
import pathlib as pl | ||
|
||
from styx.boutiques import model | ||
from styx.compiler.core import compile_descriptor | ||
from styx.compiler.settings import CompilerSettings | ||
|
||
|
||
def _cli() -> None: | ||
"""Command line interface for styx.""" | ||
parser = argparse.ArgumentParser( | ||
prog="styx", | ||
description="Styx is a command line tool Python wrapper code generator.", | ||
) | ||
|
||
parser.add_argument( | ||
"input", | ||
type=pl.Path, | ||
help="Path to the input JSON Boutiques descriptor.", | ||
) | ||
|
||
parser.add_argument( | ||
"-o", | ||
"--output", | ||
type=pl.Path, | ||
help="Path to the output Python file.", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
path_descriptor: pl.Path = args.input | ||
path_output: pl.Path | None = args.output | ||
|
||
settings = CompilerSettings() | ||
|
||
with open(path_descriptor, "r") as json_file: | ||
json_data = json.load(json_file) | ||
|
||
data = model.Tool(**json_data) # type: ignore | ||
|
||
compiled_module = compile_descriptor(data, settings) | ||
|
||
if path_output is None: | ||
print(compiled_module) | ||
else: | ||
with open(path_output, "w") as py_file: | ||
py_file.write(compiled_module) | ||
|
||
|
||
if __name__ == "__main__": | ||
_cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Boutiques to python compiler.""" |
Oops, something went wrong.