From f1b21e4633f6ec8492584e66076d982f5174f331 Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Tue, 1 Oct 2019 19:47:53 +0000 Subject: [PATCH] Make gclient.py warn on Python 3 An increasing number of Windows developers are "accidentally" ending up with Python 3 installed on their machine through the Windows Store. If this version is first in the path then gclient may fail in non-obvious ways. This adds a python version check to give a clear warning message. R=vapier@chromium.org Change-Id: I7a292fba2ab7d059a6149644d0b1fd92d2371dce Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1825945 Commit-Queue: Bruce Dawson Reviewed-by: Edward Lesmes Reviewed-by: Mike Frysinger --- gclient.py | 6 ++++++ tests/gclient_smoketest.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/gclient.py b/gclient.py index 6bfe1516eb..9bc33fda6b 100755 --- a/gclient.py +++ b/gclient.py @@ -118,6 +118,12 @@ import setup_color from third_party import six +# Check for people accidentally running this script with Python3 - an +# increasingly common error on Windows 10 due to the store version of Python. +if sys.version_info.major >= 3 and not 'GCLIENT_TEST' in os.environ: + print("Warning: gclient doesn't yet support Python 3 and may not work " + "correctly.", file=sys.stderr) + # TODO(crbug.com/953884): Remove this when python3 migration is done. if six.PY3: diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index 7d323e650c..2a9f8fda95 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -38,6 +38,8 @@ class GClientSmokeBase(fake_repos.FakeReposTestBase): self.env = os.environ.copy() self.env['DEPOT_TOOLS_UPDATE'] = '0' self.env['DEPOT_TOOLS_METRICS'] = '0' + # Suppress Python 3 warnings and other test undesirables. + self.env['GCLIENT_TEST'] = '1' def gclient(self, cmd, cwd=None): if not cwd: