Skip to content

Commit 29b7929

Browse files
committed
Deprecate setup.py stubcheck, provide alternative
1 parent 4ebed9e commit 29b7929

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

.github/workflows/build-ubuntu-sdist.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
if: matrix.os == 'ubuntu-22.04' # run stubtest only once
8181
run: |
8282
pip3 install mypy
83-
python3 setup.py stubcheck
83+
python3 buildconfig/stubs/stubcheck.py
8484
8585
# We upload the generated files under github actions assets
8686
- name: Upload sdist

buildconfig/stubs/stubcheck.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
A helper script to run mypy stubtest on the stubs directory
3+
"""
4+
5+
import os
6+
import subprocess
7+
import sys
8+
9+
from pathlib import Path
10+
11+
STUBS_BASE_DIR = Path(__file__).parent
12+
13+
14+
def main():
15+
"""
16+
Main entrypoint
17+
"""
18+
for stubtest in ([sys.executable, "-m", "mypy.stubtest"], ["stubtest"]):
19+
try:
20+
version = subprocess.run(
21+
[*stubtest, "--version"], capture_output=True, check=True, text=True
22+
).stdout.strip()
23+
except subprocess.CalledProcessError:
24+
continue
25+
26+
cmd = " ".join(stubtest)
27+
print(f"Using stubtest invokation: `{cmd}` (version: {version})")
28+
prev_dir = os.getcwd()
29+
try:
30+
os.chdir(STUBS_BASE_DIR)
31+
sys.exit(
32+
subprocess.run(
33+
[*stubtest, "pygame", "--allowlist", "mypy_allow_list.txt"]
34+
).returncode
35+
)
36+
finally:
37+
os.chdir(prev_dir)
38+
39+
print("ERROR: Could not find a valid stubtest program.")
40+
print("Make sure you have mypy installed.")
41+
sys.exit(1)
42+
43+
44+
if __name__ == "__main__":
45+
main()

setup.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -827,20 +827,12 @@ def run(self):
827827
runs mypy to build the docs.
828828
'''
829829
import subprocess
830-
import warnings
831-
832-
print("Using python:", sys.executable)
833-
834-
if shutil.which('mypy') is None:
835-
warnings.warn("Please install 'mypy' in your environment. (hint: 'python3 -m pip install mypy')")
836-
sys.exit(1)
837-
838-
os.chdir('buildconfig/stubs')
839830
command_line = [
840-
sys.executable,'-m','mypy.stubtest',"pygame","--allowlist","mypy_allow_list.txt"
831+
sys.executable, os.path.join("buildconfig", "stubs", "stubcheck.py")
841832
]
833+
print("WARNING: This command is deprecated and will be removed in the future.")
834+
print(f"Please use the following replacement: `{' '.join(command_line)}`\n")
842835
result = subprocess.run(command_line)
843-
os.chdir('../../')
844836
if result.returncode != 0:
845837
raise SystemExit("Stubcheck failed.")
846838

0 commit comments

Comments
 (0)