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

Consistent python formatting #339

Open
mikebentley15 opened this issue Sep 4, 2021 · 1 comment
Open

Consistent python formatting #339

mikebentley15 opened this issue Sep 4, 2021 · 1 comment

Comments

@mikebentley15
Copy link
Collaborator

Feature Request

Description:

The python formatting currently is done by hand by the original author (myself). This is not particularly sustainable.

It may be worthwhile to look into third-party code formatting tools. The same may be true with C++, but this feature request specifically refers to the python code which is now the majority of the code (I think).

Suggested change:

This is brought on because I found a tool called python-black which easily and reproducibly formats python code. I think it's worth looking into to see if we would like to adopt this tool officially for formatting our python code in FLiT.

It may be worthwhile making it easy to automatically run this formatter as git hooks, like commits or pushes. I'd probably prefer simply enforcing the use of this formatter (if we like it) by checking in a simple unit test that running the formatter changes nothing.

Alternative approaches:

There may be other code formatters that we like, but it seems black is popular and used by big groups like Python Pandas. But if we don't like the formatting scheme, we can look into other choices.

@caydenlund
Copy link

Great idea. I find that code formatters help teams to focus on what matters instead of getting distracted by style inconsistencies.

For Python, there are three main formatters that I see popular in the community:

  • Black, as you mentioned, is a solid option. Its selling point is that it just works; with zero configuration, it formats scripts in-place to align with its rules.
  • Autopep8 is another popular formatter that's much more permissive (i.e., it doesn't enforce as many style rules).
  • Yapf is also a solid option developed by Google. It's designed to be opinionated (like black) but also very configurable.

This blog post gives a nice overview of the differences.

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

No branches or pull requests

2 participants