p5 icon indicating copy to clipboard operation
p5 copied to clipboard

Add the black formatter GitHub Action

Open tushar5526 opened this issue 3 years ago • 11 comments

Is your feature request related to a problem? Please describe. There is a need for a uniform coding style across p5py

Describe the solution you'd like Add a GitHub action that checks a PR for coding style using black. The GHA should be able to format the code and commit it to the PR if the PR is not following the coding style.

tushar5526 avatar Jul 25 '22 13:07 tushar5526

Hey @tushar5526, I am looking forward to solving this Issue. Would you Please Assign it to me?

Mr-Sunglasses avatar Jul 31 '22 17:07 Mr-Sunglasses

@tushar5526 Some things I just want to ask:

  • The GHA runs, it finds that the code is not formatted and after formatting it, it should create a new PR with formatted code or it should make changes to the existing PR.
  • What about the pre-existing code, does the GHA need to also check the pre-existing code and format it?

Mr-Sunglasses avatar Jul 31 '22 19:07 Mr-Sunglasses

Break it into two PRs

  • A PR that formats the whole code base using black. Do this after we merge enhancing skia PR, to avoid unnecessary conflicts.
  • A PR to make a GHA that runs on incoming PRs formats the code and make a commit to that PR only. Yes you can just run black on the whole project instead of only the files that are changed.

tushar5526 avatar Jul 31 '22 19:07 tushar5526

Also, I suppose we have to format our code base first and make a PR for it.

So you can try setting up the GHA (that would run on PRs) on your fork by the time we get the pending changes merged.

tushar5526 avatar Jul 31 '22 19:07 tushar5526

Break it into two PRs

  • A PR that formats the whole code base using black. Do this after we merge enhancing skia PR, to avoid unnecessary conflicts.
  • A PR to make a GHA that runs on incoming PRs formats the code and make a commit to that PR only. Yes you can just run black on the whole project instead of only the files that are changed.

for the formatting of the pre-existing codebase do we need any GHA? In my view I don't think so, We need GHA for the new PRs, for the pre-existing codebase I'll make a PR by formatting it.

Mr-Sunglasses avatar Jul 31 '22 19:07 Mr-Sunglasses

Break it into two PRs

  • A PR that formats the whole code base using black. Do this after we merge enhancing skia PR, to avoid unnecessary conflicts.
  • A PR to make a GHA that runs on incoming PRs formats the code and make a commit to that PR only. Yes you can just run black on the whole project instead of only the files that are changed.

for the formatting of the pre-existing codebase do we need any GHA? In my view I don't think so, We need GHA for the new PRs, for the pre-existing codebase I'll make a PR by formatting it.

Yes

tushar5526 avatar Jul 31 '22 20:07 tushar5526

I am not sure if GHA can commit directly to the author's branch. In the case it can't, we can just fail the build and let the PR author format their code locally and update the result in their PR.

ziyaointl avatar Aug 01 '22 03:08 ziyaointl

I did something once to commit to a PR, but I am not sure if it still works. @Mr-Sunglasses Take a look here

tushar5526 avatar Aug 01 '22 06:08 tushar5526

Hey @Mr-Sunglasses I have run the black formatter on the whole project so I could start with my next milestone in the project. Otherwise, if this was done and merged later, there might have been a lot of merge conflicts that I then have to handle manually.

You can directly work on the GHA now.

tushar5526 avatar Aug 03 '22 07:08 tushar5526

Sure I'll be working on GHA now, will make a PR this week itself.

Mr-Sunglasses avatar Aug 03 '22 18:08 Mr-Sunglasses

No problem, take your time.

tushar5526 avatar Aug 04 '22 05:08 tushar5526

Hey @Mr-Sunglasses, have you got the chance to work on this issue ?

tushar5526 avatar Sep 02 '22 19:09 tushar5526

@tushar5526 I have created a GH action, Looking Forward for your review.

Mr-Sunglasses avatar Sep 12 '22 08:09 Mr-Sunglasses

Works like a charm @Mr-Sunglasses

Thanks!

tushar5526 avatar Sep 12 '22 11:09 tushar5526