-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An attempt to run Python exe in a more hermetic way #863
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,16 @@ def _python_repository_impl(rctx): | |
"share/**", | ||
] | ||
|
||
python_wrapper = "python_wrapper.sh" | ||
python_wrapper_content = """\ | ||
#!/bin/bash | ||
|
||
set -o errexit -o nounset -o pipefail | ||
|
||
external/{repo_name}/{python_bin} -B -s -I "$@" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the "external/" part here might depend on if a flag is set? I think you can drop the "external/" part, but not 100% sure. Actually, what's the CWD when this is invoked? The relative path here means it would have to be the runfiles root. But what is doing that chdir()? (Sorry if I missed it) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing this out. If /home/mvukov/.cache/bazel/_bazel_mvukov/bc9f8eb0563a76ddb0353ce7869ddf8d/execroot/hermetic_python/bazel-out/k8-fastbuild/bin/demo.runfiles/hermetic_python where hermetic_python is the repo name. When
I'm not doing any chdir in this PR :) Can you be a bit more specific? |
||
""".format(repo_name = rctx.name, python_bin = python_bin) | ||
rctx.file(python_wrapper, python_wrapper_content, executable = True) | ||
|
||
build_content = """\ | ||
# Generated by python/repositories.bzl | ||
|
||
|
@@ -235,8 +245,8 @@ exports_files(["python", "{python_path}"]) | |
|
||
py_runtime( | ||
name = "py3_runtime", | ||
files = [":files"], | ||
interpreter = "{python_path}", | ||
files = [":files", "{python_wrapper}"], | ||
interpreter = "{python_wrapper}", | ||
python_version = "PY3", | ||
) | ||
|
||
|
@@ -248,10 +258,11 @@ py_runtime_pair( | |
""".format( | ||
glob_include = repr(glob_include), | ||
python_path = python_bin, | ||
python_wrapper = python_wrapper, | ||
python_version = python_short_version, | ||
) | ||
rctx.delete("python") | ||
rctx.symlink(python_bin, "python") | ||
rctx.symlink(python_wrapper, "python") | ||
rctx.file(STANDALONE_INTERPRETER_FILENAME, "# File intentionally left blank. Indicates that this is an interpreter repo created by rules_python.") | ||
rctx.file("BUILD.bazel", build_content) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want -S (upper case) as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would harm in the case a custom toolchain from this repo is used. In the case a system python is used, this may even be desirable.