Skip to content

Migrate to python3 #4552

Closed
Closed

Description

@htuch

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?

Activity

  1. added
    design proposal
    help wanted
    on Sep 27, 2018
  2. mattklein123 commented on Sep 27, 2018

    @mattklein123
    Member

    🍿

  3. danielhochman commented on Sep 27, 2018

    @danielhochman
    Contributor

    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.

    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.

  4. cclauss commented on Jan 15, 2019

    @cclauss
    Contributor

    Todos:

  5. keith commented on Jun 24, 2019

    @keith
    Member

    This has come up again with some bazel updates, more context #7337

  6. kylebevans commented on Feb 2, 2020

    @kylebevans

    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.

  7. added a commit that references this issue on Apr 8, 2020
  8. mattklein123 commented on Sep 17, 2020

    @mattklein123
    Member

    I think this is done.

  9. GhostLyrics commented on Aug 23, 2022

    @GhostLyrics
    Contributor

    @mattklein123 @htuch Would you like me to create a new issue/pull request to also ask for python3 in the first line of the hot-restarter?

  10. htuch commented on Aug 24, 2022

    @htuch
    MemberAuthor

    If there is some missing Python 3, sure - @phlax can review and guide any remaining work here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    design proposalhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions