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

style: format all python files using black #16453

Merged
merged 4 commits into from
Apr 12, 2022

Conversation

surajshetty3416
Copy link
Member

@surajshetty3416 surajshetty3416 commented Mar 30, 2022

Process

  • Added a pre-commit hook for auto-formatting.
  • Ran the pre-commit command for all files using pre-commit run --all-files

ref: frappe/erpnext#29762

Changes

  • Added isort & black to pre-commit config
  • Formatted all .py files

Reason

  • One step less to ship something great!

In my early days, I used to code without any consideration for code formatting. The goal was to create something fun and useful. Then someone pointed out that you should format your code so that others can easily read the code and it looks more professional. I started formatting my code but regularly used to forget it since the goal still was to create something. Luckily, I discovered linters which made my life simpler... I just had to do fixes as linter suggest after I got the expected result from my code. Days passed, and I somehow came to be a reviewer of a big project (by this time, I was comfortable with the process of fixing according to the linter's suggestion). As a reviewer, I used to come across badly formatted code quite frequently. I started to bluntly comment on PRs to fix the formatting issues (since it was not an issue for me anymore?). Even started to judge developers based on their code formatting skills. The empathy was lost. I continued this for a long, till Ankush made us realize that you don't have to go through all that trouble. We can just add quick automation so that developers and reviewers don't have to worry about things that are not so important. Instant step-up!
I think in couple of years, newbie developers will never know the struggle of formatting. But that's fine, I never got to know the struggle of maintaining big projects without git.

@ankush
Copy link
Member

ankush commented Mar 30, 2022

lets add isort also

https://github.com/frappe/erpnext/blob/ae3ef42df7d3251d5fcaebab4738ceede5354a83/.pre-commit-config.yaml#L35-L39

Also black/isort need a config that doesn't interfere with each other:

https://github.com/frappe/erpnext/blob/ae3ef42df7d3251d5fcaebab4738ceede5354a83/pyproject.toml#L1-L11

@codecov
Copy link

codecov bot commented Mar 30, 2022

Codecov Report

Merging #16453 (5cac78a) into develop (31d8717) will decrease coverage by 0.37%.
The diff coverage is 65.81%.

@@             Coverage Diff             @@
##           develop   #16453      +/-   ##
===========================================
- Coverage    53.61%   53.24%   -0.38%     
===========================================
  Files          746      749       +3     
  Lines        66328    67368    +1040     
  Branches      5573     5776     +203     
===========================================
+ Hits         35559    35867     +308     
- Misses       26920    27515     +595     
- Partials      3849     3986     +137     
Flag Coverage Δ
server 60.05% <65.81%> (-1.77%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@gavindsouza
Copy link
Collaborator

if we're moving to standard formatting, I think we should embrace standard black completely (spaces and all 😜)

@ankush
Copy link
Member

ankush commented Mar 30, 2022

if we're moving to standard formatting, I think we should embrace standard black completely (spaces and all 😜)

Not feasible for a few reasons:

  1. Makes diff sizes VERY large (practically every line changes). Also messes up with the way ignore-revs works (I started seeing my name appear in modules I've not touched after switching to spaces, probs because git isn't THAT smart when lots of things move around?)
  2. More importantly, IMO the goal of this change is to have consistency, tabs/space don't matter much.

@stale
Copy link

stale bot commented Apr 6, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed within 3 days if no further activity occurs, but it only takes a comment to keep a contribution alive :) Also, even if it is closed, you can always reopen the PR when you're ready. Thank you for contributing.

@stale stale bot added the inactive label Apr 6, 2022
@stale stale bot closed this Apr 9, 2022
@ankush ankush reopened this Apr 10, 2022
@stale stale bot removed the inactive label Apr 10, 2022
@surajshetty3416 surajshetty3416 marked this pull request as ready for review April 12, 2022 03:47
@surajshetty3416 surajshetty3416 requested a review from a team April 12, 2022 03:48
@surajshetty3416 surajshetty3416 marked this pull request as draft April 12, 2022 03:48
@surajshetty3416
Copy link
Member Author

Ignoring linter and sider for this. Maybe we can run sourcery throughout the codebase to make the fixes.

@surajshetty3416 surajshetty3416 marked this pull request as ready for review April 12, 2022 04:24
@surajshetty3416
Copy link
Member Author

shadrak98 pushed a commit to shadrak98/frappe that referenced this pull request Apr 18, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants