-
Notifications
You must be signed in to change notification settings - Fork 71
Build fails with bazel 0.25 --incompatible_use_python_toolchains #98
Comments
Seems like this is the code at fault. Relative paths get embedded directly whereas the old default "python" interpreter command was passed to |
Possible solutions:
|
Argument for (2): This is already the default behavior for everyone who doesn't manipulate the python runtime. Who would we be breaking by making this the unconditional par shebang interpreter? Only users who override the python runtime to an absolute path (e.g. with |
Wouldn't
|
Yes, but it's only used for the stub script (unless I'm seriously misunderstanding how subpar works). So the stub script needs to be compatible with both Python 2 and Python 3, but the payload gets run with whatever This is how it works for standard |
I'm not saying it should deviate, not at all. I was just wondering if that could be problematic. Looks like it won't be: |
Would a relative path ever be valid? |
Sure, I was just thinking aloud as I'm newly considering this issue. :)
Sometimes, and I noticed this case in my own testing to reproduce this issue. For instance, when referencing an in-build runtime defined in the main repo, it so happens that the execroot directory structure allowed it to find the runtime executable. But change it to a runtime defined in an external repo and it no longer works out that way. I think it'd also fail if you invoked it directly without The reason not to allow relative paths in the shebang is that the par file ends up being non-relocatable even within the same system. For in-build runtimes, you typically would want to refer to them via workspace-relative paths, so that's one reason not to use them as the shebang. But even if you referred to it via an absolute path, you'd still end up with par files that are sensitive to changes to your source tree or output tree, which happens during the course of normal development workflows. So IMO the solution should be to only use absolute paths to platform-defined interpreters in the shebang (whether for par files or the standard |
That sounds reasonable -- can/should someone open a diff here to make that change? |
From what I can see,
Would you consider a PR with this change? Otherwise, the version finding and re-exec would have to be moved into the par executable, rather than at compile time. |
@aaliddell Thanks for raising that point -- it caused me to look a little deeper into subpar's inner workings. As best as I can tell, the shebang will choose what Python version executes the zip file, which under Python's semantics means running the I tried this out by patching
The tests run into some assertion errors because the new runtime wrapper script needs to be added to their expected file manifests. I also expect some PY2 vs PY3 problems since toolchains fix bazelbuild/bazel#4815. But this seems to solve the actual bug. |
Gah, I misread it, the generated My previous test only worked because it stopped the shebang from being malformed. But it still chooses the wrong Python version, as was uncovered when trying to run So I think @aaliddell's workaround is the way to go. It bans local paths while still carving out a loophole for people who just want the default Python interpreter. |
I’ve written that up as #99, although I didn’t add the ‘or fail’ bit there but instead left the existing behaviour for relative paths. Happy to make it fail though if desired. |
Tests still need updating, I'll look. |
Are you guys going to cut a release when this is done? I think it's warranted, since Subpar is broken with the Bazel 0.25 for everyone right now. |
Hm? Only with the incompatible change flag enabled, unless there's a more serious breakage I was unaware of. Cutting a release sounds warranted. Looks like there's no workflow around it (e.g. auto-generated release notes) other than tagging it as such in github. |
This adds a hook file for run_tests.sh to write toolchain info to before each bazel invocation. This replaces the legacy way of passing an interpreter in via --python_path. It also replaces a config_setting that was used to control whether PY2 or PY3 was used, with a simple constant symbol consumed at loading time. This is needed in order to make the target aware at analysis time of which version it is building for. Fixes #98, fixes #102.
This adds a hook file for run_tests.sh to write toolchain info to before each bazel invocation. This replaces the legacy way of passing an interpreter in via --python_path. It also replaces a config_setting that was used to control whether PY2 or PY3 was used, with a simple constant symbol consumed at loading time. This is needed in order to make the target aware at analysis time of which version it is building for. Fixes #98, fixes #102.
I'll double check that rules_python's tests pass and tag a release. I think it has to be a new major release, i.e. 2.0.0, if we're following semantic versioning, since we drop support for Bazels earlier than 0.23. I'm not sure whether previous releases used this standard but we may as well do it now since I think semantic versioning is strongly encouraged all around the bazel ecosystem. |
Tagged 2.0.0. |
Correct me if I'm worng, but I think this is still somewhat broken. Because there's currently a bug in But this causes problems with
so you get this error:
Because of how For the purposes of tests I can specify a different How do you recommend I sort this out? |
It seems like the first line in the par has an incomplete path to the wrapper script:
The text was updated successfully, but these errors were encountered: