Skip to content

Commit b5d2e7a

Browse files
authored
Rename poe tasks (#137)
* clean poe tasks * fix pytest * change help for test_dist * remove options from test_src * fix workflow * typo * pip force-reinstall * rename workflow and _step * add style * dist * fix * change help * make test_all the first entry * install the latest wheel * small changes
1 parent 0d50817 commit b5d2e7a

File tree

5 files changed

+93
-149
lines changed

5 files changed

+93
-149
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,17 @@ jobs:
3939
- name: Install project dependencies
4040
run: poetry install -vvv --no-root
4141

42-
- name: Run MyPy Against Source Code
42+
- name: Run mypy on 'tests' (using the local stubs) and on the local stubs
4343
run: poetry run poe mypy_src
4444

45-
- name: Run Pyright Against Source Code
45+
- name: Run pyright on 'tests' (using the local stubs) and on the local stubs
4646
run: poetry run poe pyright_src
4747

48-
- name: Run Pytest Against Source Code
49-
run: poetry run poe pytest_src
50-
51-
- name: Build Distribution
52-
run: poetry run poe build_dist
53-
54-
- name: Install Distribution
55-
run: poetry run poe install_dist
48+
- name: Run pytest
49+
run: poetry run poe pytest
5650

5751
- if: matrix.python-version == '3.8' && matrix.os == 'ubuntu-latest'
5852
uses: pre-commit/[email protected]
5953

60-
- name: Rename Source Code
61-
run: poetry run poe rename_src
62-
63-
- name: Run Pyright Against Distribution
64-
run: poetry run poe pyright_dist
65-
66-
- name: Run MyPy Against Distribution
67-
run: poetry run poe mypy_dist
54+
- name: Install pandas-stubs and run tests on the installed stubs
55+
run: poetry run poe test_dist

pyproject.toml

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -50,76 +50,64 @@ isort = ">=5.10.1"
5050
requires = ["poetry-core>=1.0.0"]
5151
build-backend = "poetry.core.masonry.api"
5252

53-
[tool.poe.tasks.test_src]
54-
help = "LOCAL Test | Run tests against source code version: \"poe test_src -p=<profile>\""
55-
script = "scripts.test:test_src(profile, clean_cache)"
53+
[tool.poe.tasks.test_all]
54+
help = "Run all tests"
55+
script = "scripts.test:test(clean_cache, src=True, dist=True)"
5656

57-
[[tool.poe.tasks.test_src.args]]
58-
help = "\"default\" (mypy + pyright) or \"pytest\" (pytest only) or \"full\" (mypy + pyright + pytest)"
59-
name = "profile"
60-
options = ["-p", "--profile"]
61-
default = "default"
57+
[[tool.poe.tasks.test_all.args]]
58+
help = "remove cache folders (mypy and pytest)"
59+
name = "clean-cache"
60+
options = ["-c", "--clean_cache"]
61+
default = false
62+
63+
[tool.poe.tasks.test_src]
64+
help = "Run local tests (includes 'mypy_src', 'pyright_src', 'pytest', and 'style')"
65+
script = "scripts.test:test(clean_cache, src=True)"
6266

6367
[[tool.poe.tasks.test_src.args]]
64-
help = "remove mypy and pytest cache folders"
68+
help = "remove cache folders (mypy and pytest)"
6569
name = "clean-cache"
6670
options = ["-c", "--clean_cache"]
6771
default = false
6872

6973
[tool.poe.tasks.test_dist]
70-
help = "Local Test | Run tests against distribuition version: \"poe test_dist\""
71-
script = "scripts.test:test_dist(clean_cache)"
74+
help = "Run tests on the installed stubs (includes 'mypy_dist' and 'pyright_dist')"
75+
script = "scripts.test:test(clean_cache, dist=True)"
7276

7377
[[tool.poe.tasks.test_dist.args]]
74-
help = "remove mypy and pytest cache folders"
78+
help = "remove cache folders (mypy and pytest)"
7579
name = "clean-cache"
7680
options = ["-c", "--clean_cache"]
7781
default = false
7882

79-
[tool.poe.tasks.test_all]
80-
help = "Local Test | Run tests against source code and distribuition version: \"poe test_all\""
81-
script = "scripts.test:test_all(clean_cache)"
83+
[tool.poe.tasks.pytest]
84+
help = "Run pytest"
85+
script = "scripts.test.run:pytest"
8286

83-
[[tool.poe.tasks.test_all.args]]
84-
help = "remove mypy and pytest cache folders"
85-
name = "clean-cache"
86-
options = ["-c", "--clean_cache"]
87-
default = false
87+
[tool.poe.tasks.style]
88+
help = "Run pre-commit"
89+
script = "scripts.test.run:style"
8890

8991
[tool.poe.tasks.mypy_src]
90-
help = "CI Test | Run mypy against source code"
92+
help = "Run mypy on 'tests' (using the local stubs) and on the local stubs"
9193
script = "scripts.test.run:mypy_src"
9294

95+
[tool.poe.tasks.mypy_dist]
96+
help = "Run mypy on 'tests' using the installed stubs"
97+
script = "scripts.test:test(clean_cache=False, dist=True, type_checker='mypy')"
98+
9399
[tool.poe.tasks.pyright_src]
94-
help = "CI Test | Run pyright against source code"
100+
help = "Run pyright on 'tests' (using the local stubs) and on the local stubs"
95101
script = "scripts.test.run:pyright_src"
96102

97-
[tool.poe.tasks.pytest_src]
98-
help = "CI Test | Run pytest against source code"
99-
script = "scripts.test.run:pytest_src"
100-
101-
[tool.poe.tasks.build_dist]
102-
help = "CI Test | Build distribuition"
103-
script = "scripts.test.run:build_dist"
104-
105-
[tool.poe.tasks.install_dist]
106-
help = "CI Test | Install distribuition"
107-
script = "scripts.test.run:install_dist"
103+
[tool.poe.tasks.pyright_dist]
104+
help = "Run pyright on 'tests' using the installed stubs"
105+
script = "scripts.test:test(clean_cache=False, dist=True, type_checker='pyright')"
108106

109-
[tool.poe.tasks.rename_src]
110-
help = "CI Test | Rename source code"
111-
script = "scripts.test.run:rename_src"
112107

113-
[tool.poe.tasks.mypy_dist]
114-
help = "CI Test | Run mypy against distribuition"
115-
script = "scripts.test.run:mypy_dist"
116-
117-
[tool.poe.tasks.pyright_dist]
118-
help = "CI Test | Run pyright against distribuition"
119-
script = "scripts.test.run:pyright_dist"
120108

121109
[tool.black]
122-
target-version = ['py38', 'py39']
110+
target-version = ['py38']
123111

124112
[tool.isort]
125113
known_pre_libs = "pandas._config"

scripts/test/__init__.py

Lines changed: 30 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,40 @@
1+
from typing import Literal
2+
13
from scripts._job import run_job
24
from scripts.test import _step
35

4-
5-
def test_src(profile: str, clean_cache: bool = False):
6-
steps = []
7-
if clean_cache:
8-
steps.extend(
9-
[
10-
_step.clean_mypy_cache,
11-
_step.clean_pytest_cache,
12-
]
13-
)
14-
15-
if profile in (None, "", "default"):
16-
steps.extend([_step.mypy_src, _step.pyright_src])
17-
elif profile == "pytest":
18-
steps.extend([_step.pytest_src])
19-
elif profile == "style":
20-
steps.extend([_step.style_src])
21-
elif profile == "full":
22-
steps.extend(
23-
[_step.mypy_src, _step.pyright_src, _step.pytest_src, _step.style_src]
24-
)
25-
else:
26-
raise ModuleNotFoundError("Profile not found!")
27-
28-
run_job(steps)
29-
30-
31-
def test_dist(clean_cache: bool = False):
6+
_CACHE_STEPS = [_step.clean_mypy_cache, _step.clean_pytest_cache]
7+
_SRC_STEPS = [_step.mypy_src, _step.pyright_src, _step.pytest, _step.style]
8+
_DIST_STEPS = [
9+
_step.build_dist,
10+
_step.install_dist,
11+
_step.rename_src,
12+
_step.mypy_dist,
13+
_step.pyright_dist,
14+
_step.uninstall_dist,
15+
_step.restore_src,
16+
]
17+
18+
19+
def test(
20+
clean_cache: bool = False,
21+
src: bool = False,
22+
dist: bool = False,
23+
type_checker: Literal["", "mypy", "pyright"] = "",
24+
):
3225
steps = []
3326
if clean_cache:
34-
steps.extend(
35-
[
36-
_step.clean_mypy_cache,
37-
_step.clean_pytest_cache,
38-
]
39-
)
27+
steps.extend(_CACHE_STEPS)
4028

41-
steps.extend(
42-
[
43-
_step.build_dist,
44-
_step.install_dist,
45-
_step.rename_src,
46-
_step.mypy_dist,
47-
_step.pyright_dist,
48-
_step.uninstall_dist,
49-
_step.restore_src,
50-
]
51-
)
52-
53-
run_job(steps)
29+
if src:
30+
steps.extend(_SRC_STEPS)
5431

32+
if dist:
33+
steps.extend(_DIST_STEPS)
5534

56-
def test_all(clean_cache: bool = False):
57-
steps = []
58-
if clean_cache:
59-
steps.extend(
60-
[
61-
_step.clean_mypy_cache,
62-
_step.clean_pytest_cache,
63-
]
64-
)
65-
66-
steps.extend(
67-
[
68-
_step.mypy_src,
69-
_step.pyright_src,
70-
_step.pytest_src,
71-
_step.style_src,
72-
_step.build_dist,
73-
_step.install_dist,
74-
_step.rename_src,
75-
_step.mypy_dist,
76-
_step.pyright_dist,
77-
_step.uninstall_dist,
78-
_step.restore_src,
79-
]
80-
)
35+
if type_checker:
36+
# either pyright or mypy
37+
remove = "mypy" if type_checker == "pyright" else "pyright"
38+
steps = [step for step in steps if remove not in step.name]
8139

8240
run_job(steps)

scripts/test/_step.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@
33

44
clean_mypy_cache = Step(name="Clean mypy cache", run=run.clean_mypy_cache)
55
clean_pytest_cache = Step(name="Clean pytest cache", run=run.clean_pytest_cache)
6-
mypy_src = Step(name="Run Mypy Against Source Code", run=run.mypy_src)
7-
pyright_src = Step(name="Run Pyright Against Source Code", run=run.pyright_src)
8-
pytest_src = Step(name="Run Pytest Against Source Code", run=run.pytest_src)
9-
style_src = Step(name="Run pre-commit Against Source Code", run=run.style_src)
10-
build_dist = Step(name="Build Dist", run=run.build_dist)
6+
mypy_src = Step(
7+
name="Run mypy on 'tests' (using the local stubs) and on the local stubs",
8+
run=run.mypy_src,
9+
)
10+
pyright_src = Step(
11+
name="Run pyright on 'tests' (using the local stubs) and on the local stubs",
12+
run=run.pyright_src,
13+
)
14+
pytest = Step(name="Run pytest", run=run.pytest)
15+
style = Step(name="Run pre-commit", run=run.style)
16+
build_dist = Step(name="Build pandas-stubs", run=run.build_dist)
1117
install_dist = Step(
12-
name="Install Dist", run=run.install_dist, rollback=run.uninstall_dist
18+
name="Install pandas-stubs", run=run.install_dist, rollback=run.uninstall_dist
1319
)
1420
rename_src = Step(
15-
name="Rename Source Code Folder",
21+
name="Rename local stubs",
1622
run=run.rename_src,
1723
rollback=run.restore_src,
1824
)
19-
mypy_dist = Step(name="Run MyPy Against Dist", run=run.mypy_dist)
20-
pyright_dist = Step(name="Run Pyright Against Dist", run=run.pyright_dist)
21-
uninstall_dist = Step(name="Uninstall Dist", run=run.uninstall_dist)
22-
restore_src = Step(name="Restore Source Code", run=run.restore_src)
25+
mypy_dist = Step(
26+
name="Run mypy on 'tests' using the installed stubs", run=run.mypy_dist
27+
)
28+
pyright_dist = Step(
29+
name="Run pyright on 'tests' using the installed stubs", run=run.pyright_dist
30+
)
31+
uninstall_dist = Step(name="Uninstall pandas-stubs", run=run.uninstall_dist)
32+
restore_src = Step(name="Restore local stubs", run=run.restore_src)

scripts/test/run.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def pyright_src():
1313
subprocess.run(cmd, check=True)
1414

1515

16-
def pytest_src():
16+
def pytest():
1717
cmd = ["pytest"]
1818
subprocess.run(cmd, check=True)
1919

2020

21-
def style_src():
21+
def style():
2222
cmd = ["pre-commit", "run", "--all-files", "--verbose"]
2323
subprocess.run(cmd, check=True)
2424

@@ -29,8 +29,8 @@ def build_dist():
2929

3030

3131
def install_dist():
32-
path = next(Path("dist/").glob("*.whl"))
33-
cmd = ["pip", "install", str(path)]
32+
path = sorted(Path("dist/").glob("pandas_stubs-*.whl"))[-1]
33+
cmd = ["pip", "install", "--force-reinstall", str(path)]
3434
subprocess.run(cmd, check=True)
3535

3636

0 commit comments

Comments
 (0)