-
Notifications
You must be signed in to change notification settings - Fork 105
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
End of line corruption when writing bracket comment #26
Comments
This is not a surprise. I kind of expected it actually. The latest release changed some of the lexing rules and I wasn't sure what would happen with windows line endings. Honestly I wasn't even sure if any software still writes out windows line endings. If you need a quick fix and are comfortable editing code try changing https://github.com/cheshirekow/cmake_format/blob/master/cmake_format/lexer.py#L90 from Also, sorry... I should have really tested that ;). |
On second thought, I guess |
Thanks for putting up the suggestions! Unfortunately, both yielded the same output as before on my Windows machine with Python 3.6. Looking more carefully, when I feed in a file with Unix line endings, it actually gets reformatted to have all Windows endings. Maybe this is platform dependent behavior? I maintain scripts that are formatted both ways, so it would be a really nice feature if the ending style was detected and preserved in the output. |
oh, interesting. The fact that cmake-format outputs windows line endings is very surprising to me. Maybe it's not the lexer change, but the change from plain |
Looking into this now I'm unable to replicate the problem with python 3.5.2 on linux (even with windows line endings). I might have to spin up a virtual machine to look in windows. What version of python are you using? And just to make sure I understand the problem, what you're seeing is that every line in the file ends with |
I am using Python 3.6.4 64-bit from the standard installer. Only the lines in a block comment in a file with Windows line endings are converted to \r\r\n. The remaining lines in the file retain the \r\n ending. The other strange and possibly related issue is that all line endings in a Unix file are converted from \n to \r\n. Let me show show you input and output from the same script with Windows and Unix endings: I'm no Python expert, but I am happy to help you test any ideas on my machine. |
Ok, this is very helpful. With both It is very interesting that only the lines within the bracket comment are corrupted. This suggests to me that it might have something to do with the interaction between I'll continue to investigate, but in the meantime can you try the following test for me:
You should see something like this:
|
ah! I'm on windows now and testing and It seems to be something specific about |
Alright, if you just need a quick fix you can change lines 224-225 of main.py to:
Note that this will (unfortunately) make your output files unix line endings (except for the contents of the bracket comment, which will be windows line endings verbatim. I think that what I'll do is make line ending a setting and I'll make it so that bracket comments are at least line-ending corrected and trailing-whitespace-chomped rather than just copying them input -> output verbatim. Also, I'll probably stop using tempfile.NamedTemporaryFile in order to get consistent behavior between |
Great! Thanks for putting up the quick fix. It works for me with the same caveat you described. |
@iabenz if you're willing to test a change would you mind checkout out and testing the I'll also test on windows myself sometime soon. |
Sure, I gave the new branch a try with the
mixed output: CMakeLists-Windows-Unix.txt |
oh bummer... ok, reading the documentation for io.iopen() it looks like there's a |
Ok, I believe that adding |
Nice! Your fix works great on my machine with all combinations as well. Thanks for tracking this down. |
I know this has already been an ordeal, but would you consider adding an option like |
Seems easy-enough. I'll add it to the ol' TODO list. |
I am seeing an issue since the last release when formatting files in-place with bracket comments and Windows line endings such as this CMakeLists.txt. When formatted in-place, the lines of the bracket comment pick up an extra carriage return, but the rest of the file is written correctly. The output seems correct when writing to stdout or using Unix line endings.
The text was updated successfully, but these errors were encountered: