[issue10639] reindent.py converts newlines to platform default
Changes by Éric Araujo mer...@netwok.org: Added file: http://bugs.python.org/file22765/900df5732f93.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Jason R. Coombs jar...@jaraco.com added the comment: I looked into the possibility of retaining newline characters even for files with mixed newlines, but I've decided that's too intrusive an approach. The current implementation specifically takes measures to strip whitespaces from the ends of lines, so it seems outside the scope of this bug to alter that behavior. So I've taken another stab at a more robust implementation that does newline detection but raises an error if the file contains mixed newlines. Furthermore, it adds an option (--newline) to specify which newline character to use, bypassing the mixed-newline error and allowing the user to override newline detection. Here's a demo run: PS C:\cpython-issue10639 python .\Tools\scripts\reindent.py .\foo.py .\foo.py: mixed newlines detected; cannot continue without --newline PS C:\cpython-issue10639 python .\Tools\scripts\reindent.py --newline CRLF .\foo.py PS C:\cpython-issue10639 python .\Tools\scripts\reindent.py --newline LF .\foo.py PS C:\cpython-issue10639 python .\Tools\scripts\reindent.py .\foo.py I've published this change as https://bitbucket.org/jaraco/cpython-issue10639/changeset/900df5732f93. Please review. If this changeset is acceptable, I will push the revisions to the master repo. Please advise if I may also backport to Python 3.2 and 2.7. -- hgrepos: +45 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Jason R. Coombs jar...@jaraco.com added the comment: Re msg125818, I agree that the mixed EOLs is also a potential problem, though the proposed solution behaves better than the status quo, where the EOLs get converted without warning. It would be desirable for the patch to be more robust in that situation (providing a useful error message about why it fails). What might even be better is to retain newlines even if they're mixed. I'll explore a cross-platform technique to consistently retain newlines as encountered. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Éric Araujo mer...@netwok.org added the comment: I’m not opposed to reindent normalizing EOLs, given that our VCS hooks will translate them to the right thing (for example, making sure that files specific to the Windows build use CRLF, not LF, even if edited on POSIX). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Jason R. Coombs jar...@jaraco.com added the comment: That's great that reindent works in your environment, but that's no help in my environment. Here's the use case: We have a software package developed in Unix and with Unix LF line endings. The code base may also contain files with CRLF line endings (I can't be certain). I'm developing in Windows (which includes reindent.py installed by default). I'd like to use that tool to reindent the code base without munging the line endings. I can't do this without first modifying reindent.py or using another tool to convert the line endings afterword (at which point I don't know if the Windows line endings were created by reindent.py or were there natively). If someone wants the line endings normalized on their code base, they should use another tool (or possibly an option to reindent.py), but there's definitely a case for using reindent.py without altering the line endings. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Éric Araujo mer...@netwok.org added the comment: That is a valid use case, so +1 on not changing behavior and adding a new option in 3.3 (in another bug report). What is your reply to msg125818? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Senthil Kumaran orsent...@gmail.com added the comment: Why is reindent.py translating the whole file to platform default newline such a bad thing? Could not it be considered as helpful behavior, especially in the case where the user has mixed EOLs by mistake? -- nosy: +orsenthil ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Éric Araujo mer...@netwok.org added the comment: I did a bit of testing on demo files. The first one I tested with had mixed EOLs, in which case the newlines attribute will be a tuple and open(..., newline=r.newlines) will fail. For reference: http://docs.python.org/dev/library/io#io.TextIOBase.newlines What would be the best behavior in such cases? Refuse the temptation to guess and exit? -- nosy: +pitrou status: pending - open ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Éric Araujo mer...@netwok.org added the comment: If nobody objects, I will commit this when py3k is unfrozen. -- assignee: - eric.araujo status: open - pending ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
New submission from Jason R. Coombs jar...@jaraco.com: When reindent.py runs, it will convert the line endings for each file it converts to the default line ending for the platform on which reindent.py runs. It would be better if reindent.py would retain line endings of the source file. Attached is a patch that addresses this issue. -- components: Demos and Tools files: reindent-autonewline.patch keywords: patch messages: 123476 nosy: jaraco priority: normal severity: normal status: open title: reindent.py converts newlines to platform default versions: Python 3.1, Python 3.2 Added file: http://bugs.python.org/file19955/reindent-autonewline.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Changes by Jason R. Coombs jar...@jaraco.com: Removed file: http://bugs.python.org/file19955/reindent-autonewline.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Jason R. Coombs jar...@jaraco.com added the comment: Merged the patch with the latest trunk. -- Added file: http://bugs.python.org/file19956/reindent-autonewline.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10639] reindent.py converts newlines to platform default
Éric Araujo mer...@netwok.org added the comment: Looks good. -- nosy: +eric.araujo stage: - patch review type: - behavior versions: +Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10639 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com