Skip to content

Commit 3c98b36

Browse files
author
Jonathon Belotti
authored
Fix #507 - Always run from WORKSPACE root in compile_pip_requirements update exe (#564)
1 parent 7d092c0 commit 3c98b36

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

python/pip_install/pip_compile.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,22 @@
4141
)
4242
copyfile(requirements_txt, requirements_out)
4343

44-
elif "BUILD_WORKING_DIRECTORY" in os.environ:
45-
os.chdir(os.environ['BUILD_WORKING_DIRECTORY'])
44+
elif "BUILD_WORKSPACE_DIRECTORY" in os.environ:
45+
# This value, populated when running under `bazel run`, is a path to the
46+
# "root of the workspace where the build was run."
47+
# This matches up with the values passed in via the macro using the 'rootpath' Make variable,
48+
# which for source files provides a path "relative to your workspace root."
49+
#
50+
# Changing to the WORKSPACE root avoids 'file not found' errors when the `.update` target is run
51+
# from different directories within the WORKSPACE.
52+
os.chdir(os.environ['BUILD_WORKSPACE_DIRECTORY'])
4653
else:
54+
err_msg = (
55+
"Expected to find BUILD_WORKSPACE_DIRECTORY (running under `bazel run`) or "
56+
"TEST_TMPDIR (running under `bazel test`) in environment."
57+
)
4758
print(
48-
"Expected to find BUILD_WORKING_DIRECTORY in environment",
59+
err_msg,
4960
file=sys.stderr,
5061
)
5162
sys.exit(1)

0 commit comments

Comments
 (0)