Skip to content

Commit

Permalink
test feature powerset in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Feb 21, 2024
1 parent 8c13f76 commit 670678b
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 12 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,19 @@ jobs:
- run: python3 -m pip install --upgrade pip && pip install nox
- run: python3 -m nox -s test-version-limits

test-feature-powerset:
needs: [fmt]
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || (github.event_name != 'pull_request' && github.ref != 'refs/heads/main') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
continue-on-error: true
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- run: python3 -m pip install --upgrade pip && pip install nox
- run: python3 -m nox -s test-feature-powerset

conclusion:
needs:
- fmt
Expand Down
17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,21 @@ nightly = []
# This is mostly intended for testing purposes - activating *all* of these isn't particularly useful.
full = [
"macros",
"gil-refs",
# "multiple-pymethods", # TODO re-add this when MSRV is greater than 1.62
"anyhow",
"chrono",
"chrono-tz",
"num-bigint",
"num-complex",
"hashbrown",
"smallvec",
"serde",
"indexmap",
"either",
"eyre",
"anyhow",
"experimental-inspect",
"eyre",
"hashbrown",
"indexmap",
"num-bigint",
"num-complex",
"rust_decimal",
"serde",
"smallvec",
]

[workspace]
Expand Down
82 changes: 78 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
import nox
import nox.command

try:
import tomllib as toml
except ImportError:
try:
import toml
except ImportError:
toml = None

nox.options.sessions = ["test", "clippy", "rustfmt", "ruff", "docs"]


Expand Down Expand Up @@ -479,10 +487,7 @@ def check_changelog(session: nox.Session):
def set_minimal_package_versions(session: nox.Session):
from collections import defaultdict

try:
import tomllib as toml
except ImportError:
import toml
assert toml is not None, "requires Python 3.11 or toml package"

projects = (
None,
Expand Down Expand Up @@ -593,6 +598,75 @@ def test_version_limits(session: nox.Session):
_run_cargo(session, "check", env=env, expect_error=True)


@nox.session(name="test-feature-powerset", venv_backend="none")
def test_feature_powerset(session: nox.Session):
assert toml is not None, "requires Python 3.11 or toml package"

with (PYO3_DIR / "Cargo.toml").open("rb") as cargo_toml_file:
cargo_toml = toml.load(cargo_toml_file)

EXCLUDED_FROM_FULL = {
"nightly",
"extension-module",
"full",
"default",
"auto-initialize",
"generate-import-lib",
"multiple-pymethods", # TODO add this after MSRV 1.62
}

features = cargo_toml["features"]

full_feature = set(features["full"])
expected_full_feature = {
feature
for feature in features
if not feature.startswith("abi3") and feature not in EXCLUDED_FROM_FULL
}

uncovered_features = expected_full_feature - full_feature

assert not uncovered_features, uncovered_features

experimental_features = {
feature for feature in full_feature if feature.startswith("experimental-")
}
full_without_experimental = full_feature - experimental_features

abi3_version_features = {
feature for feature in features if feature.startswith("abi3-")
}

# justification: we always assume that feature within these groups are
# mutually exclusive to simplify CI
features_to_group = [
full_without_experimental,
experimental_features,
]

features_to_skip = [
*EXCLUDED_FROM_FULL,
*abi3_version_features,
]

comma_join = ",".join
_run_cargo(
session,
"hack",
"--feature-powerset",
'--optional-deps=""',
f'--skip="{comma_join(features_to_skip)}"',
*(
f"--group-features={comma_join(group)}"
for group in features_to_group
if len(group) > 1
),
"test",
"--lib",
"--tests",
)


def _build_docs_for_ffi_check(session: nox.Session) -> None:
# pyo3-ffi-check needs to scrape docs of pyo3-ffi
_run_cargo(session, "doc", _FFI_CHECK, "-p", "pyo3-ffi", "--no-deps")
Expand Down

0 comments on commit 670678b

Please sign in to comment.