Skip to content

[py]: Introducing code formatting for a consistent code base #10761

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

Closed
wants to merge 16 commits into from

Conversation

symonk
Copy link
Member

@symonk symonk commented Jun 11, 2022

This makes some improvements to the python linting, Moving forward I would like to get the entire code base linted in a consistent manner for ease of maintenance and contributions.

As a proof of concept this pull request contains the following:

  • Upgraded github workflow to use a new tox -e linting recipe.
  • Black (very common python code formatter) enablement only on /py/test/* to prove things out.
  • Isort - Python import automatic sorter and manager
  • Having flake8 work in tandem with black & isort
  • introduction of a .git-blame-ignore-revs file for assisting git blame with sweeping changes required in future.
  • Some tweaks to the tox configurations (and increased the version of tox to latest, was outdated in CI).

Keeping things small and incremental right now to allow things to roll out gradually.

I would much rather have pre-commit implemented with this - why? edit: I know you all hate the idea of pre-commit 😄

  • It only applies to staged files with ease
  • Integrates into flow automatically on git commit <...>, enforcing client side compliance, the argument for not wanting it to get in the way is trivial, --no-verify works as normal AND SKIP=HOOKNAME git commit <...> gives individual hook skips!
  • Has tons more useful hooks for the code base
  • Does largely the same thing but better
  • Can be locked down to only apply to the python sub directory
  • Does not require managing some sort of bash/executable files to move into .git/hooks its all implicit

I have kept this over py/test/ for now, but I would really like to have it fully rolled out, the benefits are fantastic (imo).

Right now as-is the flow is unchanged, what once was tox -e flake8 should now be run as tox -e linting is now much more thorough and automatic at finding and correcting code formatting, this makes at most very minor changes to the underlying AST/BC so will not introduce any bugs into the code.

tox -e linting                                                                                                                                 ✔  py 🐍  22:34:53   
linting installed: black==22.3.0,click==8.1.3,flake8==4.0.1,importlib-metadata==4.2.0,isort==5.10.1,mccabe==0.6.1,mypy-extensions==0.4.3,pathspec==0.9.0,platformdirs==2.5.2,pycodestyle==2.8.0,pyflakes==2.4.0,tomli==2.0.1,typed-ast==1.5.4,typing_extensions==4.2.0,zipp==3.8.0
linting run-test-pre: PYTHONHASHSEED='98988857'
linting run-test: commands[0] | flake8 /home/si/workspaces/selenium/py
linting run-test: commands[1] | isort /home/si/workspaces/selenium/py/test --profile black
linting run-test: commands[2] | black /home/si/workspaces/selenium/py/test -l 120
All done! ✨ 🍰 ✨
111 files left unchanged.

@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2022

Codecov Report

Merging #10761 (1213514) into trunk (d1818d7) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##            trunk   #10761   +/-   ##
=======================================
  Coverage   52.24%   52.24%           
=======================================
  Files          84       84           
  Lines        5482     5482           
  Branches      272      272           
=======================================
  Hits         2864     2864           
  Misses       2346     2346           
  Partials      272      272           
Impacted Files Coverage Δ
py/selenium/webdriver/common/proxy.py 30.24% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@symonk symonk added the C-py Python Bindings label Jun 11, 2022
@symonk symonk changed the title [py]: Improvements to python code formatting [py]: Introducing code formatting for a consistent code base Jun 18, 2022
- If tox exits `0`, commit and push otherwise fix the newly introduced breakages.
- `flake8` requires manual fixes
- `black` will often rewrite the breakages automatically, however the files are unstaged and should staged again.
- `isort` will often rewrite the breakages automatically, however the files are unstaged and should staged again.
Copy link
Member Author

Choose a reason for hiding this comment

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

should be staged ...

@symonk
Copy link
Member Author

symonk commented Oct 1, 2022

I'm rolling this out gradually with a tox based opt in approach; Right now it wont be enforced in CI but it will be in future when things are proven out and consolidated.

@symonk symonk closed this Oct 1, 2022
@symonk symonk deleted the tox-linting-introduction branch October 1, 2022 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-py Python Bindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants