Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions src/typeshed_stats/_markdown_template.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ It works in conjunction with the
{{ stubtest_strictness.value }}

{% if not stubtest_is_skipped %}
{% set num_platforms = stubtest_platforms|length %}
{% set num_platforms = stubtest_ci_platforms|length %}
{% if num_platforms == 1 %}
In CI, stubtest is run on `{{ stubtest_platforms[0] }}` only.
In CI, stubtest is run on `{{ stubtest_ci_platforms[0] }}` only.
{% elif num_platforms == 2 %}
In CI, stubtest is run on `{{ stubtest_platforms[0] }}` and `{{ stubtest_platforms[1] }}`.
In CI, stubtest is run on `{{ stubtest_ci_platforms[0] }}` and `{{ stubtest_ci_platforms[1] }}`.
{% else %}
In CI, stubtest is run on `{{ stubtest_platforms[0] }}`, `{{ stubtest_platforms[1] }}` and `{{ stubtest_platforms[2] }}`.
In CI, stubtest is run on `{{ stubtest_ci_platforms[0] }}`, `{{ stubtest_ci_platforms[1] }}` and `{{ stubtest_ci_platforms[2] }}`.
{% endif %}
{% endif %}

Expand Down
27 changes: 17 additions & 10 deletions src/typeshed_stats/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"get_pyright_setting_for_path",
"get_stub_distribution_name",
"get_stubtest_allowlist_length",
"get_stubtest_platforms",
"get_stubtest_ci_platforms",
"get_stubtest_settings",
"get_stubtest_strictness",
"get_upload_status",
Expand Down Expand Up @@ -446,7 +446,12 @@ def get_stubtest_strictness(
... stdlib_setting = get_stubtest_strictness(
... "stdlib", typeshed_dir=typeshed
... )
... gdb_setting = get_stubtest_strictness("RPi.GPIO", typeshed_dir=typeshed)
... rpi_gpio_setting = get_stubtest_strictness(
... "RPi.GPIO", typeshed_dir=typeshed
... )
... tensorflow_setting = get_stubtest_strictness(
... "tensorflow", typeshed_dir=typeshed
... )
>>> stdlib_setting
StubtestStrictness.ERROR_ON_MISSING_STUB
>>> help(_)
Expand All @@ -455,21 +460,23 @@ def get_stubtest_strictness(
StubtestStrictness.ERROR_ON_MISSING_STUB
Objects missing from the stub cause stubtest to emit an error in typeshed's CI.
<BLANKLINE>
>>> gdb_setting
>>> rpi_gpio_setting
StubtestStrictness.SKIPPED
>>> tensorflow_setting
StubtestStrictness.SKIPPED
"""
if package_name == "stdlib":
return StubtestStrictness.ERROR_ON_MISSING_STUB
match _get_stubtest_config(package_name, typeshed_dir):
case {"skip": True}:
case {"skip": True} | {"ci_platforms": []}:
return StubtestStrictness.SKIPPED
case {"ignore_missing_stub": True}:
return StubtestStrictness.MISSING_STUBS_IGNORED
case _:
return StubtestStrictness.ERROR_ON_MISSING_STUB


def get_stubtest_platforms(
def get_stubtest_ci_platforms(
package_name: PackageName, *, typeshed_dir: Path | str
) -> list[str]:
"""Get the list of platforms on which [stubtest][] is run in typeshed's CI.
Expand All @@ -485,9 +492,9 @@ def get_stubtest_platforms(
given by [sys.platform][] at runtime.

Examples:
>>> from typeshed_stats.gather import tmpdir_typeshed, get_stubtest_platforms
>>> from typeshed_stats.gather import tmpdir_typeshed, get_stubtest_ci_platforms
>>> with tmpdir_typeshed() as typeshed:
... pywin_platforms = get_stubtest_platforms(
... pywin_platforms = get_stubtest_ci_platforms(
... "pywin32", typeshed_dir=typeshed
... )
>>> pywin_platforms
Expand All @@ -498,7 +505,7 @@ def get_stubtest_platforms(
match _get_stubtest_config(package_name, typeshed_dir):
case {"skip": True}:
return []
case {"platforms": list() as platforms}:
case {"ci_platforms": list() as platforms}:
return sorted(platforms)
case _:
return ["linux"]
Expand Down Expand Up @@ -569,7 +576,7 @@ class StubtestSettings:
"""Information on the settings under which [stubtest][] is run on a certain package."""

strictness: StubtestStrictness
platforms: list[str]
ci_platforms: list[str]
allowlist_length: int


Expand All @@ -588,7 +595,7 @@ def get_stubtest_settings(
"""
return StubtestSettings(
strictness=get_stubtest_strictness(package_name, typeshed_dir=typeshed_dir),
platforms=get_stubtest_platforms(package_name, typeshed_dir=typeshed_dir),
ci_platforms=get_stubtest_ci_platforms(package_name, typeshed_dir=typeshed_dir),
allowlist_length=get_stubtest_allowlist_length(
package_name, typeshed_dir=typeshed_dir
),
Expand Down
16 changes: 8 additions & 8 deletions src/typeshed_stats/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def stats_to_csv(stats: Sequence[PackageInfo | FileInfo]) -> str:
f"stubtest_{key}": val for key, val in info["stubtest_settings"].items()
}
del info["stubtest_settings"]
stubtest_platforms = info["stubtest_platforms"]
if not stubtest_platforms:
info["stubtest_platforms"] = "None"
stubtest_ci_platforms = info["stubtest_ci_platforms"]
if not stubtest_ci_platforms:
info["stubtest_ci_platforms"] = "None"
else:
info["stubtest_platforms"] = ";".join(stubtest_platforms)
info["stubtest_ci_platforms"] = ";".join(stubtest_ci_platforms)

fieldnames = converted_stats[0].keys()
csvfile = io.StringIO(newline="")
Expand Down Expand Up @@ -161,11 +161,11 @@ def _stats_from_csv(
converted_stat["annotation_stats"] = annotation_stats
converted_stat["stubtest_settings"] = stubtest_settings
if cls is PackageInfo:
stubtest_platforms = stubtest_settings["platforms"]
if stubtest_platforms == "None":
stubtest_settings["platforms"] = []
stubtest_ci_platforms = stubtest_settings["ci_platforms"]
if stubtest_ci_platforms == "None":
stubtest_settings["ci_platforms"] = []
else:
stubtest_settings["platforms"] = stubtest_platforms.split(";")
stubtest_settings["ci_platforms"] = stubtest_ci_platforms.split(";")
for k, v in PackageInfo.__annotations__.items():
if converted_stat[k] == "-" and v == (str | None):
converted_stat[k] = None
Expand Down
8 changes: 5 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ def random_PackageInfo() -> PackageInfo:
package_name = random_identifier()
stubtest_strictness = random.choice(list(StubtestStrictness))
if stubtest_strictness is StubtestStrictness.SKIPPED:
stubtest_platforms = []
stubtest_ci_platforms = []
else:
stubtest_platforms = [random.choice(["win32", "darwin", "linux"])]
stubtest_ci_platforms = [random.choice(["win32", "darwin", "linux"])]
return PackageInfo(
package_name=package_name,
stub_distribution_name=f"types-{package_name}",
Expand All @@ -245,7 +245,9 @@ def random_PackageInfo() -> PackageInfo:
extra_description=None,
number_of_lines=random.randint(10, 500),
package_status=random.choice(list(PackageStatus)),
stubtest_settings=StubtestSettings(stubtest_strictness, stubtest_platforms, 55),
stubtest_settings=StubtestSettings(
stubtest_strictness, stubtest_ci_platforms, 55
),
upload_status=random.choice(list(UploadStatus)),
pyright_setting=random.choice(list(PyrightSetting)),
annotation_stats=random_AnnotationStats(),
Expand Down
2 changes: 1 addition & 1 deletion tests/test__cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def _setup_and_teardown(
("get_pyright_setting_for_package", PyrightSetting.STRICT_ON_SOME_FILES),
("get_package_extra_description", None),
("get_upload_status", UploadStatus.UPLOADED),
("get_stubtest_platforms", ["linux"]),
("get_stubtest_ci_platforms", ["linux"]),
("get_stub_distribution_name", "types-foo"),
("get_stubtest_allowlist_length", 55),
]
Expand Down
11 changes: 6 additions & 5 deletions tests/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
get_pyright_setting_for_package,
get_stub_distribution_name,
get_stubtest_allowlist_length,
get_stubtest_platforms,
get_stubtest_ci_platforms,
get_stubtest_strictness,
get_upload_status,
get_upstream_url,
Expand Down Expand Up @@ -260,7 +260,8 @@ def test_get_stubtest_strictness_non_stdlib_no_stubtest_section(
"MISSING_STUBS_IGNORED",
id="ignore_missing_stub=true",
),
pytest.param("skip = true", "SKIPPED", id="skipped_stubtest"),
pytest.param("skip = true", "SKIPPED", id="explicitly_skipped_stubtest"),
pytest.param("ci_platforms = []", "SKIPPED", id="implicitly_skipped_stubtest"),
pytest.param(
"skip = true\nignore_missing_stub = true", "SKIPPED", id="skipped_stubtest2"
),
Expand Down Expand Up @@ -299,7 +300,7 @@ def test_get_stubtest_strictness_non_stdlib_with_stubtest_section(


def test_get_stubtest_platform_stdlib() -> None:
result = get_stubtest_platforms("stdlib", typeshed_dir=Path("."))
result = get_stubtest_ci_platforms("stdlib", typeshed_dir=Path("."))
assert len(result) == len(set(result))
assert set(result) == {"linux", "darwin", "win32"}
assert sorted(result) == result
Expand All @@ -310,7 +311,7 @@ def test_get_stubtest_platform_stdlib() -> None:
[
pytest.param("[tool.stubtest]\nskip = true", [], id="Skipped stubtest"),
pytest.param(
"[tool.stubtest]\nplatforms = ['win32', 'darwin']",
"[tool.stubtest]\nci_platforms = ['win32', 'darwin']",
["darwin", "win32"],
id="Platforms specified",
),
Expand All @@ -330,7 +331,7 @@ def test_get_stubtest_platform_non_stdlib(
maybe_stringize_path: Callable[[Path], Path | str],
) -> None:
write_metadata_text(typeshed, EXAMPLE_PACKAGE_NAME, metadata_contents)
actual_result = get_stubtest_platforms(
actual_result = get_stubtest_ci_platforms(
EXAMPLE_PACKAGE_NAME, typeshed_dir=maybe_stringize_path(typeshed)
)
assert actual_result == expected_result
Expand Down
6 changes: 3 additions & 3 deletions tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ def unusual_packages() -> list[PackageInfo]:
package_status=PackageStatus.UP_TO_DATE,
upload_status=UploadStatus.NOT_CURRENTLY_UPLOADED,
stubtest_settings=StubtestSettings(
strictness=StubtestStrictness.SKIPPED, platforms=[], allowlist_length=0
strictness=StubtestStrictness.SKIPPED, ci_platforms=[], allowlist_length=0
),
pyright_setting=PyrightSetting.STRICT,
annotation_stats=AnnotationStats(),
)
pkg2 = copy.deepcopy(pkg1)
pkg2.package_name = "stdlib"
pkg2.stubtest_settings.strictness = StubtestStrictness.ERROR_ON_MISSING_STUB
pkg2.stubtest_settings.platforms = ["win32", "darwin"]
pkg2.stubtest_settings.ci_platforms = ["win32", "darwin"]
pkg2.stub_distribution_name = "-"
pkg3 = copy.deepcopy(pkg2)
pkg3.stubtest_settings.platforms = ["win32", "darwin", "linux"]
pkg3.stubtest_settings.ci_platforms = ["win32", "darwin", "linux"]
return [pkg1, pkg2, pkg3]


Expand Down
Loading