-
-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A RuleRunner subclass to set ICs in Python-related tests. (#18709)
Subsequent PRs will apply this in relevant tests, so we can remove one of the hacks introduced in #18627. I have applied this to several tests and verified that it works.
- Loading branch information
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Iterable, Mapping | ||
|
||
from pants.option.options_bootstrapper import OptionsBootstrapper | ||
from pants.testutil.rule_runner import RuleRunner | ||
|
||
|
||
class PythonRuleRunner(RuleRunner): | ||
"""Set common python rule-specific options.""" | ||
|
||
def create_options_bootstrapper( | ||
self, args: Iterable[str], env: Mapping[str, str] | None | ||
) -> OptionsBootstrapper: | ||
env = dict(env) if env else {} | ||
if ( | ||
not any("--python-interpreter-constraints=" in arg for arg in args) | ||
and "PANTS_PYTHON_INTERPRETER_CONSTRAINTS" not in env | ||
): | ||
# We inject the test ICs via env and not args, because in a handful of cases | ||
# we have different behavior when the option is set via flag. | ||
env["PANTS_PYTHON_INTERPRETER_CONSTRAINTS"] = "['>=3.7,<3.10',]" | ||
return super().create_options_bootstrapper(args=args, env=env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters