Skip to content

Commit

Permalink
[pyright] Add --skip-typecheck option (#20445)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Internal companion PR: dagster-io/internal#8681

Add `--skip-typecheck` option to `run-pyright-py` script and have `make
rebuild_pyright_pins` use it. This allows us to run `make
rebuild_pyright_pins` in CI to ensure env can be built from requirements
without caring about typecheck results.

## How I Tested These Changes

Ran `make rebuild_pyright_pins` locally, confirmed skip of typecheck
(results not included here).
  • Loading branch information
smackesey authored Mar 14, 2024
1 parent 739cf11 commit 47c2d85
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ install_pyright:
rebuild_pyright:
python scripts/run-pyright.py --all --rebuild

# Skip typecheck so that this can be used to test if all requirements can successfully be resolved
# in CI independently of typechecking.
rebuild_pyright_pins:
python scripts/run-pyright.py --update-pins
python scripts/run-pyright.py --update-pins --skip-typecheck

quick_pyright:
python scripts/run-pyright.py --diff
Expand Down
47 changes: 32 additions & 15 deletions scripts/run-pyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@
),
)

parser.add_argument(
"--skip-typecheck",
action="store_true",
default=False,
help=(
"Skip type checking, i.e. actually running pyright. This only makes sense when used together"
" with `--rebuild` or `--update-pins` to build an environment."
),
)

parser.add_argument(
"paths",
type=str,
Expand All @@ -113,6 +123,7 @@ class Params(TypedDict):
rebuild: bool
update_pins: bool
venv_python: str
skip_typecheck: bool


class Position(TypedDict):
Expand Down Expand Up @@ -222,6 +233,7 @@ def get_params(args: argparse.Namespace) -> Params:
rebuild=args.rebuild,
unannotated=args.unannotated,
venv_python=venv_python,
skip_typecheck=args.skip_typecheck,
)


Expand Down Expand Up @@ -346,7 +358,6 @@ def run_pyright(
pinned_deps: bool,
venv_python: str,
) -> RunResult:
normalize_env(env, rebuild, pinned_deps, venv_python)
with temp_pyright_config_file(env, unannotated) as config_path:
base_pyright_cmd = " ".join(
[
Expand Down Expand Up @@ -502,17 +513,23 @@ def print_report(result: RunResult) -> None:
env_path_map = map_paths_to_envs(params["targets"])
else:
env_path_map = {env: None for env in params["targets"]}
run_results = [
run_pyright(
env,
paths=env_path_map[env],
rebuild=params["rebuild"],
unannotated=params["unannotated"],
pinned_deps=params["update_pins"],
venv_python=params["venv_python"],
)
for env in env_path_map
]
merged_result = reduce(merge_pyright_results, run_results)
print_output(merged_result, params["json"])
sys.exit(merged_result["returncode"])

for env in env_path_map:
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"]:
run_results = [
run_pyright(
env,
paths=env_path_map[env],
rebuild=params["rebuild"],
unannotated=params["unannotated"],
pinned_deps=params["update_pins"],
venv_python=params["venv_python"],
)
for env in env_path_map
]
merged_result = reduce(merge_pyright_results, run_results)
print_output(merged_result, params["json"])
sys.exit(merged_result["returncode"])

0 comments on commit 47c2d85

Please sign in to comment.