-
Notifications
You must be signed in to change notification settings - Fork 139
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
Ensure Python 2 and 3 are both available on all platforms #578
Comments
Ping @philwo, this would be handy to have now that we're pushing Python toolchainization. |
Philwo is currently OOO. We can look into this issue this week. |
@brandjon What is "py.exe"? I've never heard of it. We cannot easily install Python 2 and 3 on Windows, because both versions install their binaries with the same names, whereas on other platforms they're usually installed as /usr/bin/python and /usr/bin/python3. I mean, we can install both, but how would you find them, if they're not on the PATH? |
That's the problem that the py.exe launcher is intended to solve. It handles the file association for I intend to call py.exe in the toolchain of last resort that autodetects an interpreter at execution time. This toolchain may be used to run our end-to-end Python tests on Windows, or alternatively we may have the test workspace register a toolchain that hardcodes the absolute paths of the installed Python runtimes. I don't believe it's necessary for the runtimes to be on |
Ping? |
Note that I had to opt out of the new Python toolchains flag in |
I'm rolling out new Windows images that have Python 2.7 and Python 3.6 installed: Python 2.7 is in C:\Python2 |
Excellent! To confirm, is py.exe available in C:\Windows (I believe the standard location if py.exe is installed)? |
(Github has a very interesting notion of time. Your comment is currently appearing below the one I just made, with the timestamp "philwo commented 3 hours from now".) |
Time travel - it's the only way I can handle the workload. No, but lol - I have no idea what's up with GitHub :D Yes, |
Who would own the Mac image? Once we have both runtimes there, I should be able to modify our test workspace to set up appropriate toolchains so we can run Python integration tests on all platforms. |
macOS comes with Python 2.7.10 by default (in Does that work for you? |
Sure! Are both on |
Yes, they're both on the PATH :) If it doesn't work, let me know. |
See this downstream project CI failure, because I understand when you said it's on
|
Note that this will be a breaking failure when |
Yeah, that sounds problematic. What about using But I thought we had already removed the broken "PATH normalizing" from Bazel and no longer replace it with a stripped down default PATH... I have to investigate what's happening there tomorrow.
I don't know much about toolchains. We can modify the WORKSPACE file of projects before we run CI tests on them, just like we already have to do for the
That's unfortunately impossible - macOS System Integrity Protection prevents even the
(I know that it's possible to disable this by using an undocumented tool from the recovery system, but that's not really an option for a production system.) |
|
I verified that for a simple That means, I looked at the above linked failure and noticed that the test ran with this PATH: Failure reason: Cannot locate 'python3' or 'python' on the target platform's PATH, which is:
/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:. This is wrong for various reasons: a) There is no /usr/gnu/bin on the system and I don't have the slightest idea where that comes from. b) It includes the current directory in the PATH (see the trailing ":."). Any idea where that weird PATH comes from? |
I'm as stumped as you about the gnu path, I did a code search and github search for that before and found nothing. The Python stub script doesn't manipulate |
Minimal repro: # //pkg:BUILD
load(":stuff.bzl", "stuff_rule")
py_binary(
name = "foo",
srcs = [":foo.py"],
)
stuff_rule(
name = "stuff",
outfile = "stuff.txt",
) # //pkg:stuff.bzl
def _stuff_rule_impl(ctx):
ctx.actions.run(
inputs = [],
outputs = [ctx.outputs.outfile],
executable = ctx.executable._tool,
)
stuff_rule = rule(
implementation = _stuff_rule_impl,
attrs = {
# cfg param is required, but doesn't matter whether it's "host" or "target"
"_tool": attr.label(executable=True, default="//pkg:foo", cfg="target"),
"outfile": attr.output(),
},
)
That gives you the error message about not being able to locate a python command on # foo.py
import os
print(os.environ['PATH'])
# We should actually direct it to a file whose name is passed in argv[1],
# but for the purposes of this example we don't get that far.
So the problem appears to be that the new toolchain assumes Now to figure out why we're seeing these test failures on mac even though I can apparently repro the absence of |
Ok, a key part to this is that the My guess is the shell comes up with its default Fortunately, at least it means that the absence of |
This also explains where the gnu path came from. |
Oh. Ok, now I got it. When
|
And that's the difference: On my machine, when the shell initializes its own |
Re my last comment: I'm not actually sure my machine exports it. It could be an undocumented behavior of the |
This is a modification of PR #8415, which changed `which` to `command -v` so it works when PATH isn't exported. `command` is more standard for this kind of use case (https://github.com/koalaman/shellcheck/wiki/SC2230). Unfortunately, `command -v` doesn't check the executable bit, so it's not as useful for us. The previous fix for this issue (7f49531) was based on exporting PATH, but this changes the environment seen by the exec'd payload Python code. The solution in this commit is to not export PATH but rather explicitly pass it to each invocation of `which`. Fixes #8414. See also bazelbuild/continuous-integration#578. Closes #8415. PiperOrigin-RevId: 249334274
See bazelbuild/continuous-integration#578 for context. The gist of it is that when PATH is not set (as happens when a binary using this toolchain is used as a tool from Starlark), the shell comes up with its own PATH to run the pywrapper script. However, it does not necessarily export this PATH, causing "which" to misbehave and fail to locate a Python interpreter. The fix is to add "export PATH" and a regression test. Fixes bazelbuild/continuous-integration#578, work toward #7899. RELNOTES: None PiperOrigin-RevId: 249263849
This is a modification of PR #8415, which changed `which` to `command -v` so it works when PATH isn't exported. `command` is more standard for this kind of use case (https://github.com/koalaman/shellcheck/wiki/SC2230). Unfortunately, `command -v` doesn't check the executable bit, so it's not as useful for us. The previous fix for this issue (7f49531) was based on exporting PATH, but this changes the environment seen by the exec'd payload Python code. The solution in this commit is to not export PATH but rather explicitly pass it to each invocation of `which`. Fixes #8414. See also bazelbuild/continuous-integration#578. Closes #8415. PiperOrigin-RevId: 249334274
See bazelbuild/continuous-integration#578 for context. The gist of it is that when PATH is not set (as happens when a binary using this toolchain is used as a tool from Starlark), the shell comes up with its own PATH to run the pywrapper script. However, it does not necessarily export this PATH, causing "which" to misbehave and fail to locate a Python interpreter. The fix is to add "export PATH" and a regression test. Fixes bazelbuild/continuous-integration#578, work toward #7899. RELNOTES: None PiperOrigin-RevId: 249263849
This is a modification of PR #8415, which changed `which` to `command -v` so it works when PATH isn't exported. `command` is more standard for this kind of use case (https://github.com/koalaman/shellcheck/wiki/SC2230). Unfortunately, `command -v` doesn't check the executable bit, so it's not as useful for us. The previous fix for this issue (7f49531) was based on exporting PATH, but this changes the environment seen by the exec'd payload Python code. The solution in this commit is to not export PATH but rather explicitly pass it to each invocation of `which`. Fixes #8414. See also bazelbuild/continuous-integration#578. Closes #8415. PiperOrigin-RevId: 249334274
See bazelbuild/continuous-integration#578 for context. The gist of it is that when PATH is not set (as happens when a binary using this toolchain is used as a tool from Starlark), the shell comes up with its own PATH to run the pywrapper script. However, it does not necessarily export this PATH, causing "which" to misbehave and fail to locate a Python interpreter. The fix is to add "export PATH" and a regression test. Fixes bazelbuild/continuous-integration#578, work toward #7899. RELNOTES: None PiperOrigin-RevId: 249263849
This is a modification of PR #8415, which changed `which` to `command -v` so it works when PATH isn't exported. `command` is more standard for this kind of use case (https://github.com/koalaman/shellcheck/wiki/SC2230). Unfortunately, `command -v` doesn't check the executable bit, so it's not as useful for us. The previous fix for this issue (7f49531) was based on exporting PATH, but this changes the environment seen by the exec'd payload Python code. The solution in this commit is to not export PATH but rather explicitly pass it to each invocation of `which`. Fixes #8414. See also bazelbuild/continuous-integration#578. Closes #8415. PiperOrigin-RevId: 249334274
Now that we have both a Python 2 and 3 interpreter on our CI machines (bazelbuild/continuous-integration#578), we can turn on these version tests for Windows. Since there's no autodetecting toolchain for Windows yet (#7844) we define an explicit toolchain. Fixes #8411. RELNOTES: None PiperOrigin-RevId: 250562174
See bazelbuild/continuous-integration#578 for context. The gist of it is that when PATH is not set (as happens when a binary using this toolchain is used as a tool from Starlark), the shell comes up with its own PATH to run the pywrapper script. However, it does not necessarily export this PATH, causing "which" to misbehave and fail to locate a Python interpreter. The fix is to add "export PATH" and a regression test. Fixes bazelbuild/continuous-integration#578, work toward bazelbuild#7899. RELNOTES: None PiperOrigin-RevId: 249263849
This is a modification of PR bazelbuild#8415, which changed `which` to `command -v` so it works when PATH isn't exported. `command` is more standard for this kind of use case (https://github.com/koalaman/shellcheck/wiki/SC2230). Unfortunately, `command -v` doesn't check the executable bit, so it's not as useful for us. The previous fix for this issue (bazelbuild@7f49531) was based on exporting PATH, but this changes the environment seen by the exec'd payload Python code. The solution in this commit is to not export PATH but rather explicitly pass it to each invocation of `which`. Fixes bazelbuild#8414. See also bazelbuild/continuous-integration#578. Closes bazelbuild#8415. PiperOrigin-RevId: 249334274
Now that we have both a Python 2 and 3 interpreter on our CI machines (bazelbuild/continuous-integration#578), we can turn on these version tests for Windows. Since there's no autodetecting toolchain for Windows yet (bazelbuild#7844) we define an explicit toolchain. Fixes bazelbuild#8411. RELNOTES: None PiperOrigin-RevId: 250562174
Now that we have both a Python 2 and 3 interpreter on our CI machines (bazelbuild/continuous-integration#578), we can turn on these version tests for Windows. Since there's no autodetecting toolchain for Windows yet (bazelbuild#7844) we define an explicit toolchain. Fixes bazelbuild#8411. RELNOTES: None PiperOrigin-RevId: 250562174
Last time I checked, our linux workers had both Python 2 and 3 available, but windows only had Python 2 and Mac only Python 3. Can we ensure that all platforms have both versions available?
This affects what platforms some shell integration tests run on. It's possible to rewrite some of the tests as analysis-time tests, or analysis+execution-time tests. But even if I do that, I'll still want something with end-to-end coverage ensuring that
py_binary
s can in fact locate an interpreter using the (future) default Python toolchain.For Windows, please ensure that the "py.exe" wrapper is installed, which I believe comes standard with Python 3. It shouldn't matter whether "python.exe" itself is accessible on PATH so long as the wrapper is available. (Whatever tests I add for launching "py.exe" and "python.exe" will probably use a mocked out PATH and fake binaries anyway.)
The text was updated successfully, but these errors were encountered: