From 938c427f351e1df50abdd857c69c134b60260e62 Mon Sep 17 00:00:00 2001 From: Krishna Ersson Date: Thu, 17 Mar 2022 12:45:00 -0400 Subject: [PATCH] Use python3 everywhere --- .../lib/bazel/rules/python/BazelPythonSemantics.java | 8 ++------ .../lib/starlarkbuildapi/python/PyRuntimeInfoApi.java | 2 +- src/test/py/bazel/launcher_test.py | 4 ++-- tools/objc/libtool.sh | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java index 4655866c0d0629..6d03c2aabf76c7 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java @@ -221,7 +221,7 @@ public void createExecutable( * logic will extract the zip's runfiles into a temporary directory. * * The stub script has a shebang pointing to a first-stage Python interpreter (as of this - * writing "#!/usr/bin/env python"). When a zip file is built on unix, this shebang is also + * writing "#!/usr/bin/env python3"). When a zip file is built on unix, this shebang is also * prepended to the final zip artifact. On Windows shebangs are ignored, and the launcher * runs the first stage with an interpreter whose path is passed in as LaunchInfo. */ @@ -251,11 +251,7 @@ public void createExecutable( if (OS.getCurrent() != OS.WINDOWS) { PathFragment shExecutable = ShToolchain.getPathOrError(ruleContext); - // TODO(#8685): Remove this special-case handling as part of making the proper shebang a - // property of the Python toolchain configuration. - String pythonExecutableName = OS.getCurrent() == OS.OPENBSD ? "python3" : "python"; - // NOTE: keep the following line intact to support nix builds - String pythonShebang = "#!/usr/bin/env " + pythonExecutableName; + String pythonShebang = "#!/usr/bin/env python3"; ruleContext.registerAction( new SpawnAction.Builder() .addInput(zipFile) 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 9a178cee3a9a11..743bb888624bd7 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 @@ category = DocCategory.PROVIDER) public interface PyRuntimeInfoApi 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", diff --git a/src/test/py/bazel/launcher_test.py b/src/test/py/bazel/launcher_test.py index 17efcc551f8fb5..2c34722a110810 100644 --- a/src/test/py/bazel/launcher_test.py +++ b/src/test/py/bazel/launcher_test.py @@ -355,7 +355,7 @@ def testPyBinaryLauncher(self): 'helloworld(', ' name = "hello",', ' out = "hello.txt",', ')' ]) foo_py = self.ScratchFile('foo/foo.py', [ - '#!/usr/bin/env python', + '#!/usr/bin/env python3', 'import sys', 'if len(sys.argv) == 2:', ' with open(sys.argv[1], "w") as f:', @@ -364,7 +364,7 @@ def testPyBinaryLauncher(self): ' print("Hello World!")', ]) test_py = self.ScratchFile('foo/test.py', [ - '#!/usr/bin/env python', + '#!/usr/bin/env python3', 'import unittest', 'class MyTest(unittest.TestCase):', ' def test_dummy(self):', diff --git a/tools/objc/libtool.sh b/tools/objc/libtool.sh index 2420c3aaaa34a8..583e5c34df2cad 100755 --- a/tools/objc/libtool.sh +++ b/tools/objc/libtool.sh @@ -64,9 +64,9 @@ function hash_objfile() { echo "$SYMLINK_NAME" } -python_executable=/usr/bin/python2.7 +python_executable=/usr/bin/python3 if [[ ! -x "$python_executable" ]]; then - python_executable=python + python_executable=python3 fi ARGS=()