-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Expand file tree
/
Copy pathcheck_types.py
More file actions
71 lines (62 loc) · 2.78 KB
/
check_types.py
File metadata and controls
71 lines (62 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Run ty type checking on specified directories.
Usage:
python utils/check_types.py src/transformers/utils src/transformers/generation
"""
import subprocess
import sys
CHECKER_CONFIG = {
"name": "types",
"label": "Type annotations",
# For contributors:
# - `check_args` below are the exact roots passed to `ty check`.
# - `cache_globs` here are only used by `utils/checkers.py` to decide when a
# previously clean `types` run can be reused from cache.
# ty follows imports *beyond* the checked roots, so the cache key must cover every source file
# that could change a result -- not just the explicitly-checked paths. We hash the whole package
# (plus the standalone .circleci target) so any source edit busts the cache and forces a
# re-check. Otherwise a cached pass could silently hide a newly-introduced error in a
# transitively-imported module that ty pulls in but that isn't one of the checked roots.
"cache_globs": [
"src/transformers/**/*.py",
".circleci/create_circleci_config.py",
],
"check_args": [
"src/transformers/_typing.py",
"src/transformers/cli",
"src/transformers/modeling_utils.py",
"src/transformers/utils",
"src/transformers/generation",
"src/transformers/pipelines/__init__.py",
"src/transformers/pipelines/feature_extraction.py",
"src/transformers/pipelines/image_feature_extraction.py",
"src/transformers/pipelines/video_classification.py",
"src/transformers/quantizers",
".circleci/create_circleci_config.py",
"src/transformers/dependency_versions_table.py",
"src/transformers/dependency_versions_check.py",
"src/transformers/conversion_mapping.py",
"src/transformers/time_series_utils.py",
"src/transformers/debug_utils.py",
"src/transformers/hyperparameter_search.py",
"src/transformers/pytorch_utils.py",
"src/transformers/file_utils.py",
"src/transformers/trainer_jit_checkpoint.py",
"src/transformers/trainer_optimizer.py",
],
"fix_args": None,
}
def main():
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <directory> [<directory> ...]")
sys.exit(1)
directories = sys.argv[1:]
print(f"Running ty check on: {', '.join(directories)}")
# `--error-on-warning` makes ty exit non-zero on warning-level diagnostics (e.g.
# possibly-missing-attribute), not just errors. Without it, warnings print but ty exits 0, so
# `make typing` and CI both pass and the issue is never caught before commit.
result = subprocess.run(
["ty", "check", "--respect-ignore-files", "--error-on-warning", "--exclude", "**/*_pb*", *directories],
)
sys.exit(result.returncode)
if __name__ == "__main__":
main()