Skip to content
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

fix either feature conditional compilation, again #3834

Merged
merged 7 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,20 @@ 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
Copy link
Member Author

Choose a reason for hiding this comment

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

We could maybe extend to run this for each OS, but my expectation is that there's unlikely to be platform differences caught out by testing specific feature combinations. It seemed wasteful.

Similarly, if running a full test is too slow, we could downgrade to a check.

Copy link
Member

Choose a reason for hiding this comment

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

Similarly, if running a full test is too slow, we could downgrade to a check.

I think I'd prefer to start with a simple compile check instead of full test build. (The runtime is also where more platform-specific behaviour could lurk, and hence I'd say that single-platform-compile-check is a more natural working point.)

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- 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
1 change: 1 addition & 0 deletions newsfragments/3834.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix compilation failure with `either` feature enabled without `experimental-inspect` enabled.
84 changes: 80 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"
davidhewitt marked this conversation as resolved.
Show resolved Hide resolved

projects = (
None,
Expand Down Expand Up @@ -593,6 +598,77 @@ 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 = {
davidhewitt marked this conversation as resolved.
Show resolved Hide resolved
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
adamreichold marked this conversation as resolved.
Show resolved Hide resolved

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
adamreichold marked this conversation as resolved.
Show resolved Hide resolved
),
"test",
"--lib",
"--tests",
# don't run doctests here as it's unlikely they work with
# literally every combination, and the link times will cripple CI
)


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
10 changes: 8 additions & 2 deletions src/conversions/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ where
} else if let Ok(r) = obj.extract::<R>() {
Ok(Either::Right(r))
} else {
let err_msg = format!("failed to convert the value to '{}'", Self::type_input());
// TODO: it might be nice to use the `type_input()` name here once `type_input`
// is not experimental, rather than the Rust type names.
let err_msg = format!(
"failed to convert the value to 'Union[{}, {}]'",
std::any::type_name::<L>(),
std::any::type_name::<R>()
);
adamreichold marked this conversation as resolved.
Show resolved Hide resolved
Err(PyTypeError::new_err(err_msg))
}
}
Expand Down Expand Up @@ -134,7 +140,7 @@ mod tests {
assert!(err.is_instance_of::<PyTypeError>(py));
assert_eq!(
err.to_string(),
"TypeError: failed to convert the value to 'Union[int, float]'"
"TypeError: failed to convert the value to 'Union[i32, f32]'"
);

let obj_i = 42.to_object(py);
Expand Down
Loading