Skip to content
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

Replace Python 2 with Python 3 #11202

Closed
olekw opened this issue Apr 23, 2020 · 12 comments
Closed

Replace Python 2 with Python 3 #11202

olekw opened this issue Apr 23, 2020 · 12 comments
Assignees
Labels
area-EngProd Bazel CI, infrastructure, bootstrapping, release, and distribution tooling P1 I'll work on this now. (Assignee required) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: feature request

Comments

@olekw
Copy link
Contributor

olekw commented Apr 23, 2020

Description of the problem / feature request:

Python 2 has reached end-of-life and operating systems are actively removing legacy Python code and support. Please accept #11201 to convert all legacy Python 2 code in Bazel to Python 3. The patch is relatively trivial.

Feature requests: what underlying problem are you trying to solve with this feature?

Python 2 EOL

What operating system are you running Bazel on?

Debian Unstable

Have you found anything relevant by searching the web?

Yes, please see above.

Any other information, logs, or outputs that you want to share?

An alternate solution is to allow Bazel to dynamically adapt to the version of Python requested by the user. This might have been advisable a year or two ago but at this point I don't think it is worth the effort to support an obsolete version of Python.

@aiuto
Copy link
Contributor

aiuto commented Apr 23, 2020

We certainly are fine with requiring python3 to build bazel. I don't think we are ready to commit to requiring users to make that switch yet. As long as PRs only fix our build process, this should not be a problem.

@aiuto aiuto added area-EngProd Bazel CI, infrastructure, bootstrapping, release, and distribution tooling untriaged labels Apr 23, 2020
@philwo philwo added P1 I'll work on this now. (Assignee required) type: feature request and removed untriaged labels May 19, 2020
@philwo
Copy link
Member

philwo commented May 19, 2020

Thank you @olekw! I'll look into your PR.

As @aiuto said, we want our build to work on Python 3 only systems and not require Python 2. It is fine for us to achieve this by requiring Python 3, we don't need backwards compatibility with Python 2 for our build anymore.

@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
@davido
Copy link
Contributor

davido commented Apr 20, 2021

@aiuto @philwo

I don't think we are ready to commit to requiring users to make that switch yet.

One year later... Any progress here?

Python 2.7 was discontinued on January 1, 2020: [1].

[1] https://www.python.org/doc/sunset-python-2

@philwo
Copy link
Member

philwo commented Apr 20, 2021

@davido I just grepped for remaining python2 pieces in our code and couldn't find anything that looked too critical. A few references in j2objc stuff and one explicit call to python2.7 in the BUILD file used to build Debian packages for Bazel releases, that I can clean up.

Do you have anything specific in mind?

@philwo
Copy link
Member

philwo commented Apr 20, 2021

We should also replace #!/usr/bin/env python with #!/usr/bin/env python3, I'll have to check the code for that.

@davido
Copy link
Contributor

davido commented Apr 20, 2021

We should also replace #!/usr/bin/env python with #!/usr/bin/env python3

Exactly, we have similar request here: [1]. And I've sent similar CL: [2].

[1] https://crbug.com/gerrit/14175
[2] https://gerrit-review.googlesource.com/c/gerrit/+/298903

bazel-io pushed a commit that referenced this issue Apr 20, 2021
@davido
Copy link
Contributor

davido commented May 29, 2021

@philwo @brandjon

Somehow related: I cannot build Bazel without installing "python". Consider this docker image: [1] (you could do the same on Ubuntu 20.04).

If you remove python from the list of installed modules, and just leave python3, then the Bazel build would fail with the error: python is not installed. Why it's still needed? I would have expected, that Bazel could just be built with only Python3 installed.

[1] https://github.com/davido/fedora-bazel-docker

@olekw
Copy link
Contributor Author

olekw commented May 30, 2021

@davido there's a Debian/Ubuntu package that takes care of this. [1] Now, long-term it would probably be best for Bazel to just look for Python 3 directly but this is a reasonably easy interim fix.

[1] https://packages.debian.org/sid/python-is-python3

@davido
Copy link
Contributor

davido commented May 30, 2021

@olekw

Thanks for pointing this out. Yeah, also on Fedora, actually "python" is a link to python3:

============================================================================================================================
 Package                                   Architecture          Version                      Repository               Size
============================================================================================================================
python-unversioned-command                noarch                3.9.5-2.fc35                 @rawhide                 23

When building bazel build src:bazel-bin-dev, I see this error:

ERROR: /bazel/src/BUILD:323:9: Executing genrule //src:embedded_tools_jdk_allmodules failed: (Exit 127): bash failed: error executing command 
  (cd /root/.cache/bazel/_bazel_root/17ca80f5678de367412ae4ed97070adf/sandbox/processwrapper-sandbox/2198/execroot/io_bazel && \
  exec env - \
    PATH=/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/src/create_embedded_tools "bazel-out/k8-fastbuild/bin/src/embedded_tools_jdk_allmodules.zip" bazel-out/k8-fastbuild/bin/src/embedded_tools_jdk_allmodules.params')
Execution platform: //:default_host_platform

Use --sandbox_debug to see verbose messages from the sandbox
/usr/bin/env: 'python': No such file or directory
Target //src:bazel-bin-dev failed to build
INFO: Elapsed time: 572.567s, Critical Path: 155.04s
INFO: 2222 processes: 51 internal, 1445 processwrapper-sandbox, 726 worker.
FAILED: Build did NOT complete successfully

@davido
Copy link
Contributor

davido commented May 31, 2021

I can confirm, that this diff fixed the problem for me:

diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/python/PyRuntimeInfoApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/python/PyRuntimeInfoApi.java
index 9a178cee3a..743bb88862 100644
--- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/python/PyRuntimeInfoApi.java
+++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/python/PyRuntimeInfoApi.java
@@ -45,7 +45,7 @@ import net.starlark.java.eval.StarlarkValue;
     category = DocCategory.PROVIDER)
 public interface PyRuntimeInfoApi<FileT extends FileApi> extends StarlarkValue {
 
-  static final String DEFAULT_STUB_SHEBANG = "#!/usr/bin/env python";
+  static final String DEFAULT_STUB_SHEBANG = "#!/usr/bin/env python3";
 
   @StarlarkMethod(
       name = "interpreter_path",

I can build Bazel itself and Gerrit Code Review without installing python bridge:

  $ python
bash: python: command not found

  $ python3 --version
Python 3.9.5

@olekw
Copy link
Contributor Author

olekw commented May 31, 2021

I can confirm, that this diff fixed the problem for me:

Seems like a trivial and reasonable patch if Python 3 is the default anyway.

@meteorcloudy
Copy link
Member

I think Bazel has migrated to Python3, please reopen if things still need python2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-EngProd Bazel CI, infrastructure, bootstrapping, release, and distribution tooling P1 I'll work on this now. (Assignee required) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: feature request
Projects
None yet
Development

No branches or pull requests

5 participants