Skip to content

Commit 50b3702

Browse files
committed
wire in version to runtime env test
1 parent 2d021be commit 50b3702

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

MODULE.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ internal_dev_deps = use_extension(
9898
"internal_dev_deps",
9999
dev_dependency = True,
100100
)
101-
use_repo(internal_dev_deps, "buildkite_config", "wheel_for_testing")
101+
use_repo(
102+
internal_dev_deps,
103+
"buildkite_config",
104+
"rules_python_runtime_env",
105+
"wheel_for_testing",
106+
)
102107

103108
# Add gazelle plugin so that we can run the gazelle example as an e2e integration
104109
# test and include the distribution files.

python/private/internal_dev_deps.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
load("@bazel_ci_rules//:rbe_repo.bzl", "rbe_preconfig")
1717
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
18+
load(":runtime_env_repo.bzl", "runtime_env_repo")
1819

1920
def _internal_dev_deps_impl(mctx):
2021
_ = mctx # @unused
@@ -37,6 +38,7 @@ def _internal_dev_deps_impl(mctx):
3738
name = "buildkite_config",
3839
toolchain = "ubuntu1804-bazel-java11",
3940
)
41+
runtime_env_repo(name = "rules_python_runtime_env")
4042

4143
internal_dev_deps = module_extension(
4244
implementation = _internal_dev_deps_impl,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Internal setup to help the runtime_env toolchain."""
2+
3+
load("//python/private:repo_utils.bzl", "repo_utils")
4+
5+
def _runtime_env_repo_impl(rctx):
6+
pyenv = repo_utils.which_unchecked(rctx, "pyenv").binary
7+
if pyenv != None:
8+
pyenv_version_file = repo_utils.execute_checked(
9+
rctx,
10+
op = "GetPyenvVersionFile",
11+
arguments = [pyenv, "version-file"],
12+
).stdout.strip()
13+
rctx.watch(pyenv_version_file)
14+
15+
version = repo_utils.execute_checked(
16+
rctx,
17+
op = "GetPythonVersion",
18+
arguments = [
19+
"python3",
20+
"-I",
21+
"-c",
22+
"""import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")""",
23+
],
24+
environment = {
25+
# Prevent the user's current shell from influencing the result.
26+
# This envvar won't be present when a test is run.
27+
"PYENV_VERSION": None,
28+
},
29+
).stdout.strip()
30+
rctx.file("info.bzl", "PYTHON_VERSION = '{}'\n".format(version))
31+
rctx.file("BUILD.bazel", "")
32+
33+
runtime_env_repo = repository_rule(
34+
implementation = _runtime_env_repo_impl,
35+
)

tests/runtime_env_toolchain/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@rules_python_runtime_env//:info.bzl", "PYTHON_VERSION")
1516
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test")
1617
load("//tests/support:support.bzl", "CC_TOOLCHAIN")
1718
load(":runtime_env_toolchain_tests.bzl", "runtime_env_toolchain_test_suite")
@@ -30,6 +31,9 @@ py_reconfig_test(
3031
CC_TOOLCHAIN,
3132
],
3233
main = "toolchain_runs_test.py",
34+
# With bootstrap=script, the build version must match the runtime version
35+
# because the venv has the version in the lib/site-packages dir name.
36+
python_version = PYTHON_VERSION,
3337
# Our RBE has Python 3.6, which is too old for the language features
3438
# we use now. Using the runtime-env toolchain on RBE is pretty
3539
# questionable anyways.

0 commit comments

Comments
 (0)