-
-
Notifications
You must be signed in to change notification settings - Fork 295
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
[Bug] Fix formatting, use Black #543
Comments
|
Things which would be good to do before applying Black to the code base:
What code should be Black applied to? The above stats are just about the "primary" code such as modules in |
|
Thanks for your hard work on getting GH Actions to work and on the code style formatting issues. While I am in favour of significantly improving the Python code formatting, a related question: do we backport those changes? If not, backporting will soon be hard or even impossible. Or, do we fork 7.10 from master in some near future? |
|
Another question: will/can we have this in https://github.com/OSGeo/grass-addons/ as well? |
Given our current plans, if we do it before branching out to do the 8.0.0 release, we are good. |
I suggest to ask for full back Black and maximum Flake8 compliance for all new addons. Additionally, we could apply Black before/when reorganizing addons for v8. |
|
Black applied to the script directory in #1347. |
|
Black applied to the lib/init/grass.py file in #1359. |
|
Black 20.8b1 with target versions py36, py37, py38 and line length 88 applied in: Configuration is in the Bugs in Black 20.8b1 prevent these three files from being formatted correctly (to be resolved later with some subsequent release of Black together with other updates if needed): Black is not applied to addons yet (except for some files). |
Describe the bug
There is over 5000 whitespace issues in Python source code in GRASS GIS. Unlike other languages, Python has good standards for whitespace (even the one which does not matter syntactically) such as PEP8. Let's use them.
Black (https://github.com/psf/black) is a Python code formatter which cannot be configured, so even the parts which are open to interpretation in PEP8 are fixed in Black. So, there is no need to configure it (except line length, string handling, and Python version specific code handling - compare e.g. to ClangFormat or Pylint). As one testimonial says: Black is opinionated so you don't have to be.
Depending on the parameters, the command line tool black reformats code automatically, checks if it is correctly formatted, or gives diff saying how code should be changed, so we can use it reformat code once and then have it in CI to check the formatting and suggest the fix.
Some choices made in Black are different from what we are using currently, but I think going with the standard is just worth it and also easy enough since the tool will just take care of that (it can run from command line, your editor may have an integration already, or you can set it up as a pre-commit hook.
Black is still in beta, so some changes in formatting may occur, but my guess is that it will be much smaller than the current changes needed or even changes done in past.
Also this will introduce many changes in the source code, so e.g.
git blamewill require more work to get to the actual author. However, we need to make a lot of changes anyway (see e.g. #538. #539, #540) and we have several of these things in the souce code already (given the history of the project).To Reproduce
flake8 --statistics --count ..Expected behavior
Contributors can use Python editors with default settings and don't need to manually get the formatting right when there is a tool for it.
Current error reports by Flake8
lib/python
scripts
temporal
gui/wxpython
Additional context
Black was already suggested by @neteler on grass-dev with some discussion by @pmav99 and myself.
CI (GitHub Actions) now has Flake8 checks with many issues now being fixes, so producing high-quality code should become easier for contributors also in the other areas than consistent formatting as the existing code will obey the rules and best practices.
The text was updated successfully, but these errors were encountered: