forked from pandas-dev/pandas-stubs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
153 lines (114 loc) · 3.68 KB
/
run.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from __future__ import annotations
from pathlib import Path
import subprocess
import sys
def mypy_src():
cmd = ["mypy", "pandas-stubs", "tests", "--no-incremental"]
subprocess.run(cmd, check=True)
def pyright_src():
cmd = ["pyright"]
subprocess.run(cmd, check=True)
def pyright_src_strict():
cmd = ["pyright", "--project", "pyrightconfig-strict.json"]
subprocess.run(cmd, check=True)
def pytest():
cmd = ["pytest", "--cache-clear"]
subprocess.run(cmd, check=True)
def style():
cmd = ["pre-commit", "run", "--all-files", "--verbose"]
subprocess.run(cmd, check=True)
def stubtest(allowlist: str = "", check_missing: bool = False):
cmd = [
sys.executable,
"-m",
"mypy.stubtest",
"pandas",
"--concise",
"--mypy-config-file",
"pyproject.toml",
]
if not check_missing:
cmd += ["--ignore-missing-stub"]
if allowlist:
cmd += ["--allowlist", allowlist]
subprocess.run(cmd, check=True)
def build_dist():
cmd = ["poetry", "build", "-f", "wheel"]
subprocess.run(cmd, check=True)
def install_dist():
path = sorted(Path("dist/").glob("pandas_stubs-*.whl"))[-1]
cmd = [sys.executable, "-m", "pip", "install", "--force-reinstall", str(path)]
subprocess.run(cmd, check=True)
def rename_src():
if Path(r"pandas-stubs").exists():
Path(r"pandas-stubs").rename("_pandas-stubs")
else:
raise FileNotFoundError("'pandas-stubs' folder does not exists.")
def mypy_dist():
cmd = ["mypy", "tests", "--no-incremental"]
subprocess.run(cmd, check=True)
def pyright_dist():
cmd = ["pyright", "tests"]
subprocess.run(cmd, check=True)
def uninstall_dist():
cmd = [sys.executable, "-m", "pip", "uninstall", "-y", "pandas-stubs"]
subprocess.run(cmd, check=True)
def restore_src():
if Path(r"_pandas-stubs").exists():
Path(r"_pandas-stubs").rename("pandas-stubs")
else:
raise FileNotFoundError("'_pandas-stubs' folder does not exists.")
def nightly_pandas():
cmd = [
sys.executable,
"-m",
"pip",
"install",
"--pre",
"--use-deprecated=legacy-resolver",
"--upgrade",
"--extra-index-url",
"https://pypi.anaconda.org/scientific-python-nightly-wheels/simple",
"pandas",
]
subprocess.run(cmd, check=True)
def _get_version_from_pyproject(program: str) -> str:
text = Path("pyproject.toml").read_text()
version_line = next(
line for line in text.splitlines() if line.startswith(f"{program} = ")
)
return version_line.split('"')[1]
def released_pandas():
version = _get_version_from_pyproject("pandas")
cmd = [sys.executable, "-m", "pip", "install", f"pandas=={version}"]
subprocess.run(cmd, check=True)
def nightly_mypy():
cmd = [
sys.executable,
"-m",
"pip",
"install",
"--upgrade",
"--find-links",
"https://github.com/mypyc/mypy_mypyc-wheels/releases/",
"mypy",
]
subprocess.run(cmd, check=True)
# ignore unused ignore errors
config_file = Path("pyproject.toml")
config_file.write_text(
config_file.read_text().replace(
"warn_unused_ignores = true", "warn_unused_ignores = false"
)
)
def released_mypy():
version = _get_version_from_pyproject("mypy")
cmd = [sys.executable, "-m", "pip", "install", f"mypy=={version}"]
subprocess.run(cmd, check=True)
# check for unused ignores again
config_file = Path("pyproject.toml")
config_file.write_text(
config_file.read_text().replace(
"warn_unused_ignores = false", "warn_unused_ignores = true"
)
)