mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-09 05:24:53 +08:00
Optimize tests typechecking script (#255)
* skip whole Django repo for tests typechecking * lint
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ pip-wheel-metadata/
|
|||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
/.envrc
|
/.envrc
|
||||||
/.direnv
|
/.direnv
|
||||||
|
django-sources/
|
||||||
@@ -11,19 +11,16 @@ jobs:
|
|||||||
- name: Typecheck Django 3.0 test suite with python 3.7
|
- name: Typecheck Django 3.0 test suite with python 3.7
|
||||||
python: 3.7
|
python: 3.7
|
||||||
script: |
|
script: |
|
||||||
pip install Django==3.0.*
|
|
||||||
python ./scripts/typecheck_tests.py --django_version=3.0
|
python ./scripts/typecheck_tests.py --django_version=3.0
|
||||||
|
|
||||||
- name: Typecheck Django 3.0 test suite with python 3.6
|
- name: Typecheck Django 3.0 test suite with python 3.6
|
||||||
python: 3.6
|
python: 3.6
|
||||||
script: |
|
script: |
|
||||||
pip install Django==3.0.*
|
|
||||||
python ./scripts/typecheck_tests.py --django_version=3.0
|
python ./scripts/typecheck_tests.py --django_version=3.0
|
||||||
|
|
||||||
- name: Typecheck Django 2.2 test suite with python 3.7
|
- name: Typecheck Django 2.2 test suite with python 3.7
|
||||||
python: 3.7
|
python: 3.7
|
||||||
script: |
|
script: |
|
||||||
pip install Django==2.2.*
|
|
||||||
python ./scripts/typecheck_tests.py --django_version=2.2
|
python ./scripts/typecheck_tests.py --django_version=2.2
|
||||||
|
|
||||||
- name: Mypy for plugin code
|
- name: Mypy for plugin code
|
||||||
|
|||||||
@@ -5,17 +5,17 @@ import sys
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List, Pattern, Union
|
from typing import Dict, List, Pattern, Tuple, Union
|
||||||
|
|
||||||
from git import Repo
|
from git import RemoteProgress, Repo
|
||||||
|
|
||||||
from scripts.enabled_test_modules import (
|
from scripts.enabled_test_modules import (
|
||||||
EXTERNAL_MODULES, IGNORED_ERRORS, IGNORED_MODULES, MOCK_OBJECTS,
|
EXTERNAL_MODULES, IGNORED_ERRORS, IGNORED_MODULES, MOCK_OBJECTS,
|
||||||
)
|
)
|
||||||
|
|
||||||
DJANGO_COMMIT_REFS = {
|
DJANGO_COMMIT_REFS: Dict[str, Tuple[str, str]] = {
|
||||||
'2.2': 'e8b0903976077b951795938b260211214ed7fe41',
|
'2.2': ('stable/2.2.x', 'e8b0903976077b951795938b260211214ed7fe41'),
|
||||||
'3.0': '7ec5962638144cbf4c2e47ea7d8dc02d1ce44394'
|
'3.0': ('stable/3.0.x', '7ec5962638144cbf4c2e47ea7d8dc02d1ce44394')
|
||||||
}
|
}
|
||||||
PROJECT_DIRECTORY = Path(__file__).parent.parent
|
PROJECT_DIRECTORY = Path(__file__).parent.parent
|
||||||
DJANGO_SOURCE_DIRECTORY = PROJECT_DIRECTORY / 'django-sources' # type: Path
|
DJANGO_SOURCE_DIRECTORY = PROJECT_DIRECTORY / 'django-sources' # type: Path
|
||||||
@@ -75,10 +75,21 @@ def replace_with_clickable_location(error: str, abs_test_folder: Path) -> str:
|
|||||||
return error.replace(raw_path, clickable_location)
|
return error.replace(raw_path, clickable_location)
|
||||||
|
|
||||||
|
|
||||||
def get_django_repo_object() -> Repo:
|
class ProgressPrinter(RemoteProgress):
|
||||||
|
def line_dropped(self, line: str) -> None:
|
||||||
|
print(line)
|
||||||
|
|
||||||
|
def update(self, op_code, cur_count, max_count=None, message=''):
|
||||||
|
print(self._cur_line)
|
||||||
|
|
||||||
|
|
||||||
|
def get_django_repo_object(branch: str) -> Repo:
|
||||||
if not DJANGO_SOURCE_DIRECTORY.exists():
|
if not DJANGO_SOURCE_DIRECTORY.exists():
|
||||||
DJANGO_SOURCE_DIRECTORY.mkdir(exist_ok=True, parents=False)
|
DJANGO_SOURCE_DIRECTORY.mkdir(exist_ok=True, parents=False)
|
||||||
return Repo.clone_from('https://github.com/django/django.git', DJANGO_SOURCE_DIRECTORY)
|
return Repo.clone_from('https://github.com/django/django.git', DJANGO_SOURCE_DIRECTORY,
|
||||||
|
progress=ProgressPrinter(),
|
||||||
|
branch=branch,
|
||||||
|
depth=100)
|
||||||
else:
|
else:
|
||||||
repo = Repo(DJANGO_SOURCE_DIRECTORY)
|
repo = Repo(DJANGO_SOURCE_DIRECTORY)
|
||||||
return repo
|
return repo
|
||||||
@@ -89,10 +100,13 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('--django_version', choices=['2.2', '3.0'], required=True)
|
parser.add_argument('--django_version', choices=['2.2', '3.0'], required=True)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
commit_sha = DJANGO_COMMIT_REFS[args.django_version]
|
# install proper Django version
|
||||||
repo = get_django_repo_object()
|
subprocess.check_call([sys.executable, '-m', 'pip', 'install', f'Django=={args.django_version}.*'])
|
||||||
|
|
||||||
|
branch, commit_sha = DJANGO_COMMIT_REFS[args.django_version]
|
||||||
|
repo = get_django_repo_object(branch)
|
||||||
if repo.head.commit.hexsha != commit_sha:
|
if repo.head.commit.hexsha != commit_sha:
|
||||||
repo.git.fetch('origin')
|
repo.remote('origin').fetch(branch, progress=ProgressPrinter(), depth=100)
|
||||||
repo.git.checkout(commit_sha)
|
repo.git.checkout(commit_sha)
|
||||||
|
|
||||||
mypy_config_file = (PROJECT_DIRECTORY / 'scripts' / 'mypy.ini').absolute()
|
mypy_config_file = (PROJECT_DIRECTORY / 'scripts' / 'mypy.ini').absolute()
|
||||||
|
|||||||
Reference in New Issue
Block a user