From e4c2b64110acef512664b850748b24fcd8d4f528 Mon Sep 17 00:00:00 2001 From: Sean Mackesey Date: Wed, 27 Mar 2024 12:32:04 -0400 Subject: [PATCH] Add pre-push hook to run `make quick_pyright` (#12115) ### Summary & Motivation Internal companion PR: https://github.com/dagster-io/internal/pull/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. --- .pre-commit-config.yaml | 12 ++++++++++++ scripts/run-pyright.py | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d05d2b55d137..67dbdb27d9eac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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] diff --git a/scripts/run-pyright.py b/scripts/run-pyright.py index f3fb5c0cb496a..45585336f5edb 100755 --- a/scripts/run-pyright.py +++ b/scripts/run-pyright.py @@ -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() @@ -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,