Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Aug 3, 2024
1 parent 76512e4 commit 366dbf8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
76 changes: 41 additions & 35 deletions tests/stubtest_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import subprocess
import sys
import tempfile
from pathlib import Path

from _utils import allowlist_stubtest_arguments, allowlists_path
Expand All @@ -21,41 +22,46 @@ def run_stubtest(typeshed_dir: Path) -> int:
# This is fine because we don't care about distutils and allowlist all errors from it
# https://github.com/python/typeshed/pull/10253#discussion_r1216712404
# https://github.com/python/typeshed/pull/9734
cmd = [
sys.executable,
"-m",
"mypy.stubtest",
"--check-typeshed",
"--custom-typeshed-dir",
str(typeshed_dir),
*allowlist_stubtest_arguments("stdlib"),
# Options for mypy check before the stubtest:
"--disable-error-code=overload-overlap",
]
if sys.version_info < (3, 10):
# As discussed in https://github.com/python/typeshed/issues/3693, we only aim for
# positional-only arg accuracy for python 3.10 and above.
cmd += ["--ignore-positional-only"]
print(" ".join(cmd), file=sys.stderr)
try:
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(
"\nNB: stubtest output depends on the Python version (and system) it is run with. "
+ "See README.md for more details.\n"
+ "NB: We only check positional-only arg accuracy for Python 3.10.\n"
+ f"\nCommand run was: {' '.join(cmd)}\n",
file=sys.stderr,
)
print("\n\n", file=sys.stderr)
print(
f'To fix "unused allowlist" errors, remove the corresponding entries from {allowlists_path("stdlib")}',
file=sys.stderr,
)
return e.returncode
else:
print("stubtest succeeded", file=sys.stderr)
return 0
with tempfile.NamedTemporaryFile("w+") as temp:
temp.write("[mypy]\ndisable_error_code = overload-overlap")
temp.flush()

cmd = [
sys.executable,
"-m",
"mypy.stubtest",
"--check-typeshed",
"--custom-typeshed-dir",
str(typeshed_dir),
*allowlist_stubtest_arguments("stdlib"),
# Options for mypy check before the stubtest:
"--mypy-config-file",
str(config_file),

Check failure on line 39 in tests/stubtest_stdlib.py

View workflow job for this annotation

GitHub Actions / Run pyright against the scripts and tests directories (Windows)

"config_file" is not defined (reportUndefinedVariable)

Check failure on line 39 in tests/stubtest_stdlib.py

View workflow job for this annotation

GitHub Actions / Run pyright against the scripts and tests directories (Windows)

Argument type is unknown   Argument corresponds to parameter "object" in function "__new__" (reportUnknownArgumentType)

Check failure on line 39 in tests/stubtest_stdlib.py

View workflow job for this annotation

GitHub Actions / Run pyright against the scripts and tests directories (Linux)

"config_file" is not defined (reportUndefinedVariable)

Check failure on line 39 in tests/stubtest_stdlib.py

View workflow job for this annotation

GitHub Actions / Run pyright against the scripts and tests directories (Linux)

Argument type is unknown   Argument corresponds to parameter "object" in function "__new__" (reportUnknownArgumentType)
]
if sys.version_info < (3, 10):
# As discussed in https://github.com/python/typeshed/issues/3693, we only aim for
# positional-only arg accuracy for python 3.10 and above.
cmd += ["--ignore-positional-only"]
print(" ".join(cmd), file=sys.stderr)
try:
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(
"\nNB: stubtest output depends on the Python version (and system) it is run with. "
+ "See README.md for more details.\n"
+ "NB: We only check positional-only arg accuracy for Python 3.10.\n"
+ f"\nCommand run was: {' '.join(cmd)}\n",
file=sys.stderr,
)
print("\n\n", file=sys.stderr)
print(
f'To fix "unused allowlist" errors, remove the corresponding entries from {allowlists_path("stdlib")}',
file=sys.stderr,
)
return e.returncode
else:
print("stubtest succeeded", file=sys.stderr)
return 0


if __name__ == "__main__":
Expand Down
7 changes: 6 additions & 1 deletion tests/stubtest_third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def run_stubtest(
ignore_missing_stub = ["--ignore-missing-stub"] if stubtest_settings.ignore_missing_stub else []
packages_to_check = [d.name for d in dist.iterdir() if d.is_dir() and d.name.isidentifier()]
modules_to_check = [d.stem for d in dist.iterdir() if d.is_file() and d.suffix == ".pyi"]

config_file = Path(tmp, "mypy.ini")
config_file.write_text("[mypy]\ndisable_error_code = overload-overlap")

stubtest_cmd = [
python_exe,
"-m",
Expand All @@ -111,7 +115,8 @@ def run_stubtest(
*modules_to_check,
*allowlist_stubtest_arguments(dist_name),
# Options for mypy check before the stubtest:
"--disable-error-code=overload-overlap",
"--mypy-config-file",
str(config_file),
]

stubs_dir = dist.parent
Expand Down

0 comments on commit 366dbf8

Please sign in to comment.