WIP: fix scripts/typecheck_tests.py (#162)

* WIP: fix scripts/typecheck_tests.py

Exit non-zero if it fails to run.

Currently it fails on CI, but goes unnoticed:
https://travis-ci.com/typeddjango/django-stubs/jobs/235296115

* exit on unexpected rc, and output on stderr

* Fix

* scripts/mypy.ini: django_settings_module=scripts.django_tests_settings
This commit is contained in:
Daniel Hahler
2019-09-14 21:23:45 +02:00
committed by Maxim Kurnikov
parent 82e3aa5464
commit e3ea84143f
2 changed files with 23 additions and 7 deletions

View File

@@ -11,4 +11,4 @@ plugins =
mypy_django_plugin.main
[mypy.plugins.django-stubs]
django_settings_module = 'django_tests_settings'
django_settings_module = 'scripts.django_tests_settings'

View File

@@ -49,9 +49,6 @@ if __name__ == '__main__':
tests_root = repo_directory / 'tests'
global_rc = 0
# copy django settings to the tests_root directory
shutil.copy(PROJECT_DIRECTORY / 'scripts' / 'django_tests_settings.py', tests_root)
try:
mypy_options = ['--cache-dir', str(mypy_config_file.parent / '.mypy_cache'),
'--config-file', str(mypy_config_file)]
@@ -60,9 +57,28 @@ if __name__ == '__main__':
import distutils.spawn
mypy_executable = distutils.spawn.find_executable('mypy')
completed = subprocess.run([mypy_executable, *mypy_options], env={'PYTHONPATH': str(tests_root)},
stdout=subprocess.PIPE, cwd=str(tests_root))
sorted_lines = sorted(completed.stdout.decode().splitlines())
mypy_argv = [mypy_executable, *mypy_options]
completed = subprocess.run(
mypy_argv,
env={'PYTHONPATH': str(tests_root)},
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
rc = completed.returncode
stdout = completed.stdout.decode()
stderr = completed.stderr.decode()
if rc not in (0, 1) or stderr:
import shlex
cmd = " ".join(shlex.quote(s) for s in mypy_argv)
print("Failed to run {} (exitcode {})!".format(cmd, rc), file=sys.stderr)
if stderr:
print("=== Output on stderr: ===\n{}".format(stderr.rstrip("\n")))
if stdout:
print("=== Output on stdout: ===\n{}".format(stdout.rstrip("\n")))
sys.exit(rc or 1)
sorted_lines = sorted(stdout.splitlines())
for line in sorted_lines:
try:
module_name = line.split('/')[0]