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

ci: update python to use a matrix and have correct ordering #21775

Conversation

clintonsteiner
Copy link
Contributor

* Introduced in
  pantsbuild@e18484d#diff-8f5723a712281f34ef9e6ab0a15737801bd4c72972b4d95d83fb8e95f4eb7b6aR18
* Previously only using a single python version here
* Also, kept 3.7 and 3.8 in to be less controversial but those are both
  EOL and could be dropped off if we decide to keep other versions in
@huonw
Copy link
Contributor

huonw commented Dec 18, 2024

Thanks for contributing.

Could you spell out the motivation for doing this in more detail? The description currently describes what is happening, but not why we should do this.

You should also be aware that the test-suite will internally parametrize over different python versions.

  • Helper:
    def all_major_minor_python_versions(
    constraints: Iterable[str],
    ) -> tuple[_pytest.mark.structures.ParameterSet, ...]:
    """All major.minor Python versions used by the interpreter constraints.
    This is intended to be used with `@pytest.mark.parametrize()` to run a test with every relevant
    Python interpreter.
    """
    versions = InterpreterConstraints(constraints).partition_into_major_minor_versions(
    # Please update this when new stable Python versions are released to CI.
    interpreter_universe=["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
    )
    return tuple(
    pytest.param(
    version,
    marks=pytest.mark.skipif(
    not has_python_version(version),
    reason=f"Could not find python {version} on system. Skipping.",
    ),
    )
    for version in versions
    )
  • Example test:
    @pytest.mark.platform_specific_behavior
    @pytest.mark.parametrize(
    "major_minor_interpreter",
    all_major_minor_python_versions(["CPython>=3.8,<4"]),
    )
    def test_passing(rule_runner: PythonRuleRunner, major_minor_interpreter: str) -> None:
    rule_runner.write_files({f"{PACKAGE}/f.py": GOOD_FILE, f"{PACKAGE}/BUILD": "python_sources()"})
    tgt = rule_runner.get_target(Address(PACKAGE, relative_file_path="f.py"))
    assert_success(
    rule_runner,
    tgt,
    extra_args=[f"--python-interpreter-constraints=['=={major_minor_interpreter}.*']"],
    )

@clintonsteiner
Copy link
Contributor Author

Are we not double parametrized now? I admit I am looking more into pantsbuild and am no expert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants