Debian Codegraph @

docs/source/commandline_interface.rst

raw
1 Common Commandline Interface
2 ============================
3
4
5 Motivation And High Level Example
6 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7
8 - Provide a common interface for executables to expose options
9 - Provide a common interface for executables to be called
10 - Provide a common interface for exposing metadata of tool, such as memory usage, cpu usage, required temp files
11
12 Benefits
13 ~~~~~~~~
14
15 - A consistent concrete common interface for shelling out to an executable
16 - task options have a consistent model for validation
17 - task version is supported
18 - A principled model for wrapping tools. For example, pbalign would "inherit" blasr options and extend, or wrap them.
19 - Once a manifest has been defined and registered to pbsmrtpipe, the task/manifest can be referenced in pipelines with no additional work
20
21
22 Terms
23 ~~~~~
24
25 - 'Tool Contract' is a single file that exposing the exe interface. It
26 contains metadata about the task, such as input and output file
27 types, nproc.
28 - 'Resolved Tool Contract' is a single file that contains the resolved values in the manifest
29 - 'Driver' is the general interface for calling a commandline exe. This can be called from the commandline or directly as an API call (via any language which supports the manifest interface).
30
31 Hello World Dev Example
32 ~~~~~~~~~~~~~~~~~~~~~~~
33
34 Tool Contract example for an exe, 'python -m pbcommand.cli.example.dev_app` with tool contract id `pbcommand.tasks.dev_app`.
35
36
37 .. literalinclude:: ../../tests/data/tool-contracts/pbcommand.tasks.dev_app_tool_contract.json
38 :language: javascript
39
40
41 Details of Tool Contract
42 ~~~~~~~~~~~~~~~~~~~~~~~~
43
44 - Tool Contract id which can be referenced globally (e.g., within a pipeline template)
45 - Input File types have file type id, id that can be referenced within the driver, and a brief description
46 - Output File types have a file type id and a default output file name
47 - number of processors is defined by $nproc. "\$" prefixed values are symbols that have well defined semantic meaning
48 - Temp files and Log files are defined using "$" symbols are can have multiple items
49 - the exe options are exposed via jsonschema standard. Each option has an id and maps to a single schema definition. Each option must have a default value.
50 - the exe section of the "driver" is the commandline interface that will be called as a positional arguement (e.g., "my-exe resolved-manifest.json")
51 - task type describes if the task should be submitted to the cluster resources
52
53
54 Note. A single driver can reference many manifests. For example "pbreports" would have a single driver exe. From the "task_manifest_id", the driver would dispatch to the correct function call
55
56 Programmatically defining a Parser to Emit a Tool Contract
57 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
59 pbcommand provides a API to create a tool contract and an argparse instance from a single interface. This facilitates a single point of defining options and keeps the standard commandline entry point and the tool contract to be in sync.
60
61 This also allows your tool to emit the tool contract to stdout using "--emit-tool-contract" **and** the tool to be run from a **Resolved Tool Contract** using the "--resolved-tool-contract /path/to/resolved-tool-contract.json" commandline argument **while** also supporting the python standards commandline interface via argparse.
62
63 Complete App shown below.
64
65
66 .. literalinclude:: ../../pbcommand/cli/examples/dev_app.py
67 :language: python
68
69 .. note:: Options must be prefixed with {pbcommand}.task_options.{option_id} format.
70
71 Details and Example of a Resolved Tool Contract
72 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73
74 - Language agnostic JSON format to encode the resolved values
75 - input, outputs file types are resolved to file paths
76 - nproc and other resources are resolved
77 - IO layers to convert between JSON and python using `load_resolved_tool_contract_from` in `pbcommand.pb_io`
78
79 Example Resolved Tool Contract:
80
81 .. literalinclude:: ../../tests/data/resolved-tool-contracts/dev_example_resolved_tool_contract.json
82 :language: javascript
83
84
85 Testing Tool Contracts
86 ~~~~~~~~~~~~~~~~~~~~~~
87
88 There is a thin test framework in `pbcommand.testkit` to help test tool contracts from within nose.
89
90 The `PbTestApp` base class will provide the core validation of the outputs as well as handled the creation of the resolved tool contract.
91
92 Output Validation assertions
93
94 - validates Output files exist
95 - validates resolved task options
96 - validates resolved value of is distributed
97 - validates resolved value of nproc
98
99 Example:
100
101 .. literalinclude:: ../../tests/test_e2e_example_apps.py
102 :language: python
103
104
105 Tips
106 ~~~~
107
108 A dev tool within pbcommand can help convert Tool Contract JSON files to Resolved Tool Contract for testing purposes.
109
110
111 .. argparse::
112 :module: pbcommand.interactive_resolver
113 :func: get_parser
114 :prog: python -m pbcommand.interactive_resolver
115
116
117 .. note:: This tool has dependency on `prompt_kit` and can be installed via pip.