-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Run pylance tests in CI #5051
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
Run pylance tests in CI #5051
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
from typing import Iterable, List | ||
|
||
|
||
_WELL_KNOWN_FILE = Path("tests", "pyright_test.py") | ||
_PYRIGHT_COMMAND = ["npx", "-p", "[email protected]", "pyright"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be unpinned, if mypy is getting run at master (based on the requirements file, anyway)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see #5048 says this is probably just a starter PR, ignore me :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'd prefer a pinned version, so our CI doesn't start failing with no action. mypy is currently run from master because of transitional state around the recent directory reorganization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pinning mypy was discussed in #4332. I am still in favor of it (and we should also pin pytest while we are at it). As Jelle pointed out, using master has the disadvantage that build can fail for reasons unrelated to a PR. |
||
|
||
|
||
def main() -> None: | ||
assert_npm_is_installed() | ||
files = find_stubs() | ||
ret = run_pyright(files) | ||
sys.exit(ret) | ||
|
||
|
||
def assert_npm_is_installed() -> None: | ||
if not _WELL_KNOWN_FILE.exists(): | ||
print("pyright_test.py must be run from the typeshed root directory", file=sys.stderr) | ||
sys.exit(1) | ||
try: | ||
subprocess.run(["npx", "--version"]) | ||
except OSError: | ||
print("error running npx; is Node.js installed?", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
|
||
def find_stubs() -> List[str]: | ||
files: List[str] = [] | ||
for top in ["stdlib", "stubs"]: | ||
for dirpath, dirnames, filenames in os.walk(top): | ||
for fn in filenames: | ||
if fn.endswith(".pyi"): | ||
files.append(os.path.join(dirpath, fn)) | ||
try: | ||
dirnames.remove("@python2") | ||
except ValueError: | ||
pass | ||
return files | ||
|
||
|
||
def run_pyright(files: Iterable[str]) -> int: | ||
full_args = _PYRIGHT_COMMAND + list(files) | ||
return subprocess.run(full_args).returncode | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.