mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 14:01:56 +08:00
Compare commits
1 Commits
newsemanal
...
typecheck-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
984337c304 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -7,4 +7,5 @@ out/
|
||||
.mypy_cache/
|
||||
django-sources
|
||||
build/
|
||||
dist/
|
||||
dist/
|
||||
django-sources-typed/
|
||||
0
scripts/__init__.py
Normal file
0
scripts/__init__.py
Normal file
23
scripts/git_sources.py
Normal file
23
scripts/git_sources.py
Normal 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)
|
||||
@@ -1 +1 @@
|
||||
gitpython
|
||||
gitpython
|
||||
|
||||
22
scripts/typecheck_sources.py
Normal file
22
scripts/typecheck_sources.py
Normal 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
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user