Skip to content

Commit d6f26eb

Browse files
Specify python interpreter for pip_parse for ci dependencies
1 parent 7ef5f5a commit d6f26eb

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

WORKSPACE

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ load("@vaticle_dependencies//tool/swig:deps.bzl", swig_deps = "deps")
119119
swig_deps()
120120

121121
# Load //tool/common
122+
load("//python:python_versions.bzl", "create_interpreter_symlinks")
123+
create_interpreter_symlinks({"python39_symlink" : "python39"})
122124
load("@vaticle_dependencies//tool/common:deps.bzl", "vaticle_dependencies_ci_pip")
123-
vaticle_dependencies_ci_pip()
125+
vaticle_dependencies_ci_pip("@python39_symlink//:python")
124126
load("@vaticle_dependencies_ci_pip//:requirements.bzl", "install_deps")
125127
install_deps()
126128

dependencies/vaticle/repositories.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def vaticle_dependencies():
2121
git_repository(
2222
name = "vaticle_dependencies",
2323
remote = "https://github.com/krishnangovindraj/dependencies",
24-
commit = "60969be65a2e663db603ac9cca2cdec83a0b9efe", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
24+
commit = "247d9e38545c65ffc831d7ce1ed944af910fc251", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
2525
)
2626

2727
def vaticle_typeql():

python/python_versions.bzl

+45
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,48 @@ python_versions = [
5353
def register_all_toolchains():
5454
for version in python_versions:
5555
python_register_toolchains(name=version["name"], python_version=version["python_version"], ignore_root_user_error = True)
56+
57+
# Symlinks which allow us to use the right python interpreter
58+
def create_interpreter_symlinks(target_names_to_version):
59+
for (name, version) in target_names_to_version.items():
60+
python_interpreter_symlink(name=name, version=version)
61+
62+
OS_NAMES = ("mac", "win", "linux")
63+
OS_ARCHS = ("aarch64", "x86_64")
64+
(MAC, WIN, LINUX) = OS_NAMES
65+
(ARM64, X64) = OS_ARCHS
66+
67+
PYTHON_INTERPRETER_SUFFIXES = {
68+
(MAC, ARM64) : "aarch64-apple-darwin",
69+
(MAC, X64) : "x86_64-apple-darwin",
70+
(LINUX, ARM64): "aarch64-unknown-linux-gnu",
71+
(LINUX, X64): "x86_64-unknown-linux-gnu",
72+
(WIN, X64) : "x86_64-pc-windows-msvc",
73+
}
74+
75+
def _python_interpreter_symlink_impl(rctx):
76+
os_name = None
77+
for name in OS_NAMES:
78+
if name in rctx.os.name:
79+
os_name = name
80+
81+
if os_name == None:
82+
fail
83+
os_arch = rctx.os.arch
84+
interpreter_suffix = PYTHON_INTERPRETER_SUFFIXES.get((os_name, os_arch))
85+
86+
resolved_interpreter_label = Label("@" + rctx.attr.version + "_" + interpreter_suffix + "//:python")
87+
build_file_content = """
88+
package(default_visibility = ["//visibility:public"])
89+
exports_files(["python"])
90+
"""
91+
rctx.file("WORKSPACE", "workspace(name = \"%s\")"%rctx.attr.name)
92+
rctx.file("BUILD.bazel", content=build_file_content, executable=False)
93+
rctx.symlink(resolved_interpreter_label, "python")
94+
95+
python_interpreter_symlink = repository_rule(
96+
implementation= _python_interpreter_symlink_impl,
97+
attrs={
98+
"version" : attr.string(mandatory=True),
99+
}
100+
)

0 commit comments

Comments
 (0)