open-telemetry / opentelemetry-python

OpenTelemetry Python API and SDK
https://opentelemetry.io
Apache License 2.0
1.67k stars 570 forks source link

CONTRIBUTING: introduce pre-commit #3875

Closed xrmx closed 2 months ago

xrmx commented 2 months ago

Description

Instead of asking developers to run commands from tox manually let them configure pre-commit and run them automatically before committing (and pushing :).

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Does This PR Require a Contrib Repo Change?

Answer the following question based on these examples of changes that would require a Contrib Repo Change:

Checklist:

lzchen commented 2 months ago

Im not too familiar with pre-commit. What happens after user installs pre-commit install? Do they need to run anything else?

xrmx commented 2 months ago

Im not too familiar with pre-commit. What happens after user installs pre-commit install? Do they need to run anything else?

pre-commit will configure git hooks to run the tools before committing so if any of the tool will fail code will be fixed automatically (for black at least) but not committed. The idea is to catch the low hanging fruit issues (black, flake8 and isort) before pushing to github.

lzchen commented 2 months ago

Im not too familiar with pre-commit. What happens after user installs pre-commit install? Do they need to run anything else?

pre-commit will configure git hooks to run the tools before committing so if any of the tool will fail code will be fixed automatically (for black at least) but not committed. The idea is to catch the low hanging fruit issues (black, flake8 and isort) before pushing to github.

So the git hooks will be run when user chooses to git commit? Also curious if the commands will pick up the linting configuration we have for black, flake8 and isort in .flake8 and .isort.cfg and such.

xrmx commented 2 months ago

pre-commit will configure git hooks to run the tools before committing so if any of the tool will fail code will be fixed automatically (for black at least) but not committed. The idea is to catch the low hanging fruit issues (black, flake8 and isort) before pushing to github.

So the git hooks will be run when user chooses to git commit? Also curious if the commands will pick up the linting configuration we have for black, flake8 and isort in .flake8 and .isort.cfg and such.

yes, black and the linters will run when git commit is invoked. The configuration files we ship in the repo will be used since they are in the root of the project dir.

emdneto commented 2 months ago

@xrmx Did some tests and it's working fine:

git commit -m "test"

black....................................................................Failed
- hook id: black
- files were modified by this hook

reformatted test.py

All done! ✨ 🍰 ✨
1 file reformatted.

isort....................................................................Passed
flake8...................................................................Passed

Do you think it will be worth to have pre-commit in dev-requirements?

xrmx commented 2 months ago

@emdneto I have pre-commit installed globally but yeah, could make sense to have it in dev-requirements.