From 9886ce79bb5744fcb98cf0d869e8b8e7ded91cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Fenoy?= Date: Mon, 6 Oct 2025 12:07:33 +0200 Subject: [PATCH] Add CWLFloatInput to the available annotations --- ipython2cwl/cwltoolextractor.py | 8 ++++++-- ipython2cwl/iotypes.py | 13 +++++++++++++ tests/test_cwltoolextractor.py | 13 ++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ipython2cwl/cwltoolextractor.py b/ipython2cwl/cwltoolextractor.py index abe9962..fb3d5d1 100644 --- a/ipython2cwl/cwltoolextractor.py +++ b/ipython2cwl/cwltoolextractor.py @@ -14,8 +14,8 @@ import yaml from nbformat.notebooknode import NotebookNode # type: ignore -from .iotypes import CWLFilePathInput, CWLBooleanInput, CWLIntInput, CWLStringInput, CWLFilePathOutput, \ - CWLDumpableFile, CWLDumpableBinaryFile, CWLDumpable, CWLPNGPlot, CWLPNGFigure +from .iotypes import CWLFilePathInput, CWLBooleanInput, CWLIntInput, CWLFloatInput, CWLStringInput, \ + CWLFilePathOutput, CWLDumpableFile, CWLDumpableBinaryFile, CWLDumpable, CWLPNGPlot, CWLPNGFigure from .requirements_manager import RequirementsManager with open(os.sep.join([os.path.abspath(os.path.dirname(__file__)), 'templates', 'template.dockerfile'])) as f: @@ -46,6 +46,10 @@ class AnnotatedVariablesExtractor(ast.NodeTransformer): 'int', 'int', ), + (CWLFloatInput.__name__,): ( + 'float', + 'float', + ), (CWLStringInput.__name__,): ( 'string', 'str', diff --git a/ipython2cwl/iotypes.py b/ipython2cwl/iotypes.py index dc438a4..1bdc216 100644 --- a/ipython2cwl/iotypes.py +++ b/ipython2cwl/iotypes.py @@ -15,6 +15,8 @@ * CWLIntInput + * CWLFloatInput + * Outputs: * CWLFilePathOutput @@ -86,6 +88,17 @@ class CWLIntInput(_CWLInput): """ pass +class CWLFloatInput(_CWLInput): + """Use that hint to annotate that a variable is a float input. You can use the typing annotation + as a string by importing it. At the generated script a command line argument with the name of the variable + will be created and the assignment of value will be generalised. + + >>> dataset1: CWLFloatInput = 1.0 + >>> dataset2: 'CWLFloatInput' = 2.0 + + """ + pass + class _CWLOutput: pass diff --git a/tests/test_cwltoolextractor.py b/tests/test_cwltoolextractor.py index 724a030..7d5dd89 100644 --- a/tests/test_cwltoolextractor.py +++ b/tests/test_cwltoolextractor.py @@ -18,7 +18,8 @@ def test_AnnotatedIPython2CWLToolConverter_cwl_command_line_tool(self): "import csv", "input_filename: CWLFilePathInput = 'data.csv'", "flag: CWLBooleanInput = true", - "num: CWLIntInput = 1", + "num_int: CWLIntInput = 1", + "num_float: CWLFloatInput = 1.0", "msg: CWLStringInput = 'hello world'", "with open(input_filename) as f:", "\tcsv_reader = csv.reader(f)", @@ -50,10 +51,16 @@ def test_AnnotatedIPython2CWLToolConverter_cwl_command_line_tool(self): 'prefix': '--flag' } }, - 'num': { + 'num_int': { 'type': 'int', 'inputBinding': { - 'prefix': '--num' + 'prefix': '--num_int' + } + }, + 'num_float': { + 'type': 'float', + 'inputBinding': { + 'prefix': '--num_float' } }, 'msg': {