You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What do folks think about moving to Python 3 across the board? We're going to need this at Google in the short-medium term. I'm not an expert on what the best practices are here, how we can best maintain Python 2/3 mixed compatibility etc. @danielhochman do you have any thoughts?
For the amount of Python that we have, even including dependencies, it shouldn't be that hard to maintain mixed compatibility. six is used for standard library backwards compatibility. I checked all of the libraries we depend on in various requirements.txt and they're all 2/3 compatible.
We'll probably need to go ahead and write a specific test target for our Python scripts to guarantee 2/3 compatibility. Otherwise we would have to run much larger targets that depend on the scripts with both Python versions.
An Ubuntu 18.04 system with only python3 threw this error while building:
ERROR: /home/kylebe/envoy/source/extensions/filters/network/kafka/BUILD:163:1: Executing genrule //source/extensions/filters/network/kafka:kafka_response_generated_source failed (Exit 1) bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
Error occurred while attempting to use the default Python toolchain (@rules_python//python:autodetecting_toolchain).
According to '/usr/bin/python -V', version is 'Python 3.6.7', but we need version 2. PATH is:
/home/kylebe/envoy/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
Please ensure an interpreter with version 2 is available on this platform as 'python2' or 'python', or else register an appropriate Python toolchain as per the documentation for py_runtime_pair (https://github.com/bazelbuild/rules_python/blob/master/docs/python.md#py_runtime_pair).
Note that prior to Bazel 0.27, there was no check to ensure that the interpreter's version matched the version declared by the target (#4815). If your build worked prior to Bazel 0.27, and you're sure your targets do not require Python 2, you can opt out of this version check by using the non-strict autodetecting toolchain instead of the standard autodetecting toolchain. This can be done by passing the flag `--extra_toolchains=@rules_python//python:autodetecting_toolchain_nonstrict` on the command line or adding it to your bazelrc.
----------------
Note: The failure of target //source/extensions/filters/network/kafka:kafka_protocol_code_generator_bin (with exit code 1) may have been caused by the fact that it is running under Python 2 instead of Python 3. Examine the error to determine if that appears to be the problem. Since this target is built in the host configuration, the only way to change its version is to set --host_force_python=PY3, which affects the entire build.
If this error started occurring in Bazel 0.27 and later, it may be because the Python toolchain now enforces that targets analyzed as PY2 and PY3 run under a Python 2 and Python 3 interpreter, respectively. See https://github.com/bazelbuild/bazel/issues/7899 for more information.
----------------
Target //source/exe:envoy-static failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 3.423s, Critical Path: 2.55s
INFO: 3 processes: 3 processwrapper-sandbox.
FAILED: Build did NOT complete successfully
Running bazel with the --host_force_python=PY3 worked: bazel build //source/exe:envoy-static --host_force_python=PY3
Another option seems to be to set the python version explicitly in the bazel build rules.
I'm not sure where I'm going with this, but I wouldn't mind sending a PR to update the docs or to try to update the build rules if you want.
Activity
mattklein123 commentedon Sep 27, 2018
🍿
danielhochman commentedon Sep 27, 2018
For the amount of Python that we have, even including dependencies, it shouldn't be that hard to maintain mixed compatibility. six is used for standard library backwards compatibility. I checked all of the libraries we depend on in various
requirements.txtand they're all 2/3 compatible.There are some other tools and considerations listed in Porting Python 2 Code to Python 3.
We'll probably need to go ahead and write a specific test target for our Python scripts to guarantee 2/3 compatibility. Otherwise we would have to run much larger targets that depend on the scripts with both Python versions.
cclauss commentedon Jan 15, 2019
Todos:
keith commentedon Jun 24, 2019
This has come up again with some bazel updates, more context #7337
Use print() function in both Python 2 and Python 3 (#7383)
Use print() function in both Python 2 and Python 3 (#7384)
Define cmp() in Python 3 (#7385)
Run flake8 on Python instead of legacy Python (#7388)
kylebevans commentedon Feb 2, 2020
An Ubuntu 18.04 system with only python3 threw this error while building:
Running bazel with the --host_force_python=PY3 worked:
bazel build //source/exe:envoy-static --host_force_python=PY3Another option seems to be to set the python version explicitly in the bazel build rules.
I'm not sure where I'm going with this, but I wouldn't mind sending a PR to update the docs or to try to update the build rules if you want.
thrift: fix test tooling for python3
mattklein123 commentedon Sep 17, 2020
I think this is done.
GhostLyrics commentedon Aug 23, 2022
@mattklein123 @htuch Would you like me to create a new issue/pull request to also ask for
python3in the first line of the hot-restarter?htuch commentedon Aug 24, 2022
If there is some missing Python 3, sure - @phlax can review and guide any remaining work here.