-
-
Notifications
You must be signed in to change notification settings - Fork 608
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?
feat: Support main_module with bootstrap_impl=system_python #3072
Conversation
94428b0
to
c183928
Compare
9cc661a
to
ffed3fb
Compare
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.
Thanks for the PR and test!
aside: if you grant maintainer permssions to edit, i can directly do some of the small things.
@@ -127,11 +128,22 @@ py_reconfig_test( | |||
name = "main_module_test", | |||
srcs = ["main_module.py"], | |||
bootstrap_impl = "script", | |||
imports = ["."], |
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.
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 comment
The 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, imports
says "add this directory to PYTHONPATH", but we're specifying main_module
with the full absolute path, so imports = ["."]
isn't doing anything. Would imports = []
have the behavior you want?
@@ -0,0 +1,9 @@ | |||
""" | |||
A shim to get `main_module` working with `bootstrap_impl=system_python`. |
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
5791f3d
to
6910f2b
Compare
6910f2b
to
418a70c
Compare
main_module
was added in #2671, but support was only added forbootstrap_impl=script
. Despite only supportingbootstrap_impl=script
, both the CHANGELOG and the documentation didn't mention that limitation, making it seem likemain_module
doesn't work out-of-the-box (given thatbootstrap_impl=system_python
is the default). See #2765 (comment).This PR adds support for
main_module
withbootstrap_impl=system_python
. This is categorized asfeat
because it's new functionality, but it can also be conceptualized as afix
, since it's bringing the feature in line with docs.