Skip to content
Merged
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
63 changes: 50 additions & 13 deletions tests/integration_python/pixi_build/test_examples_satisfiability.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
import tomllib
from pathlib import Path
from typing import TypeAlias, cast

import pytest

from .common import repo_root, verify_cli_command
from .common import current_platform, repo_root, verify_cli_command

Workspace: TypeAlias = dict[str, object]


def workspace_from_manifest(manifest_path: Path) -> Workspace | None:
manifest = cast(dict[str, object], tomllib.loads(manifest_path.read_text()))
if manifest_path.name == "pyproject.toml":
# Only consider pyproject.toml files that configure a pixi workspace
# to avoid testing non-pixi files.
tool = cast(dict[str, object], manifest.get("tool", {}))
pixi = cast(dict[str, object], tool.get("pixi", {}))
workspace = pixi.get("workspace")
elif manifest_path.name == "pixi.toml":
# Only consider pixi.toml files with a workspace section to avoid
# testing non-workspace member manifests.
workspace = manifest.get("workspace")
else:
return None

if isinstance(workspace, dict):
return cast(Workspace, workspace)
return None


def workspace_example_manifests() -> list[Path]:
Expand All @@ -14,25 +37,32 @@ def workspace_example_manifests() -> list[Path]:
"""
manifests: list[Path] = []
for manifest_path in sorted(repo_root().joinpath("examples").glob("**/p*.toml")):
manifest = tomllib.loads(manifest_path.read_text())
if manifest_path.name == "pyproject.toml":
# Only consider pyproject.toml files that configure a pixi workspace
# to avoid testing non-pixi files.
workspace = manifest.get("tool", {}).get("pixi", {}).get("workspace")
elif manifest_path.name == "pixi.toml":
# Only consider pixi.toml files with a workspace section to avoid
# testing non-workspace member manifests.
workspace = manifest.get("workspace")
else:
continue
if workspace is not None:
if workspace_from_manifest(manifest_path) is not None:
manifests.append(manifest_path)
return manifests


WORKSPACE_EXAMPLE_MANIFESTS = workspace_example_manifests()


def supports_current_platform(workspace: Workspace) -> bool:
"""Return whether the workspace supports the current runner platform."""
platforms = workspace.get("platforms")
if not isinstance(platforms, list):
return False

current = current_platform()
for platform in cast(list[object], platforms):
if platform == current:
return True
if isinstance(platform, dict):
rich_platform = cast(dict[str, object], platform)
if rich_platform.get("name") == current or rich_platform.get("platform") == current:
return True

return False


@pytest.mark.slow
@pytest.mark.parametrize(
"manifest_path",
Expand All @@ -47,6 +77,13 @@ def test_example_lock_file_satisfiability(pixi: Path, manifest_path: Path) -> No
`PIXI_BUILD_BACKEND_OVERRIDE` that is set by the session fixture in
`conftest.py`.
"""
workspace = workspace_from_manifest(manifest_path)
if workspace is None:
pytest.fail(f"{manifest_path} does not contain a pixi workspace")

if not supports_current_platform(workspace):
pytest.skip(f"example does not support current platform {current_platform()}")

verify_cli_command(
[
pixi,
Expand Down
Loading