-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PR: Enforce LF line endings in Spyder code #18691
Conversation
I recommand the "Hide whitespace" option for reviewing |
Should this one be closed @impact27 ? |
@impact27, I agree with you because it's becoming an issue with more and more people contributing to the project. Furthermore, it's something that we've thought to do for a long time: PR #2370 describes the steps to follow to not break The problem is that enforcing LF as the only line ending in our codebase would break practically all open PRs, so I don't know what to do about it. |
We could provide instructions to solve the conflicts. Something along the lines of:
|
So something along the lines of:
|
I am not sure what to do about git blame. You can use the -w option to ignore white spaces. I don’t think I understand how to work around that without changing history |
I though it was an outdated/orphan PR left before the closing the codeeditor.py issue at #18690 but now looking more closely the changes here this solves the line return for all Spyder so I guess we need instead to figure out how to apply the changes without causing to much trouble to already open PRs and in general future merges. Maybe as described at #2370 we could do this with the new check/test added here for the CI (maybe adding some logic to only check the files changed in the current PR?) to then reinforce this measure (and prevent introducing more mismatches in terms of line endings) and also doing it in multiple PRs? Maybe even checking the current open PRs and applying the line endings correction in the files that each PR touches? Also maybe I'm not totally sure how the diff between line endings work with version control but shouldn't the correction be done over 5.x too? |
2195f0f
to
fec5656
Compare
I have added a test checking for CRLF in python files
I am not sure about multiple PR, would this not make the transition more painful? This PR essentially does two things:
This is an excellent point, I will open this PR on 5.x |
Ok new strategy for fixing open PR, git merge has a
|
d4f1e0e
to
c3748b8
Compare
Hah! I just submitted a tiny PR (one line), and for the life of me couldn't figure out why git diff showed a CR. Then after figuring out that the whole file was like that, I decided I might as well just leave it in rather than editing the entire file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some high-level comments:
- Right now, this conforms even files that should be CRLF, like
.bat
files, to LF (including those in our vendoredexternal-deps
directory, which is particularly undesirable) - Furthermore, the
text=auto
option will rely on autodetection to determine the file to convert, which may not always be strictly reliable, as opposed to relying on known file extensions whenever possible. - Finally, this may still check out files as CRLF, which is inconsistent across users and platforms, and may produce a extra Git warning on checkin
Instead, I suggest using the well-proven, standardized .gitattributes
that has been used on many of our repos now for years (as well as many others), with QtPy being among those using the latest version. This avoids all the problems mentioned above, along with bringing other benefits like better diffs and not exporting irrelevant files in Git tarballs.
This will also conform all files automatically on commit, so there is no need for a hacky and expensive test in the test suite (and why the non-standard file name capitalization?). If we do want to be absolutely sure that no LF files are ever committed again or merged again, adding the relevant built-in pre-commit hook would be a better solution (though again, probably not worth it on its own since Git already makes sure of it).
As for reducing the impact on the git blame/git history, you can use .git-blame-ignore-revs as of Git 2.23 and later which GitHub finally now supports (beta) and make sure to squash this down to one atomic commit first once its ready.
Beyond that, the problem of breaking existing PRs is a significant concern. Our strategy before when eliminating trailing whitespace was using this script I wrote which conformed all files not touched by existing PRs. That approach could be used, perhaps combined with ignoring PRs that are stale by more than a month or so, but it would blunt much of the impact of the changes, so I'm not sure about that and whether we should just go ahead and do it.
Ok, let's try to merge this PR before any other one so that @impact27 doesn't have to constantly rebase it. About preserving https://black.readthedocs.io/en/latest/guides/introducing_black_to_your_project.html So, if I understood things correctly, you need to leave a single commit with the line ending changes and then add its hash to a |
The major remaining action items are:
|
Apparently the tests don't like
|
To fix that please add |
I did some more testing, and the best way to fix current PR seems to be:
2 - Reset line ending for all py files inside the spyder directory
3 - merge 5.x (or master) ignoring CR:
After this the PR can be merged into 5.x / master as usual |
Thanks for checking that, but I have one question: is it possible to avoid this step?
The thing is that would introduce a commit per PR that would need to be added to |
I am not sure how git blame works, but wouldn't it just check the merge commit which doesn't change line endings? Maybe rebase is better |
The nuclear option would be to do all these steps, then:
All the commits would be lost, but the result would be as expected |
I think @CAM-Gerlach, what do you think about this? |
Ideally you would rebase PR on top of this PR. You should be able to do it with: |
I found the magic git command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like all the things I mentioned were addressed, thanks. However, instead of just dropping 0040028 and rebasing on the base branch with it merged, it seems not one but two commits were made undoing the original commits. Since this cannot be squash-merged (or .git-blame-ignore-revs
will of course not work, since the resulting commit hash cannot be known a priori), these need to all be dealt with properly.
@impact27, it seems Github only shows the commit that changed line endings on blank lines; the other lines preserve the last commit that changed them, which is what we want (otherwise we'd see the entire file as changed by yourself). Could you attend today's developers meeting to talk about this and see if we can merge it? @CAM-Gerlach is going to be there too, so it'd be a great opportunity to go through this in person. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this is LGTM at least from my side, but we can talk about it at the meeting today since this does have some potential for disruption on existing PRs so we need to make sure we've carefully considered the implications and everyone's on the same page
Ok, let's merge this one. Thanks @impact27 for your work on it and @CAM-Gerlach for the review. Note: The failures with the Windows installer are unrelated to this. |
@ccordoba12 for master you can |
Thanks for the tip, I just did it. |
One additional note: to ignore the commits added to
|
Description of Changes
Transform CRLF to LF and add a test
Issue(s) Resolved
Fixes #18690
Affirmation
By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.
I certify the above statement is true and correct: