-
Notifications
You must be signed in to change notification settings - Fork 61
STYLE: Adding precommit hook and workflow for checking code quality #302
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
Open
Jahnvi Thakkar (jahnvi480)
wants to merge
2
commits into
main
Choose a base branch
from
jahnvi/linting_prehook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| --- | ||
| applyTo: "**" | ||
| --- | ||
|
|
||
| # Local formatting setup | ||
|
|
||
| When starting a local editing, commit, or push task, ensure this clone has the | ||
| repository's formatting hooks installed. Perform the setup when needed rather | ||
| than only suggesting commands. Do not install tools or change hooks for read-only | ||
| questions, code reviews, or CI jobs. Respect the user's tool permissions. | ||
|
|
||
| These instructions take effect when Copilot works on the checkout. Pulling | ||
| `main` does not execute them, and a developer without an active Copilot session | ||
| must follow the setup in `CONTRIBUTING.md`. | ||
|
|
||
| ## One-time setup per clone | ||
|
|
||
| 1. Use the project's Python 3.10+ virtual environment, or the devcontainer's | ||
| configured Python. If no development environment exists, follow | ||
| `.github/prompts/setup-dev-env.prompt.md` for virtual environment setup first. | ||
| Do not install into an unrelated or global Python environment. | ||
| 2. Check `python -m pre_commit --version` against `requirements-lint.txt`. | ||
| If the module is missing or its version differs, install it: | ||
|
|
||
| ```console | ||
| python -m pip install -r requirements-lint.txt | ||
| ``` | ||
|
|
||
| 3. Inspect `git config --get core.hooksPath` and resolve the default hook directory | ||
| with `git rev-parse --git-path hooks`; do not assume `.git` is a directory. | ||
| If a custom hooks path is configured, stop and ask how to integrate with it; | ||
| do not unset it or change global Git settings. Check that both `pre-commit` and | ||
| `pre-push` are pre-commit-managed hooks for `.pre-commit-config.yaml` and use a | ||
| valid development interpreter. If missing or stale, run: | ||
|
|
||
| ```console | ||
| python -m pre_commit install --install-hooks | ||
| ``` | ||
|
|
||
| Preserve existing hooks; do not use `--overwrite`. Verify both hooks were | ||
| installed. Skip reinstallation when they are already correct, including in | ||
| devcontainers. Reinstall if the development environment was recreated. | ||
| 4. Verify the configuration with `python -m pre_commit validate-config`. | ||
| Report installation, network, or environment errors explicitly. Do not claim | ||
| setup succeeded or bypass a failure. | ||
|
|
||
| ## Before commits, pushes, and PRs | ||
|
|
||
| - Let the commit hook format staged Python files. If it changes files, inspect | ||
| the diff and stage only the intended fixes before retrying. Preserve unrelated | ||
| and partially staged edits; never use `git add .` to accept formatter changes. | ||
| - Before pushing or opening a PR, run the same full-directory check as CI: | ||
|
|
||
| ```console | ||
| python -m pre_commit run black-check --all-files --hook-stage pre-push | ||
| ``` | ||
|
|
||
| - To fix reported formatting errors, use | ||
| `python -m pre_commit run black --all-files`. It returns nonzero when it changes | ||
| files. Review the diff, keep unrelated edits out of the commit, and rerun the | ||
| check. Do not commit or push unless the user has authorized those actions. | ||
| - Use the pinned hook environment, not a separately installed Black version. | ||
| These formatting checks need neither a native extension build nor SQL Server. | ||
| Keep other linters informational, matching the existing CI policy. | ||
| - Never use `--no-verify`, `SKIP`, or configuration changes to bypass the checks. | ||
| Local hooks cannot enforce PR creation or merging: requiring **Linting Summary** | ||
| in branch protection is a separate administrator action, not part of setup. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| minimum_pre_commit_version: '4.0.0' | ||
| default_install_hook_types: [pre-commit, pre-push] | ||
|
|
||
| repos: | ||
| - repo: https://github.com/psf/black-pre-commit-mirror | ||
| rev: 26.5.1 | ||
| hooks: | ||
| - id: black | ||
| name: Black (format staged Python files) | ||
| files: ^(mssql_python|tests)/.*\.pyi?$ | ||
| types_or: [python, pyi] | ||
| args: [--config=pyproject.toml] | ||
| stages: [pre-commit, manual] | ||
| - id: black | ||
| alias: black-check | ||
| name: Black (full CI formatting check) | ||
| args: [--config=pyproject.toml, --check, --diff, mssql_python, tests] | ||
| pass_filenames: false | ||
| always_run: true | ||
| stages: [pre-push] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Black is pinned in .pre-commit-config.yaml and installed in an isolated hook environment. | ||
| pre-commit==4.5.1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.