Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I avoid removing comments in CWL ? #20

Open
aleksandarbaburski opened this issue Nov 9, 2022 · 6 comments
Open

How can I avoid removing comments in CWL ? #20

aleksandarbaburski opened this issue Nov 9, 2022 · 6 comments

Comments

@aleksandarbaburski
Copy link

Hi,
while formatting CWL code, the cwl-format will remove all comment lines.
Can I avoid that somehow? I would like to have some comments in the code.
Is there a reason for removing comments by default?

Thanks,
Aleksandar

@mr-c
Copy link
Contributor

mr-c commented Nov 9, 2022

Hello @aleksandarbaburski

DId you see the first entry in https://github.com/rabix/cwl-format#rules ?

If there are useful comments, perhaps they would make more sense as label and doc entries?

@aleksandarbaburski
Copy link
Author

Thanks @mr-c on quick response!

Yes, I sow that first rule, but I wasn't sure if that's some best practice specific for CWL or there is some other reason why classical comments (#) in the CWL code should be avoided?

@aleksandarbaburski
Copy link
Author

aleksandarbaburski commented Nov 14, 2022

Hi @mr-c,

I am trying to run the second use case in the "Use programmatically in Python" section:

from cwlformat.formatter import stringify_dict

as_dict = load_yaml(unformatted_text)
formatted_str = stringify_dict(as_dict)
  1. I couldn't find load_yaml function. How to import it?
  2. It looks like the first 2 rules do not apply to this use case. Here, all the comments (including comments before the actual CWL code) will be removed, right?

FYI @bhanu-gandham

@aleksandarbaburski
Copy link
Author

@mr-c, what can be done to override the feature of removing comments within CWL?
On the other hand, if removing those comments is in line with CWL best practice we will use the cwl-format package as is.
Thanks

FYI @bhanu-gandham

@mr-c
Copy link
Contributor

mr-c commented Nov 14, 2022

Yes, I sow that first rule, but I wasn't sure if that's some best practice specific for CWL or there is some other reason why classical comments (#) in the CWL code should be avoided?

If the comments would be meaningful to the user of the tool or workflow, then they would be better suited for the various doc and label fields

The choice to remove comments altogether was not mine; this tool was originally written by @kghose

@mr-c
Copy link
Contributor

mr-c commented Nov 14, 2022

Replace load_yaml with your preferred yaml loader (pyyaml or ruamel.yaml, for example)

import ruamel.yaml
yaml = ruamel.yaml.YAML()
as_dict = yaml.load( ... )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants