Skip to content

Commit 17d6bec

Browse files
committed
test feature powerset in CI
1 parent 8c13f76 commit 17d6bec

File tree

3 files changed

+102
-12
lines changed

3 files changed

+102
-12
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,19 @@ jobs:
480480
- run: python3 -m pip install --upgrade pip && pip install nox
481481
- run: python3 -m nox -s test-version-limits
482482

483+
test-feature-powerset:
484+
needs: [fmt]
485+
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || (github.event_name != 'pull_request' && github.ref != 'refs/heads/main') }}
486+
runs-on: ubuntu-latest
487+
steps:
488+
- uses: actions/checkout@v4
489+
- uses: Swatinem/rust-cache@v2
490+
continue-on-error: true
491+
- uses: dtolnay/rust-toolchain@stable
492+
- uses: taiki-e/install-action@cargo-hack
493+
- run: python3 -m pip install --upgrade pip && pip install nox
494+
- run: python3 -m nox -s test-feature-powerset
495+
483496
conclusion:
484497
needs:
485498
- fmt

Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,21 @@ nightly = []
107107
# This is mostly intended for testing purposes - activating *all* of these isn't particularly useful.
108108
full = [
109109
"macros",
110+
"gil-refs",
110111
# "multiple-pymethods", # TODO re-add this when MSRV is greater than 1.62
112+
"anyhow",
111113
"chrono",
112114
"chrono-tz",
113-
"num-bigint",
114-
"num-complex",
115-
"hashbrown",
116-
"smallvec",
117-
"serde",
118-
"indexmap",
119115
"either",
120-
"eyre",
121-
"anyhow",
122116
"experimental-inspect",
117+
"eyre",
118+
"hashbrown",
119+
"indexmap",
120+
"num-bigint",
121+
"num-complex",
123122
"rust_decimal",
123+
"serde",
124+
"smallvec",
124125
]
125126

126127
[workspace]

noxfile.py

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
import nox
1414
import nox.command
1515

16+
try:
17+
import tomllib as toml
18+
except ImportError:
19+
try:
20+
import toml
21+
except ImportError:
22+
toml = None
23+
1624
nox.options.sessions = ["test", "clippy", "rustfmt", "ruff", "docs"]
1725

1826

@@ -479,10 +487,7 @@ def check_changelog(session: nox.Session):
479487
def set_minimal_package_versions(session: nox.Session):
480488
from collections import defaultdict
481489

482-
try:
483-
import tomllib as toml
484-
except ImportError:
485-
import toml
490+
assert toml is not None, "requires Python 3.11 or toml package"
486491

487492
projects = (
488493
None,
@@ -593,6 +598,77 @@ def test_version_limits(session: nox.Session):
593598
_run_cargo(session, "check", env=env, expect_error=True)
594599

595600

601+
@nox.session(name="test-feature-powerset", venv_backend="none")
602+
def test_feature_powerset(session: nox.Session):
603+
assert toml is not None, "requires Python 3.11 or toml package"
604+
605+
with (PYO3_DIR / "Cargo.toml").open("rb") as cargo_toml_file:
606+
cargo_toml = toml.load(cargo_toml_file)
607+
608+
EXCLUDED_FROM_FULL = {
609+
"nightly",
610+
"extension-module",
611+
"full",
612+
"default",
613+
"auto-initialize",
614+
"generate-import-lib",
615+
"multiple-pymethods", # TODO add this after MSRV 1.62
616+
}
617+
618+
features = cargo_toml["features"]
619+
620+
full_feature = set(features["full"])
621+
expected_full_feature = {
622+
feature
623+
for feature in features
624+
if not feature.startswith("abi3") and feature not in EXCLUDED_FROM_FULL
625+
}
626+
627+
uncovered_features = expected_full_feature - full_feature
628+
629+
assert not uncovered_features, uncovered_features
630+
631+
experimental_features = {
632+
feature for feature in full_feature if feature.startswith("experimental-")
633+
}
634+
full_without_experimental = full_feature - experimental_features
635+
636+
abi3_version_features = {
637+
feature for feature in features if feature.startswith("abi3-")
638+
}
639+
640+
# justification: we always assume that feature within these groups are
641+
# mutually exclusive to simplify CI
642+
features_to_group = [
643+
full_without_experimental,
644+
experimental_features,
645+
]
646+
647+
features_to_skip = [
648+
*EXCLUDED_FROM_FULL,
649+
*abi3_version_features,
650+
]
651+
652+
comma_join = ",".join
653+
_run_cargo(
654+
session,
655+
"hack",
656+
"--feature-powerset",
657+
'--optional-deps=""',
658+
f'--skip="{comma_join(features_to_skip)}"',
659+
*(
660+
f"--group-features={comma_join(group)}"
661+
for group in features_to_group
662+
if len(group) > 1
663+
),
664+
"test",
665+
"--lib",
666+
"--tests",
667+
# don't run doctests here as it's unlikely they work with
668+
# literally every combination, and the link times will cripple CI
669+
)
670+
671+
596672
def _build_docs_for_ffi_check(session: nox.Session) -> None:
597673
# pyo3-ffi-check needs to scrape docs of pyo3-ffi
598674
_run_cargo(session, "doc", _FFI_CHECK, "-p", "pyo3-ffi", "--no-deps")

0 commit comments

Comments
 (0)