This commit is contained in:
Maxim Kurnikov
2019-01-30 18:11:07 +03:00
parent 322addf6b2
commit 984337c304
6 changed files with 54 additions and 22 deletions

3
.gitignore vendored
View File

@@ -7,4 +7,5 @@ out/
.mypy_cache/ .mypy_cache/
django-sources django-sources
build/ build/
dist/ dist/
django-sources-typed/

0
scripts/__init__.py Normal file
View File

23
scripts/git_sources.py Normal file
View File

@@ -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)

View File

@@ -1 +1 @@
gitpython gitpython

View File

@@ -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

View File

@@ -5,15 +5,10 @@ from contextlib import contextmanager
from pathlib import Path from pathlib import Path
from typing import Pattern from typing import Pattern
from git import Repo
from mypy import build from mypy import build
from mypy.main import process_options from mypy.main import process_options
# Django branch to typecheck against from scripts.git_sources import PROJECT_DIRECTORY, REPO_DIRECTORY, update_django_sources_repo
DJANGO_BRANCH = 'stable/2.1.x'
# Specific commit in the Django repository to check against
DJANGO_COMMIT_SHA = '03219b5f709dcd5b0bfacd963508625557ec1ef0'
# Some errors occur for the test suite itself, and cannot be addressed via django-stubs. They should be ignored # Some errors occur for the test suite itself, and cannot be addressed via django-stubs. They should be ignored
# using this constant. # using this constant.
@@ -159,25 +154,16 @@ def check_with_mypy(abs_path: Path, config_file_path: Path) -> int:
if __name__ == '__main__': if __name__ == '__main__':
project_directory = Path(__file__).parent.parent mypy_tests_config_file = (PROJECT_DIRECTORY / 'scripts' / 'mypy.ini').absolute()
mypy_config_file = (project_directory / 'scripts' / 'mypy.ini').absolute() tests_root = REPO_DIRECTORY / 'tests'
repo_directory = project_directory / 'django-sources'
tests_root = repo_directory / 'tests'
global_rc = 0 global_rc = 0
# clone Django repository, if it does not exist update_django_sources_repo()
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)
for dirname in TESTS_DIRS: 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()}') 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: if rc != 0:
global_rc = 1 global_rc = 1