-
-
Notifications
You must be signed in to change notification settings - Fork 611
feat: Support main_module with bootstrap_impl=system_python #3072
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
A shim to get `main_module` working with `bootstrap_impl=system_python`. | ||
""" | ||
|
||
import os | ||
import runpy | ||
|
||
if __name__ == "__main__": | ||
runpy.run_module("%main_module%", run_name="__main__", alter_sys=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
# limitations under the License. | ||
load("@rules_pkg//pkg:tar.bzl", "pkg_tar") | ||
load("@rules_shell//shell:sh_test.bzl", "sh_test") | ||
load("//python:defs.bzl", "py_library") | ||
load("//tests/support:py_reconfig.bzl", "py_reconfig_binary", "py_reconfig_test") | ||
load("//tests/support:sh_py_run_test.bzl", "sh_py_run_test") | ||
load("//tests/support:support.bzl", "SUPPORTS_BOOTSTRAP_SCRIPT") | ||
|
@@ -123,13 +124,25 @@ py_reconfig_test( | |
main = "sys_path_order_test.py", | ||
) | ||
|
||
py_reconfig_test( | ||
name = "main_module_test", | ||
py_library( | ||
name = "main_module_lib", | ||
srcs = ["main_module.py"], | ||
bootstrap_impl = "script", | ||
imports = ["."], | ||
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. This needs to be kept because it ensures the correct entry is added to sys.path. Without it, it can inadvertently rely on the implicit behavior from the flag that adds repos to sys.path and the PYTHONSAFEPATH setting 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 can re-add it, but I don't understand the reasoning. IIUC, |
||
) | ||
|
||
py_reconfig_test( | ||
name = "main_module_script_test", | ||
bootstrap_impl = "script", | ||
main_module = "tests.bootstrap_impls.main_module", | ||
target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, | ||
deps = [":main_module_lib"], | ||
) | ||
|
||
py_reconfig_test( | ||
name = "main_module_system_python_test", | ||
brandonchinn178 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bootstrap_impl = "system_python", | ||
main_module = "tests.bootstrap_impls.main_module", | ||
deps = [":main_module_lib"], | ||
) | ||
|
||
sh_py_run_test( | ||
|
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.
Instead of creating a shim like this, modify the bootstrap template. All it should really need is to populate a %main_module% variable and pass
-m
when invoking python. That should simplify things quite a bit.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.
hm I could try it again, but it was difficult because then I'd have to update all the locations where
%main%
is used, since there isn't a main file anymore. It seemed easier to say "we're using the main file logic everywhere still, it just points to a shim"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.
yeah, it seems like the notion of a main file is hardcoded in a lot of places in
python_bootstrap_template.txt
. It's also not immediately clear how the translation to-m <main_module>
would work for the coverage path. The shim seems like the easiest solution, especially given this is a deprecated codepath and it should have a negligible performance impact