common-workflow-language / cwl-utils

Python utilities for CWL

Home Page:https://cwl-utils.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cwlgen export functionality

JoanaFMorgado opened this issue · comments

Hello,

I would like to know if cwl-utils provides a method such as export that enables the generation of a CWL file from python Classes?
It would be useful and I am not able to currently find it within cwl-utils.

Many thanks!

Kind Regards,
Joana

Hey Joanna, you can!

Every cwl object has a .save() method which will convert it to dictionary which you could write with ruamel.yaml.
For example:

from io import StringIO
import ruamel.yaml

yaml = ruamel.yaml.YAML()

def convert_cwl_object_to_string(cwlobj: cwlgen.Savable):

    dict_object: dict = cwlobj.save()
    io = StringIO()
    yaml.dump(m, io)
    return io.getvalue()