Skip to content

CI: run stubtest #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ Here are the most important options. Fore more details, please use `poe --help`.
- Run only pytest: `poe pytest`
- Run only pre-commit: `poe style`
- Run tests against the installed stubs (this will install and uninstall the stubs): `poe test_dist`
- Optional: Run stubtest to compare the installed pandas-stubs against pandas (this will fail): `poe stubtest`. If you have created an allowlist to ignore certain errors: `poe stubtest path_to_the_allow_list`

These tests originally came from https://github.com/VirtusLab/pandas-stubs.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ script = "scripts.test.run:pyright_src"
help = "Run pyright on 'tests' using the installed stubs"
script = "scripts.test:test(dist=True, type_checker='pyright')"

[tool.poe.tasks.stubtest]
script = "scripts.test:stubtest(allowlist)"
help = "Run stubtest to compare the installed stubs against pandas"
args = [{ name = "allowlist", positional = true, default = "", required = false, help= "Path to an allowlist (optional)" }]


[tool.black]
Expand Down
3 changes: 3 additions & 0 deletions scripts/_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@ def run_job(steps: List[Step]) -> None:
end = time.perf_counter()
logger.success(f"End: '{step.name}', runtime: {end - start:.3f} seconds.")

if not failed:
__rollback_job(rollback_steps)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated: run the rollbacks when none of the steps failed (instead of having to specify the rollback as a step)


if failed:
sys.exit(1)
10 changes: 8 additions & 2 deletions scripts/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from copy import copy
from functools import partial
from typing import Literal

from scripts._job import run_job
Expand All @@ -10,8 +12,6 @@
_step.rename_src,
_step.mypy_dist,
_step.pyright_dist,
_step.uninstall_dist,
_step.restore_src,
]


Expand All @@ -33,3 +33,9 @@ def test(
steps = [step for step in steps if remove not in step.name]

run_job(steps)


def stubtest(allowlist: str):
stubtest = copy(_step.stubtest)
stubtest.run = partial(_step.stubtest.run, allowlist=allowlist)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit ugly but I didn't see another way with the current test structure.

run_job(_DIST_STEPS[:-2] + [stubtest])
5 changes: 3 additions & 2 deletions scripts/test/_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
pyright_dist = Step(
name="Run pyright on 'tests' using the installed stubs", run=run.pyright_dist
)
uninstall_dist = Step(name="Uninstall pandas-stubs", run=run.uninstall_dist)
restore_src = Step(name="Restore local stubs", run=run.restore_src)
stubtest = Step(
name="Run stubtest to compare the installed stubs against pandas", run=run.stubtest
)
17 changes: 17 additions & 0 deletions scripts/test/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import subprocess
import sys


def mypy_src():
Expand All @@ -22,6 +23,22 @@ def style():
subprocess.run(cmd, check=True)


def stubtest(allowlist: str = ""):
cmd = [
sys.executable,
"-m",
"mypy.stubtest",
"pandas",
"--concise",
"--ignore-missing-stub",
"--mypy-config-file",
"pyproject.toml",
]
if allowlist:
cmd += ["--allowlist", allowlist]
subprocess.run(cmd, check=True)


def build_dist():
cmd = ["poetry", "build", "-f", "wheel"]
subprocess.run(cmd, check=True)
Expand Down