-
Notifications
You must be signed in to change notification settings - Fork 29
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
snakefmt corrupts heredoc string #123
Comments
Hi @dariober can you please retry with v0.4.4 - we have made some changes to how shell strings are handled since v0.4.0 |
@mbhall88 Thanks for looking into this. I made a new conda environment, updated snakefmt and the problem persists in v0.4.4. |
Ok, this seems to be related to #39 where we made a conscious decision to format these shell strings. @bricoletc maybe we need to add some functionality whereby r-strings (like in the above example) are left alone? |
I would be happy for r-strings to be left alone (I got the habit of always using r-strings for shell directives unless required otherwise) but I would still consider it a bug. A user may write a heredoc without r-formatting and find it broken after snakefmt. |
@dariober sorry for the massive delay. Could you try mbhall88@b591a81 and see if this works as you expect? I added a test case using your example above and this is indeed formatted (i.e. not formatted) as expected |
@mbhall88 thanks for that and no worries about the delay! I can confirm that the version you linked works on the test file I posted. I would still contend that the content of a string is "data" not "code" and as such it shouldn't be edited in any way. I mean, you cannot make assumptions about what the user put in a string. But I assume you guys have discussed this and opted for this solution... |
Yes, you're both correct. @bricoletc, even when I make it a normal docstring it doesn't change that example. I think this is something we have touched on in #118 and #121 and it may have gotten a little lost in the details.
At the end of the day, this should be handled inline with black - see black's code style for strings.
So after all of this, I'm a little confused as to what needs to change? |
I think there is some confusion about docstrings and multiline strings. Python doesn't have heredocs
So I guess black's actions on multiline strings is the behaviour we should mirror at the end of the day. I think nearly all of the confusion about what to do here stems from the |
Just a side question @dariober , can you describe why heredoc is used here? It seems to me like you can achieve the same effect by doing:
This is of course ultimately unrelated to the issue as we do have an issue with heredoc here |
Sometimes I use heredoc strings to execute small R scripts like this:
Basically, dump the R code to a temporary file and execute it with For small R scripts I find it more transparent than using the |
To confirm I have this correct, I will test out the fix I implemented for this issue and see how it performs on other heredoc-style strings and ensure we don't indent multiline strings? |
@mbhall88 how about we simply not indent if the shell string contains some regexp capturing EOF, e.g. |
I guess my only reservation with that approach is whether there are examples other than a heredoc where the indenting in a multiline string matters? |
I suspect that is going to be tricky because
Personally, I would leave the content of the strings alone and just re-align the opening and closing quotes. |
@dariober this should now be fixed in mbhall88@4c83e06. Feel free to try it out if you like. I will create a PR soon to get this into a release |
snakefmt v0.4.0 reformats this rule:
into:
the reformatted indentation makes the heredoc invalid since bash expects the closing
EOF
at the start of the line. When execute it I get:I tried to upgrade to snakefmt 0.4.4 using mamba. This maybe a separate issue, I get:
The text was updated successfully, but these errors were encountered: