-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
add mypy_selftest.py #1102
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
add mypy_selftest.py #1102
Changes from all commits
90b9f24
6c551e2
acf76bb
f5a558c
48e4fbc
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,27 @@ | ||
| #!/usr/bin/env python3 | ||
| """Script to run mypy's test suite against this version of typeshed.""" | ||
|
|
||
| from pathlib import Path | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
| import tempfile | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| with tempfile.TemporaryDirectory() as tempdir: | ||
| dirpath = Path(tempdir) | ||
| subprocess.run(['git', 'clone', '--depth', '1', 'git://github.com/python/mypy', | ||
| str(dirpath / 'mypy')], check=True) | ||
| subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r', | ||
| str(dirpath / 'mypy/test-requirements.txt')], check=True) | ||
|
Contributor
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. Let's create nice error messages for both.
Member
Author
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 feel like that's overengineering. People submitting changes to typeshed can probably read a Python stack trace, and there's a chance we make it harder to find the underlying error if we wrap it in our own error handling. |
||
| shutil.copytree('stdlib', str(dirpath / 'mypy/typeshed/stdlib')) | ||
| shutil.copytree('third_party', str(dirpath / 'mypy/typeshed/third_party')) | ||
|
Contributor
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. Those two guys can also raise
Member
Author
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. Same thing here. |
||
| try: | ||
| subprocess.run(['./runtests.py'], cwd=str(dirpath / 'mypy'), check=True) | ||
| except subprocess.CalledProcessError as e: | ||
| print('mypy tests failed', file=sys.stderr) | ||
| sys.exit(e.returncode) | ||
| else: | ||
| print('mypy tests succeeded', file=sys.stderr) | ||
| sys.exit(0) | ||
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.
nit: this is a bit of cargo culting. The point of
ifmainis testability. Putting all code in this block doesn't achieve that, you're just losing one level of indentation. I'd just remove it for our simple script. Otherwise, prefermain()functions, they don't create unexpected globals :-)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.
It also helps tools that try to import every file in a tree (e.g., stubgen). I prefer to just always avoid side-effects from importing files.