From 984337c304a870901454a7d33506f913e61351eb Mon Sep 17 00:00:00 2001 From: Maxim Kurnikov Date: Wed, 30 Jan 2019 18:11:07 +0300 Subject: [PATCH] wip 1 --- .gitignore | 3 ++- scripts/__init__.py | 0 scripts/git_sources.py | 23 +++++++++++++++++++++ scripts/typecheck-tests-requirements.txt | 2 +- scripts/typecheck_sources.py | 22 ++++++++++++++++++++ scripts/typecheck_tests.py | 26 ++++++------------------ 6 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 scripts/__init__.py create mode 100644 scripts/git_sources.py create mode 100644 scripts/typecheck_sources.py diff --git a/.gitignore b/.gitignore index ffb8e8a..5f02b01 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ out/ .mypy_cache/ django-sources build/ -dist/ \ No newline at end of file +dist/ +django-sources-typed/ \ No newline at end of file diff --git a/scripts/__init__.py b/scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/git_sources.py b/scripts/git_sources.py new file mode 100644 index 0000000..e408b4d --- /dev/null +++ b/scripts/git_sources.py @@ -0,0 +1,23 @@ +# Django branch to typecheck against +from pathlib import Path + +from git import Repo + +DJANGO_BRANCH = 'stable/2.1.x' + +# Specific commit in the Django repository to check against +DJANGO_COMMIT_SHA = '03219b5f709dcd5b0bfacd963508625557ec1ef0' + +PROJECT_DIRECTORY = Path(__file__).parent.parent +REPO_DIRECTORY = PROJECT_DIRECTORY / 'django-sources' + + +def update_django_sources_repo(): + # clone Django repository, if it does not exist + if not REPO_DIRECTORY.exists(): + repo = Repo.clone_from('https://github.com/django/django.git', REPO_DIRECTORY) + else: + repo = Repo(REPO_DIRECTORY) + repo.remotes['origin'].pull(DJANGO_BRANCH) + + repo.git.checkout(DJANGO_COMMIT_SHA) diff --git a/scripts/typecheck-tests-requirements.txt b/scripts/typecheck-tests-requirements.txt index 5396f9c..59348f9 100644 --- a/scripts/typecheck-tests-requirements.txt +++ b/scripts/typecheck-tests-requirements.txt @@ -1 +1 @@ -gitpython \ No newline at end of file +gitpython diff --git a/scripts/typecheck_sources.py b/scripts/typecheck_sources.py new file mode 100644 index 0000000..758c276 --- /dev/null +++ b/scripts/typecheck_sources.py @@ -0,0 +1,22 @@ +import shutil +import sys +from pathlib import Path + +import retype + +from scripts.git_sources import PROJECT_DIRECTORY, REPO_DIRECTORY, update_django_sources_repo + +if __name__ == '__main__': + update_django_sources_repo() + + target_directory = PROJECT_DIRECTORY / 'django-sources-typed' + shutil.rmtree(target_directory, ignore_errors=True) + + retype.Config.incremental = True + for src_path in (REPO_DIRECTORY / 'django').glob('*'): + for file, error, exc_type, tb in retype.retype_path(src=Path(src_path), + pyi_dir=PROJECT_DIRECTORY / 'django-stubs', + targets=target_directory / 'django', + src_explicitly_given=True): + print(f'error: {file}: {error}', file=sys.stderr) + break diff --git a/scripts/typecheck_tests.py b/scripts/typecheck_tests.py index 26ffb9f..1a66cde 100644 --- a/scripts/typecheck_tests.py +++ b/scripts/typecheck_tests.py @@ -5,15 +5,10 @@ from contextlib import contextmanager from pathlib import Path from typing import Pattern -from git import Repo from mypy import build from mypy.main import process_options -# Django branch to typecheck against -DJANGO_BRANCH = 'stable/2.1.x' - -# Specific commit in the Django repository to check against -DJANGO_COMMIT_SHA = '03219b5f709dcd5b0bfacd963508625557ec1ef0' +from scripts.git_sources import PROJECT_DIRECTORY, REPO_DIRECTORY, update_django_sources_repo # Some errors occur for the test suite itself, and cannot be addressed via django-stubs. They should be ignored # using this constant. @@ -159,25 +154,16 @@ def check_with_mypy(abs_path: Path, config_file_path: Path) -> int: if __name__ == '__main__': - project_directory = Path(__file__).parent.parent - mypy_config_file = (project_directory / 'scripts' / 'mypy.ini').absolute() - repo_directory = project_directory / 'django-sources' - tests_root = repo_directory / 'tests' + mypy_tests_config_file = (PROJECT_DIRECTORY / 'scripts' / 'mypy.ini').absolute() + tests_root = REPO_DIRECTORY / 'tests' global_rc = 0 - # clone Django repository, if it does not exist - if not repo_directory.exists(): - repo = Repo.clone_from('https://github.com/django/django.git', repo_directory) - else: - repo = Repo(repo_directory) - repo.remotes['origin'].pull(DJANGO_BRANCH) - - repo.git.checkout(DJANGO_COMMIT_SHA) + update_django_sources_repo() for dirname in TESTS_DIRS: - abs_path = (project_directory / tests_root / dirname).absolute() + abs_path = (PROJECT_DIRECTORY / tests_root / dirname).absolute() print(f'Checking {abs_path.as_uri()}') - rc = check_with_mypy(abs_path, mypy_config_file) + rc = check_with_mypy(abs_path, mypy_tests_config_file) if rc != 0: global_rc = 1