Skip to content

Commit e831327

Browse files
committed
Fix Bazel PEP 517 Build Environment Isolation and Sandbox Restrictions
1 parent f213412 commit e831327

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

setup.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,27 @@ def run(self):
9090
bazel_version = f.read().strip()
9191
os.environ["USE_BAZEL_VERSION"] = bazel_version
9292

93+
pythonpath = os.environ.get("PYTHONPATH", "")
94+
# Include sys.path entries to support PEP 517 isolated build environments
95+
sys_path_entries = os.pathsep.join([p for p in sys.path if p])
96+
if pythonpath:
97+
pythonpath = os.pathsep.join([pythonpath, sys_path_entries])
98+
else:
99+
pythonpath = sys_path_entries
100+
101+
bazel_args = [
102+
self._bazel_cmd,
103+
"run",
104+
"-c",
105+
"opt",
106+
f"--repo_env=PYTHON_BIN_PATH={sys.executable}",
107+
f"--repo_env=PYTHONPATH={pythonpath}",
108+
]
109+
bazel_args.extend(self._additional_build_options)
110+
bazel_args.append("//tensorflow_data_validation:move_generated_files")
111+
93112
subprocess.check_call(
94-
[self._bazel_cmd, "run", "-c", "opt"]
95-
+ self._additional_build_options
96-
+ ["//tensorflow_data_validation:move_generated_files"],
113+
bazel_args,
97114
# Bazel should be invoked in a directory containing bazel WORKSPACE
98115
# file, which is the root directory.
99116
cwd=os.path.dirname(os.path.realpath(__file__)),
@@ -225,7 +242,7 @@ def select_constraint(default, nightly=None, git_master=None):
225242
),
226243
"tfx-bsl"
227244
+ select_constraint(
228-
default="@git+https://github.com/vkarampudi/tfx-bsl@testing",
245+
default="@git+https://github.com/vkarampudi/tfx-bsl@master",
229246
nightly=">=1.18.0.dev",
230247
git_master="@git+https://github.com/tensorflow/tfx-bsl@master",
231248
),

third_party/python_configure.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ def _raw_exec(repository_ctx, cmdline):
205205
Returns:
206206
The 'exec_result' of repository_ctx.execute().
207207
"""
208-
return repository_ctx.execute(cmdline)
208+
env = {}
209+
for k in ["PYTHONPATH", "PYTHON_BIN_PATH", "PYTHON_LIB_PATH"]:
210+
if k in repository_ctx.os.environ:
211+
env[k] = repository_ctx.os.environ[k]
212+
return repository_ctx.execute(cmdline, environment = env)
209213

210214
def _read_dir(repository_ctx, src_dir):
211215
"""Returns a sorted list with all files in a directory.
@@ -476,6 +480,7 @@ _ENVIRONS = [
476480
BAZEL_SH,
477481
PYTHON_BIN_PATH,
478482
PYTHON_LIB_PATH,
483+
"PYTHONPATH",
479484
]
480485

481486
local_python_configure = repository_rule(

0 commit comments

Comments
 (0)