-
Notifications
You must be signed in to change notification settings - Fork 56
Add support for hermetic Python #29
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
Conversation
This doesn't bridge it with toolchains though, does it? |
That's right, it doesn't - but the rules in rules_python don't do it either. I don't know if that sort of thing would be possible at all, given that toolchain resolution happens at a later stage (and depends on the target). |
Ended up with this in WORKSPACE and confirm it works:
I don't think the "toolchains support" issue should be closed though. I don't see why supporting toolchains wouldn't be possible, but it does seem like supporting them would take writing pybind rules almost from scratch. @TheButlah anything preventing the merge? |
I'm not a maintainer of the repo |
I thought that rules_python do support them though - isn't that what |
The |
Oh I think I understand what you are saying - for a toolchain, you register the bazel target for the python interpreter as a toolchain and then all python rules should be able to use it automatically without specifying it as a dependency. But in this merge request, instead of relying on the registered toolchain, the user still has to explicitly provide the python interpreter target to the rule. Therefore, even though its hermetic, it still doesn't truly interoperate with the toolchain system. Did I understand that correctly @quval? |
That's pretty much my understanding as well. And since toolchain resolution depends on the target, making |
So for whoever is inevitably going to look to review this, its mergeable right? It just adds hermetic python support, rather than toolchain support |
I'm getting the following error from Bazel when I try to build a pybind11 library with the
WIth the sandbox enabled, the compiler is unable to find the header. If I add
|
@jordanzliu I could find a handful of results referencing what looks like the same problem you're having, so just to make sure: are you seeing this error only with this patch? What version of Python are you using? |
I'm on Python 3.7.9. I did actually end up finding out that |
Hmm. I haven't had to do this with Python 3.8 or Python 3.9. |
In any case, this patch shouldn't fail if |
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.
_get_python_lib needs to change
def _get_python_lib(repository_ctx, python_bin, python_lib, local):
"""Gets the python lib path."""
if not (local or python_lib):
python_lib = repository_ctx.os.environ.get(_PYTHON_LIB_PATH)
if python_lib:
return python_lib
# .. default to running python to find lib
@@ -391,6 +396,7 @@ python_configure = repository_rule( | |||
], | |||
attrs = { | |||
"python_version": attr.string(default=""), | |||
"python_interpreter_target": attr.label(), | |||
}, |
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.
would suggest library target for completeness
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 you mean to substitute the check at _get_python_lib
? What would this target look like? As far as I understand, we should be getting the correct value by querying the interpreter.
Ahh nice, I was just about to start a PR. As is, this looks like it will still use the python system libraries- left some suggestions |
@dmadisetti Thanks for reviewing! What system libraries are you thinking will be used? I've successfully used this for executing actions on an image that has no Python installation. |
@quval No problem! I was dealing with use-case of standardizing python across my platforms (vs. using completely vanilla containers). If my base image already has
I'm happy to make / test these patches, but I don't know who we need to ping to get this merged in |
@dmadisetti Ah, if that environment variable is set, things will indeed break. I was assuming it wouldn't be there when using hermetic Python. Specifying a target for the include path could be very nice if it can replace the genrule. I have no idea who is maintaining this repository, but I'll be happy to merge your patch into this PR, in hope that helps people. (I'll also add in @jordanzliu's patch from above when I get around to do it.) |
Locally tested and pr'ed quval#1 |
Can you please merge this PR to the master branch? We need it for our hermetic python env. Thank you. |
@Raschild This PR is basically the patch we used on top of pybind11_bazel - perhaps that can help you until somebody can get around to reviewing or merging this. |
Would love to get this merged as this unblocks using a custom sysroot C++ toolchain |
Allow
python_configure
to use a Python interpreter that is provided by a Bazel target, similarly to other Python rules (e.g.pip_install
).