Generates CWL documents and associated parameters from a Click CLI definition
Project description
Click2CWL - from a Click context to a CWL document
Rational and context
EO application developers use Click to create command line tools to process EO data.
Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary. It’s the “Command Line Interface Creation Kit”. It’s highly configurable but comes with sensible defaults out of the box. It aims to make the process of writing command line tools quick and fun while also preventing any frustration caused by the inability to implement an intended CLI API.
To deploy these applications on an Exploitation Plaform on the Cloud, the EO application developers generate a CWL document that becomes an Application Package.
The repo contains a helper Python module that exploits the information contained in a Click context object to generate the CWL document and eventually the parameters.
This helper Python module can thus be used to add "CWL dump" behaviour to a Python CLI that uses Click by adding an import and call to the dump(ctx)
function provided in the helper Python module.
Installation
Install this Python module in your conda environment using conda
or mamba
(see this article to learn about mamba):
conda install -c terradue click2cwl
Note: Add click2cwl
dependency and terradue
channel in your environment.yml file, e.g.:
name: my_env
channels:
- terradue
- conda-forge
dependencies:
- python
- click2cwl
Usage
First import the click2cwl dump
function with:
from click2cwl import dump
Then, in the Python application entry point function, update and enrich the Click function decorator with the information for generating the CWL document.
The information defined at the Click function decorator is explained below:
@click.command
The @click.command
decorator must:
- set the
allow_extra_args
flag toTrue
. This allows using the command line interface to pass the runtime information to generate the CWL. - set the
short_help
to define the CWL Workflow class label - set the
help
to define the CWL Workflow class doc
@click.command(
short_help="This is Workflow class label",
help="This is Workflow class doc",
context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True,
),
)
@click.option
The @click.option
decorator must:
- define the option type that can be
click.Path
for aDirectory
, aclick.File
for aFile
or the default, aString
to map asstring
- set the
help
to define the CWL Workflow class doc and label - set the
required
flag toFalse
if the parameter is optional
@click.option(
"--input_path",
"-i",
"input_path",
type=click.Path(),
help="this input path",
multiple=False,
required=True,
)
Finally, invoke the dump
function in your Click decorated function with:
@click.command ...
@click.option ...
@click.pass_context
def main(ctx, **kwargs):
dump(ctx)
print("business as usual")
print(kwargs)
if __name__ == '__main__':
main()
Note: See the examples folder to discover typical use cases.
Install your application with:
python setup.py install
When the app help is invoked, it will only show the arguments defined by the click.decorators:
myapp --help
but it now supports additional args to drive the generation of the CWL document and associated parameters:
The additional args are:
--dump
cwl
|params
|clt
. Example--dump cwl --dump params
will dump the CWL document and the CWL parameters template in YAML.clt
will dump the CWlCommandLineTool
class only (no Workflow)--requirement
withrequirement=value
where requirement here is one of"coresMin"
,"coresMax"
,"ramMin"
,"ramMax"
. Example:--requirement ramMax=1 --requirement ramMin=2
--docker <docker image>
if set, theDockerRequirement
hint is set to pull the<docker image>
--env
sets environment variables in the CWL withenv_var=env_var_value
. Example--env A=1 --env B=2
where A and B are the environment variables to set in the CWLEnvVarRequirement
requirement--wall-time <wall-time in seconds>
if set, theToolTimeLimit
cWL requirement is set and the CWL document version is set to v1.1 (instead of default 1.0)--cwl-version
, if set, thecwlVersion
uses that value
Try me on Binder
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file click2cwl-0.0.4.tar.gz
.
File metadata
- Download URL: click2cwl-0.0.4.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f14818283fd624234b4ea28c004cedd89e7b1d49eee9e2aacc4cd1e676d3532 |
|
MD5 | 2e9a4b2c8392097acc7ba1334da461b0 |
|
BLAKE2b-256 | 4efd1f485aae55a65f7a632361f0d4eac59eb53d1442351f5bad16a515550bca |
File details
Details for the file click2cwl-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: click2cwl-0.0.4-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7daef980f79590fd522e0dc3cabc90b8b9a44d6a4db0b6e783a9976ec9141603 |
|
MD5 | 6eb9ff87a88ea2bf65dc3e2bf4977303 |
|
BLAKE2b-256 | dd719c549174a072438c5e9cd62c2123f9796ba57222aac33175d53f3afc6088 |