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

Apply blackdoc to python source #4119

Merged
merged 2 commits into from Mar 11, 2023
Merged

Apply blackdoc to python source #4119

merged 2 commits into from Mar 11, 2023

Conversation

akaszynski
Copy link
Member

PyVista has adopted black, but we fail to implement this for our documentation or doc strings.

This PR implements blackdoc to reformat all Python code in our docstrings as a pre-commit.

Pinging @jorgepiloto because this is really cool and IMO works better than blacken-docs

@github-actions github-actions bot added the documentation Anything related to the documentation/website label Mar 11, 2023
tkoyama010
tkoyama010 previously approved these changes Mar 11, 2023
Copy link
Member

@tkoyama010 tkoyama010 left a comment

Choose a reason for hiding this comment

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

Excellent. I was always concerned that the docstring code was not formatted by black. This solves that!

@codecov
Copy link

codecov bot commented Mar 11, 2023

Codecov Report

Merging #4119 (84b326f) into main (a313b23) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #4119   +/-   ##
=======================================
  Coverage   95.56%   95.56%           
=======================================
  Files          95       95           
  Lines       20247    20247           
=======================================
  Hits        19350    19350           
  Misses        897      897           

@adeak
Copy link
Member

adeak commented Mar 11, 2023

Any chance that we can separate the black run from any other change (i.e. adding this to pre-commit) into separate PRs? I'd like to be able to skip the style PR's merge commit in the git blame. As usual.

@adeak
Copy link
Member

adeak commented Mar 11, 2023

To be clear the ideal situation would be to separate all autoformatting. If you changed anything manually and know what that was, that should also be moved along with the other changes (because we want to see all human actions in the blame). With one big commit that's probably not feasible though.

And along with the pre-commit addition we should add a check for this in CI, otherwise noncomforming commits will startvseeping back quick.

@tkoyama010
Copy link
Member

And along with the pre-commit addition we should add a check for this in CI, otherwise noncomforming commits will startvseeping back quick.

I guess the pre-commit error will stop CI, isn't it?

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: 'pip'
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files

@adeak
Copy link
Member

adeak commented Mar 11, 2023

Aaah, right! Thanks @tkoyama010 👍

@MatthewFlamm
Copy link
Contributor

This would be a good example where a merge commit would be better to preserve the commit history in a PR (one commit for each step here), but we have disabled this (for good reasons).

Another thought is that you could have two PRs, one for adding to our pre-commit (this will fail), the other for the changes. You would merge the first if the second passes and then merge them in one after the other.

A lot of extra work however.

@adeak
Copy link
Member

adeak commented Mar 11, 2023

Another thought is that you could have two PRs, one for adding to our pre-commit (this will fail), the other for the changes. You would merge the first if the second passes and then merge them in one after the other.

That's what I had in mind. First merge the autoformatting changes, then adding the pre-commit hook and any hypothetical manual changes needed.

A lot of extra work however.

Only if @akaszynski touched formatting beyond running blackdoc. The non-autoformat changes would be quite obvious otherwise. And we can only do this right once, now, or we'll be stuck with crap history.

It's of course possible that I'm the only one looking at git blames, in which case "sucks to be me" is another option :P

@akaszynski
Copy link
Member Author

Agree with separating this out. I didn't consider git blame, but when I do need it it's quite valuable for tracking down bugs.

@akaszynski akaszynski closed this Mar 11, 2023
@adeak
Copy link
Member

adeak commented Mar 11, 2023

You could keep most of the changes here, and just revert the few other changes. Whichever is less of a hassle.

@akaszynski
Copy link
Member Author

Ok @adeak. I went ahead and opened #4120. I would like to merge the changes from branch into main with and also add git blame --ignore-rev.

After the merge I will add the commit hash to the . git-blame-ignore-revs file.

See
https://akrabat.com/ignoring-revisions-with-git-blame/
https://github.blog/changelog/2022-03-24-ignore-commits-in-the-blame-view-beta/

@akaszynski
Copy link
Member Author

Please note that the changes here are entirely from the auto-formatter. Recommending merging this PR first and adding the ignore rev file to #4120.

@adeak
Copy link
Member

adeak commented Mar 11, 2023

Please note that the changes here are entirely from the auto-formatter. Recommending merging this PR first and adding the ignore rev file to #4120.

I'm on mobile for the next few hours still, but if this has autoformatting only then this is good to go. Any manual corrections would have to be put elsewhere anyway.

Adding the ignore-revs item in the follow-up is fine too. For the original blackening we had #2684.

Thanks a lot @akaszynski.

@MatthewFlamm
Copy link
Contributor

This sounds like a good plan

@akaszynski akaszynski merged commit a26a52d into main Mar 11, 2023
@akaszynski akaszynski deleted the docs/blackdoc branch March 11, 2023 20:47
@adeak
Copy link
Member

adeak commented Mar 11, 2023

Also pointing out for posterity that the changes here were made with an explicit exclusion of pyvista/plotting/charts.py, see #4120 (comment).

@akaszynski
Copy link
Member Author

I’ll work on the follow up PR and implement the changes before enforcing blackdox. Thanks for the comments, I’ll be less trigger happy…

@adeak
Copy link
Member

adeak commented Mar 11, 2023

I’ll be less trigger happy…

It's all good, I wouldn't have approved if I had insisted on taking a close look before merge :) In the worst case of changing the config and rerunning blackdoc on the whole codebase we can just have another autoformat PR and add two commits to the ignore-revs file. No harm done.

@akaszynski akaszynski mentioned this pull request Apr 30, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Anything related to the documentation/website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants