Skip to content

Commit

Permalink
Add pre-push hook to run make quick_pyright (dagster-io#12115)
Browse files Browse the repository at this point in the history
### Summary & Motivation

Internal companion PR: dagster-io/internal#8967

This adds a pre-commit hook that runs scripts/run-pyright.py --diff on
push only.

On my machine it takes ~2 seconds for a commit with several updated
python files. Significantly slower than black/ruff but IMO worth it for
push.

In order to active this, devs must run `pre-commit install --hook-type
pre-push`.

### How I Tested These Changes

I tried to push a type error in this PR and the hook worked.
  • Loading branch information
smackesey authored Mar 27, 2024
1 parent 5ff8d78 commit e4c2b64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ repos:
entry: bash -c "cd docs && make mdx-format"
pass_filenames: false
files: ^docs/content

# We do not use pyright's provided pre-commit hook because we need the environment management
# supplied by `scripts/run-pyright.py`.
- id: pyright
name: pyright
entry: make quick_pyright
stages: [pre-push]
# This means pre-commit will not try to install a new environment for this hook. It relies on
# having a pre-existing `make` installed (and scripts/run-pyright.py).
language: system
pass_filenames: false
types: [python]
6 changes: 4 additions & 2 deletions scripts/run-pyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def get_params(args: argparse.Namespace) -> Params:
sys.exit(0)
else:
mode = "path"
targets = args.pathsBUILDKIT
targets = args.paths

venv_python = (
subprocess.run(["which", "python"], check=True, capture_output=True).stdout.decode().strip()
Expand Down Expand Up @@ -524,7 +524,9 @@ def print_report(result: RunResult) -> None:
normalize_env(env, params["rebuild"], params["update_pins"], params["venv_python"])
if params["skip_typecheck"]:
print("Successfully built environments. Skipping typecheck.")
if not params["skip_typecheck"]:
elif len(env_path_map) == 0:
print("No paths to analyze. Skipping typecheck.")
elif not params["skip_typecheck"]:
run_results = [
run_pyright(
env,
Expand Down

0 comments on commit e4c2b64

Please sign in to comment.