Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
331 stars 100 forks source link

Configure Precommit hooks with black and isort #1416

Closed vrdmr closed 5 months ago

vrdmr commented 5 months ago

Description

This change is to introduce precommit hooks to ensure same dev setup across the team.

  1. Added a new dev requirement - precommit-hooks
  2. Added a new config file .pre-commit-config.yaml and configured it with black and isort for now.
  3. Installing it first time on your box once it is setup
    azfuncpyworker on ξ‚  vameru/precommit-hook [$!] via venv311Arm64 via 🐍 system took 15s 
    ➜ pre-commit install
    [WARNING] The 'rev' field of repo 'https://github.com/psf/black' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.  Hint: `pre-commit autoupdate` often fixes this.
    pre-commit installed at .git/hooks/pre-commit
  4. When you do a commit, black is run automatically and it there are any updates, it'll change it and fail the commit to make you add it explicitly.
    
    azfuncpyworker on ξ‚  vameru/precommit-hook [$+] via venv311Arm64 via 🐍 system 
    ➜ git commit -m "test"
    black....................................................................Failed
    - hook id: black
    - files were modified by this hook

reformatted azure_functions_worker/constants.py

All done! ✨ 🍰 ✨ 1 file reformatted.

5. If you don't have any relevant files changed, the configurations won't run
```bash
azfuncpyworker on ξ‚  vameru/precommit-hook [$+] via venv311Arm64 via 🐍 system 
➜ git commit -m "Updating flake8 limits and add isort to precommit"
[INFO] Initializing environment for https://github.com/PyCQA/isort.
[INFO] Installing environment for https://github.com/PyCQA/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
black................................................(no files to check)Skipped
isort................................................(no files to check)Skipped
[vameru/precommit-hook 194ff51] Updating flake8 limits and add isort to precommit
 2 files changed, 6 insertions(+), 1 deletion(-)

The current black state is the following and will send another PR for this.

azfuncpyworker on ξ‚  vameru/precommit-hook [$] via venv311Arm64 via 🐍 system 
➜ pre-commit run --all-files
black....................................................................Failed
- hook id: black
- exit code: 123
- files were modified by this hook

reformatted azure_functions_worker/__main__.py
reformatted azure_functions_worker/bindings/__init__.py
...
reformatted tests/unittests/broken_functions/return_param_in/main.py
error: cannot format tests/unittests/broken_functions/syntax_error/main.py: Cannot parse: 6:15:     1 /  # noqa
reformatted tests/unittests/broken_functions/wrong_param_dir/main.py
...
reformatted tests/unittests/test_utilities.py
reformatted tests/utils/testutils.py

Oh no! πŸ’₯ πŸ’” πŸ’₯
306 files reformatted, 72 files left unchanged, 1 file failed to reformat.

Fixes #


PR information

Quality of Code and Contribution Guidelines

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (535b3d9) 85.31% compared to head (224a9b9) 85.87%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #1416 +/- ## ========================================== + Coverage 85.31% 85.87% +0.55% ========================================== Files 35 35 Lines 1968 1968 Branches 370 370 ========================================== + Hits 1679 1690 +11 + Misses 216 209 -7 + Partials 73 69 -4 ``` | [Flag](https://app.codecov.io/gh/Azure/azure-functions-python-worker/pull/1416/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) | Coverage Ξ” | | |---|---|---| | [unittests](https://app.codecov.io/gh/Azure/azure-functions-python-worker/pull/1416/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) | `85.82% <ΓΈ> (+0.55%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.