-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
How to fix merge conflicts related to the black code style reformatting of the scikit-learn code base #20301
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
Comments
I updated commit to cherry-pick e8f58cd which adds the |
I just tried this approach with one of my older PRs. I think straight merging is easier. Running black yourself with the commit right before |
git merge --abort
git fetch upstream main
# Update black config and resolve conflicts before black
git merge 0e7761cdc4f244adb4803f1a97f0a9fe4b365a99
git cherry-pick e8f58cddb55777e0e40195aaf64d5a890b9fdaac
# There is a bug in darker where isort is a hard dependency and fix will be in the next release.
# isort will **not** run when calling `darker`
pip install isort darker black==21.6b0
darker --revision upstream/main .
git commit -m "STY Apply black only on diff"
git merge upstream/main Edit Found a better workflow with: I think I got a workflow that works with. This only runs black on the changed files, which actually uses git diff $(git merge-base upstream/main HEAD) --name-only -- '*.py' | xargs black instead of running |
Should we pin this issue for future contributors? |
It is pinned. |
The problem is that it's not trivial to get this command to work on windows: it will only work in a git bash or a WSL command-line prompt. In particular it will not work in anaconda prompt and I am not sure if it works to activate a conda env in a I am not even sure for the use of |
Maybe it's easier to reformat only the files changed in the PR with black by passing all the necessary config and filenames as command line argument, commit the result and then merge the latest main? |
That would work. Is there a nice way to get all the files that the PR changed in windows? Maybe just copying and pasting is good enough?
|
hey can someone help me? |
Will answer in #20316 |
Could we also add the git ignore command thingy here? We should have one place where all the required changes and configurations in one place. I'm quite confused now. |
I added a small section for git blame to work locally run. i.e:
|
Thanks @thomasjpfan , I updated its title, otherwise 👍 |
My fork hard codes the configuration we are using, which means a contributor does not need to update EditI have been updating some of my older PRs and found that this works with the least conflicts:
|
Merge conflicts can occur when you try to merge code that has been modified in multiple branches or by multiple developers. If the changes are conflicting, it can be difficult to resolve the conflict and merge the code successfully. If you are experiencing merge conflicts related to the black code style reformatting of the scikit-learn codebase, here are some steps you can follow to try to resolve the conflict:
Keep in mind that these are just general guidelines, and the specific steps you need to take to resolve merge conflicts may vary depending on the nature of the conflicts and the changes you are trying to merge. If you are having trouble resolving the conflicts, you may want to seek assistance from other developers or from the scikit-learn community. |
I think we can close this PR now that two years have elapsed. What do you think? |
In #18948 we recently started to use black to format almost all of scikit-learn's code, so it's possible that your PR is conflicting with the
main
branch due to the new code formatting style. Here are some instructions to resolve conflict that you may encounter when merging your PR's branch with themain
branch.Here we assume that
upstream
is an alias for thehttps://github.com/scikit-learn/scikit-learn
git repo or its ssh variant. You can confirm that on your end by checking the output ofgit remote -v
.You could try to directly merge with
main
and then applyblack
locally, but this is likely to introduce a lot of conflicts due to the formatting style change. Instead, we recommend the following workflow:Abort any previous merge attempts in your branch:
git merge --abort
. If you weren't in the middle of a merge before this will fail with "fatal: There is no merge to abort". It's normal, you can safely ignore this message.Fetch all the commits from the main repo
git fetch upstream
Merge your PR branch with the commit right before the black formatting commit:
This will import the black config and deal with existing merge conflicts before black formatting.
Cherry-pick the commit the updates the black config with
target_version
:Then, locally apply black to all the code:
pip install black==21.6b0
To format the code changes in your PR branch from the top level
scikit-learn
source folder:Commit black formatted changes.
This should work without code-style related conflicts.
If
git blame
is important to youFor git blame to work locally run:
The text was updated successfully, but these errors were encountered: