Skip to content
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

Adding tooling for JuliaFormatter. #2323

Merged
merged 12 commits into from
Sep 10, 2023

Conversation

codetalker7
Copy link
Contributor

@codetalker7 codetalker7 commented Aug 28, 2023

This PR is to add some format tooling to Flux. A new environment is created in the dev folder, which will contain all dependencies required for the tooling (currently it only contains JuliaFormatter.jl). A new config file for JuliaFormatter is added, along with a script to run JuliaFormatter (dev/flux_format.jl). Along with this, a new JuliaFormatter CI has been added as well. Much of this is inspired from the workflow in ClimaCore.jl.

TODO:

  • Implement a pre-commit hook which runs the formatting script before each commit.
  • Do we need to add docs for this?
  • Do we add this to our test suite?

Closes #2298.

cc @ToucheSir @CarloLucibello @darsnack

@codetalker7
Copy link
Contributor Author

codetalker7 commented Aug 29, 2023

Just a heads up: git hooks in the .git directory aren't version controlled by default. Assuming that users have at least Git 2.9, we can set the core.hooksPath config to a custom directory in the project (say .githooks). To do this we'll have to probably write another script which does this whenever Flux is cloned (or installed).

Any other alternatives for managing hooks (for example pre-commit) will require users to install other packages most likely.

@codetalker7 codetalker7 marked this pull request as ready for review August 29, 2023 11:32
@codetalker7 codetalker7 marked this pull request as draft August 29, 2023 11:32
@Saransh-cpp
Copy link
Member

See #2074 for a lot of discussion over JuliaFormatter and tools like pre-commit 🙂

@codetalker7
Copy link
Contributor Author

See #2074 for a lot of discussion over JuliaFormatter and tools like pre-commit 🙂

Thanks for the reference.

@ToucheSir
Copy link
Member

ToucheSir commented Aug 30, 2023

Originally I had thought that one could use .gitattributes to work around having to install hooks as a separate step, but that turns out to not be possible. As such, we may have to compromise and make a Julia script which does tool setup + hook installation. Technical setup documentation (e.g. "run this script") would then be added in CONTRIBUTING.md.

@codetalker7
Copy link
Contributor Author

Originally I had thought that one could use .gitattributes to work around having to install hooks as a separate step, but that turns out to not be possible. As such, we may have to compromise and make a Julia script which does tool setup + hook installation. Technical setup documentation (e.g. "run this script") would then be added in CONTRIBUTING.md.

Yes, that sounds good. Also, how about adding this as a build step for Flux? So adding all these steps in deps/build.jl and using the deps folder for tooling instead of dev (I'm not too familiar with the pros/cons of doing this as part of the build step)?

@ToucheSir
Copy link
Member

I would double-check if build scripts can run on package install. If so, we shouldn't be using them for this.

@codetalker7
Copy link
Contributor Author

codetalker7 commented Sep 2, 2023

How does the setup.jl file look? Developers will be able to set up the hook by running julia dev/setup.jl. I hope the chmod function from Base.Filesystem works on non-Linux OS's as well. If not, I'll have to add some conditionals for each OS (update: tested it on Windows, it works fine).

@codetalker7 codetalker7 marked this pull request as ready for review September 2, 2023 12:48
@codecov-commenter
Copy link

codecov-commenter commented Sep 3, 2023

Codecov Report

Patch coverage has no change and project coverage change: -1.81% ⚠️

Comparison is base (fdcf8d3) 76.46% compared to head (5fdd72a) 74.65%.
Report is 6 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2323      +/-   ##
==========================================
- Coverage   76.46%   74.65%   -1.81%     
==========================================
  Files          31       31              
  Lines        1814     1815       +1     
==========================================
- Hits         1387     1355      -32     
- Misses        427      460      +33     

see 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.

📢 Have feedback on the report? Share it here.

on:
push:
branches:
- main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- main
- master

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh yes, it should be master instead of main. I'll update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the change; also removed the other two spurious branches, and removed a deprecated workflow.

@codetalker7
Copy link
Contributor Author

Also added formatting information to CONTRIBUTING.md. One question: should we have the --verbose option in the pre-commit hook? It prints all the formatted files when the commit is initiated.

@ToucheSir
Copy link
Member

I would say no. Does it provide any visual feedback that formatting is running right now without --verbose? If not we'd want to add at least a "formatting in progress" println or something like it.

@ToucheSir
Copy link
Member

Oh sorry, another thing I forgot to mention is that we should split up the commits adding tooling + CI and the commits actually reformatting the codebase. If you're comfortable doing the history manipulation to have those on the same PR go for it, just make sure to add a .git-blame-ignore-revs like we have in Metalhead. If not, feel free to back out the reformatting and we can leave that for a future PR.

@codetalker7
Copy link
Contributor Author

Oh sorry, another thing I forgot to mention is that we should split up the commits adding tooling + CI and the commits actually reformatting the codebase. If you're comfortable doing the history manipulation to have those on the same PR go for it, just make sure to add a .git-blame-ignore-revs like we have in Metalhead. If not, feel free to back out the reformatting and we can leave that for a future PR.

Done. How does it look now?

@ToucheSir
Copy link
Member

It looks good, but I realized another issue, sorry. The formatting style being used is not one many contributors like. In particular, I think the splitting args across multiple lines instead of trying to wrap on as few lines as possible was a deal-breaker. Do you mind just backing out the reformat for now? I don't want us to lose out on merging the nice tooling PR while we bikeshed what the formatting style should be!

@codetalker7
Copy link
Contributor Author

It looks good, but I realized another issue, sorry. The formatting style being used is not one many contributors like. In particular, I think the splitting args across multiple lines instead of trying to wrap on as few lines as possible was a deal-breaker. Do you mind just backing out the reformat for now? I don't want us to lose out on merging the nice tooling PR while we bikeshed what the formatting style should be!

Sure, I've removed the formatting commit. Please let me know if anything else is missing/needed.

Also, do we want to add the formatting check to our test suite?

@ToucheSir
Copy link
Member

Do you mean to the package test suite? Probably not, I think.

@codetalker7
Copy link
Contributor Author

Do you mean to the package test suite? Probably not, I think.

Okay 👍

@CarloLucibello CarloLucibello merged commit 0841ea4 into FluxML:master Sep 10, 2023
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

move the codebase to 4 spaces indentation
5 participants