Skip to content

Enable Black and other pre-commit hooks#744

Merged
freakboy3742 merged 25 commits into
beeware:mainfrom
danyeaw:black
May 27, 2022
Merged

Enable Black and other pre-commit hooks#744
freakboy3742 merged 25 commits into
beeware:mainfrom
danyeaw:black

Conversation

@danyeaw

@danyeaw danyeaw commented May 25, 2022

Copy link
Copy Markdown
Member

Enables pre-commit hooks for:

  • Black
  • isort
  • flake8
  • docformatter
  • pyupgrade

Adds a .git-blame-ignore-revs file for keeping git blame history. Removes flake8 from tox since it is part of the pre-commit hook. Updates the CI to include the pre-commit hooks as part of the beefore step.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@danyeaw danyeaw requested a review from freakboy3742 May 25, 2022 01:40

@freakboy3742 freakboy3742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks fairly straightforward - although there's already a merge conflict because of the formatting changes from #743 :-)

A couple of questions/clarifications inline about the specifics on how will play out in practice.

Comment thread .git-blame-ignore-revs
Comment thread .github/workflows/ci.yml Outdated
with:
python-version: "3.9"
- name: Lint with Pre-commit
uses: pre-commit/action@v2.0.3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this modify the code, or just run flake/black/etc checks and report an error if they haven't been run? If it does modify - who is the author of the commit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Exits with an error if pre-commit would need to modify a file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok; makes sense. However, we may need to restructure the CI workflow to accomodate. At present, the
"beefore" CI step is being run as a matrix, so there are 3 parallel tasks; this is running pre-commit on each of them, so a black violation is reported 3 times (see this test run on #746 for an example); and it looks like the failure is due to "town crier", rather than the underlying flake8 issue.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, moved pre-commit to the first action run, then beefore follows. Another option is, we could make use of https://pre-commit.ci. An advantage is it runs faster and automatically creates PRs with the pre-commit hooks are out of date. This could be a future thing we look at, though.

Comment thread .pre-commit-config.yaml
Comment thread CONTRIBUTING.md Outdated
@danyeaw

danyeaw commented May 25, 2022

Copy link
Copy Markdown
Member Author

Looks fairly straightforward - although there's already a merge conflict because of the formatting changes from #743 :-)

Merge conflict fixed, I rebased it!

@freakboy3742 freakboy3742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've had a chance to play around with pre-commit; I'm not in love with the onboarding experience (i.e., there's no way to signal to developers that they're missing something in their config) - but I'm not sure if there's anything we can do about that.

I've flagged two specific places that need some more attention in the specific configuration of pre-commit.

Comment thread .github/workflows/ci.yml Outdated
with:
python-version: "3.9"
- name: Lint with Pre-commit
uses: pre-commit/action@v2.0.3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok; makes sense. However, we may need to restructure the CI workflow to accomodate. At present, the
"beefore" CI step is being run as a matrix, so there are 3 parallel tasks; this is running pre-commit on each of them, so a black violation is reported 3 times (see this test run on #746 for an example); and it looks like the failure is due to "town crier", rather than the underlying flake8 issue.

Comment thread CONTRIBUTING.md Outdated
Comment thread .pre-commit-config.yaml
rev: v4.2.0
hooks:
- id: check-toml
- id: check-yaml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be worth auditing the full list of available hooks to see if there's anything else useful there. Other projects (like pyscript or pip) may be a good reference here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a few more for trailing whitespace, newline for end-of-file, etc. 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

One additional one that would be good would be to add mypy as a pre-commit hook, even if we aren't planning on or planning on adding incremental type hints. It's analysis found errors, and we could resolve these and make it part of a future PR.

@danyeaw

danyeaw commented May 26, 2022

Copy link
Copy Markdown
Member Author

Updates made! Hopefully I don't have to rebase this one again 🙏 😄

@codecov

codecov Bot commented May 27, 2022

Copy link
Copy Markdown

Codecov Report

Merging #744 (5dd2519) into main (b9c01e5) will decrease coverage by 0.00%.
The diff coverage is 95.21%.

Impacted Files Coverage Δ
src/briefcase/integrations/cookiecutter.py 0.00% <0.00%> (ø)
src/briefcase/integrations/git.py 55.55% <0.00%> (ø)
src/briefcase/exceptions.py 94.93% <50.00%> (ø)
src/briefcase/platforms/windows/msi.py 81.72% <55.55%> (ø)
src/briefcase/platforms/macOS/xcode.py 91.48% <85.71%> (ø)
src/briefcase/integrations/docker.py 92.50% <90.00%> (ø)
src/briefcase/platforms/iOS/xcode.py 94.73% <96.77%> (ø)
src/briefcase/integrations/android_sdk.py 98.99% <97.82%> (ø)
src/briefcase/cmdline.py 100.00% <100.00%> (ø)
src/briefcase/commands/base.py 98.20% <100.00%> (-0.03%) ⬇️
... and 19 more

@freakboy3742 freakboy3742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've made a couple of documentation tweaks and similar cosmetic cleanups, but otherwise, this looks good to go. There's a couple more pre-commit checks that might be worth integrating - but given the overhead associated with maintaining this patch (and the impact it has on other patches), I think it's worth landing as-is, and dealing with those additions as follow-on work.

Thanks for the prod (and the legwork) to make this happen!

Comment thread docs/how-to/contribute-code.rst Outdated
.. code-block:: doscon

C:\...>pip install tox
C:\...>pip install -r requirements.test.txt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

requirements.test.txt is the set of requirements installed by tox; it would be better for us to include tox in the dev requirements.

@danyeaw

danyeaw commented May 27, 2022

Copy link
Copy Markdown
Member Author

Thanks @freakboy3742 ! 🙌

@danyeaw danyeaw deleted the black branch May 27, 2022 19:18
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.

2 participants