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

Protect ruamel from blank comment strings when making templates #1390

Merged
merged 2 commits into from
Jan 6, 2022

Conversation

leipzig
Copy link
Contributor

@leipzig leipzig commented Dec 14, 2020

If Ruamel encounters a blank comment string "" instead of None it throws a hissy fit. This happened for me when an input was of type 'Record' using --make-template

  read_names:
    type:
      - type: record
Traceback (most recent call last):
  File "~/dev/capanno-utils/lib/python3.6/site-packages/cwltool/main.py", line 972, in main
    make_template(tool)
  File "~/dev/capanno-utils/lib/python3.6/site-packages/cwltool/main.py", line 732, in make_template
    generate_input_template(tool),
  File "~/dev/capanno-utils/lib/python3.6/site-packages/cwltool/main.py", line 299, in generate_input_template
    template.insert(0, name, value, comment)
  File "~/dev/capanno-utils/lib/python3.6/site-packages/ruamel/yaml/comments.py", line 722, in insert
    self.yaml_add_eol_comment(comment, key=key)
  File "~/dev/capanno-utils/lib/python3.6/site-packages/ruamel/yaml/comments.py", line 294, in yaml_add_eol_comment
    if comment[0] != '#':

@leipzig leipzig changed the title Update main.py Protect ruamel from blank comment strings when making templates Dec 14, 2020
@codecov
Copy link

codecov bot commented Dec 14, 2020

Codecov Report

Merging #1390 (62bf024) into main (8c4665d) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1390   +/-   ##
=======================================
  Coverage   65.93%   65.93%           
=======================================
  Files          93       93           
  Lines       16447    16447           
  Branches     4358     4358           
=======================================
  Hits        10844    10844           
+ Misses       4451     4445    -6     
- Partials     1152     1158    +6     
Impacted Files Coverage Δ
cwltool/singularity.py 58.41% <ø> (-0.20%) ⬇️
cwltool/main.py 67.69% <100.00%> (+0.71%) ⬆️
job.py 61.53% <0.00%> (-0.79%) ⬇️
singularity.py 52.33% <0.00%> (-0.23%) ⬇️
main.py 31.90% <0.00%> (-0.05%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c4665d...62bf024. Read the comment docs.

Copy link
Member

@mr-c mr-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @leipzig ! Can you add a confirmatory test-case?

@leipzig
Copy link
Contributor Author

leipzig commented Dec 14, 2020

Thank you @leipzig ! Can you add a confirmatory test-case?

OK I don't see any existing tests of make_template generate_input_template generate_example_input but I'll give it a go

@mr-c
Copy link
Member

mr-c commented Dec 14, 2020

Thank you @leipzig ! Can you add a confirmatory test-case?

OK I don't see any existing tests of make_template generate_input_template generate_example_input but I'll give it a go

Yeah, I'm setting you up to test previously under-tested code; good luck and please ask for help!

https://codecov.io/gh/common-workflow-language/cwltool/src/main/cwltool/main.py#L160

@mr-c mr-c enabled auto-merge (squash) January 6, 2022 10:46
@mr-c mr-c force-pushed the patch-1 branch 2 times, most recently from 14243b0 to 786a0ee Compare January 6, 2022 10:52
leipzig and others added 2 commits January 6, 2022 13:14
If ruamel.yaml encounters a blank comment string "" instead of None it throws a fit. This happens when an input is of type 'Record' without a name
```
  read_names:
    type:
      - type: record
```

```
Traceback (most recent call last):
  File "~/dev/capanno-utils/lib/python3.6/site-packages/cwltool/main.py", line 972, in main
    make_template(tool)
  File "~/dev/capanno-utils/lib/python3.6/site-packages/cwltool/main.py", line 732, in make_template
    generate_input_template(tool),
  File "~/dev/capanno-utils/lib/python3.6/site-packages/cwltool/main.py", line 299, in generate_input_template
    template.insert(0, name, value, comment)
  File "~/dev/capanno-utils/lib/python3.6/site-packages/ruamel/yaml/comments.py", line 722, in insert
    self.yaml_add_eol_comment(comment, key=key)
  File "~/dev/capanno-utils/lib/python3.6/site-packages/ruamel/yaml/comments.py", line 294, in yaml_add_eol_comment
    if comment[0] != '#':
```
@lgtm-com
Copy link

lgtm-com bot commented Jan 6, 2022

This pull request fixes 2 alerts when merging 62bf024 into 8c4665d - view on LGTM.com

fixed alerts:

  • 2 for Unused import

@mr-c mr-c merged commit d5f7fa1 into common-workflow-language:main Jan 6, 2022
@mr-c
Copy link
Member

mr-c commented Jan 6, 2022

Thanks @leipzig !

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

Successfully merging this pull request may close these issues.

2 participants