Commit d2a5a4c0 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

Revert "presubmit_support: Fix tests on Python 3."

This reverts commit a834f39e.

Reason for revert:
https://bugs.chromium.org/p/chromium/issues/detail?id=1017367

Original change's description:
> presubmit_support: Fix tests on Python 3.
>
> Bug: 1009814
> Change-Id: I2c2a835fc4fa0a7fc9e68dfff680fb0beacb491e
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1869535
> Reviewed-by: Anthony Polito <apolito@google.com>
> Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>

TBR=ehmaldonado@chromium.org,apolito@google.com

Bug: 1009814
Change-Id: I48907caeca9b9b32e4e3a7cb5a636280d017a4c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1877350Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent a7c808a4
python_version: "3.8" python_version: "3.8"
# Used by:
# auth.py
# gerrit_util.py
# git_cl.py
# my_activity.py
# TODO(crbug.com/1002153): Add ninjalog_uploader.py
wheel: <
name: "infra/python/wheels/httplib2-py3"
version: "version:0.13.1"
>
# Used by:
# my_activity.py
wheel: <
name: "infra/python/wheels/python-dateutil-py2_py3"
version: "version:2.7.3"
>
wheel: <
name: "infra/python/wheels/six-py2_py3"
version: "version:1.10.0"
>
...@@ -12,6 +12,8 @@ from __future__ import print_function ...@@ -12,6 +12,8 @@ from __future__ import print_function
import base64 import base64
import contextlib import contextlib
import cookielib
import httplib # Still used for its constants.
import httplib2 import httplib2
import json import json
import logging import logging
...@@ -25,6 +27,8 @@ import sys ...@@ -25,6 +27,8 @@ import sys
import tempfile import tempfile
import time import time
import urllib import urllib
import urlparse
from cStringIO import StringIO
from multiprocessing.pool import ThreadPool from multiprocessing.pool import ThreadPool
import auth import auth
...@@ -33,17 +37,6 @@ import metrics ...@@ -33,17 +37,6 @@ import metrics
import metrics_utils import metrics_utils
import subprocess2 import subprocess2
if sys.version_info.major == 2:
import cookielib
import httplib
import urlparse
from cStringIO import StringIO
else:
import http.cookiejar as cookielib
import http.client as httplib
import urllib.parse as urlparse
from io import StringIO
LOGGER = logging.getLogger() LOGGER = logging.getLogger()
# With a starting sleep time of 1.5 seconds, 2^n exponential backoff, and seven # With a starting sleep time of 1.5 seconds, 2^n exponential backoff, and seven
# total tries, the sleep time between the first and last tries will be 94.5 sec. # total tries, the sleep time between the first and last tries will be 94.5 sec.
......
...@@ -15,6 +15,7 @@ import base64 ...@@ -15,6 +15,7 @@ import base64
import collections import collections
import datetime import datetime
import glob import glob
import httplib
import httplib2 import httplib2
import itertools import itertools
import json import json
...@@ -29,6 +30,9 @@ import sys ...@@ -29,6 +30,9 @@ import sys
import tempfile import tempfile
import textwrap import textwrap
import time import time
import urllib
import urllib2
import urlparse
import uuid import uuid
import webbrowser import webbrowser
import zlib import zlib
...@@ -54,17 +58,6 @@ import subcommand ...@@ -54,17 +58,6 @@ import subcommand
import subprocess2 import subprocess2
import watchlists import watchlists
if sys.version_info.major == 2:
import httplib
import urllib2 as urllib_request
import urllib2 as urllib_error
import urlparse
else:
import http.client as httplib
import urllib.request as urllib_request
import urllib.error as urllib_error
import urllib.parse as urlparse
__version__ = '2.0' __version__ = '2.0'
# Traces for git push will be stored in a traces directory inside the # Traces for git push will be stored in a traces directory inside the
...@@ -3189,7 +3182,7 @@ def urlretrieve(source, destination): ...@@ -3189,7 +3182,7 @@ def urlretrieve(source, destination):
This is necessary because urllib is broken for SSL connections via a proxy. This is necessary because urllib is broken for SSL connections via a proxy.
""" """
with open(destination, 'w') as f: with open(destination, 'w') as f:
f.write(urllib_request.urlopen(source).read()) f.write(urllib2.urlopen(source).read())
def hasSheBang(fname): def hasSheBang(fname):
...@@ -4662,7 +4655,7 @@ def GetTreeStatus(url=None): ...@@ -4662,7 +4655,7 @@ def GetTreeStatus(url=None):
'unknown' or 'unset'.""" 'unknown' or 'unset'."""
url = url or settings.GetTreeStatusUrl(error_ok=True) url = url or settings.GetTreeStatusUrl(error_ok=True)
if url: if url:
status = urllib_request.urlopen(url).read().lower() status = urllib2.urlopen(url).read().lower()
if status.find('closed') != -1 or status == '0': if status.find('closed') != -1 or status == '0':
return 'closed' return 'closed'
elif status.find('open') != -1 or status == '1': elif status.find('open') != -1 or status == '1':
...@@ -4676,7 +4669,7 @@ def GetTreeStatusReason(): ...@@ -4676,7 +4669,7 @@ def GetTreeStatusReason():
with the reason for the tree to be opened or closed.""" with the reason for the tree to be opened or closed."""
url = settings.GetTreeStatusUrl() url = settings.GetTreeStatusUrl()
json_url = urlparse.urljoin(url, '/current?format=json') json_url = urlparse.urljoin(url, '/current?format=json')
connection = urllib_request.urlopen(json_url) connection = urllib2.urlopen(json_url)
status = json.loads(connection.read()) status = json.loads(connection.read())
connection.close() connection.close()
return status['message'] return status['message']
...@@ -5466,7 +5459,7 @@ def main(argv): ...@@ -5466,7 +5459,7 @@ def main(argv):
return dispatcher.execute(OptionParser(), argv) return dispatcher.execute(OptionParser(), argv)
except auth.LoginRequiredError as e: except auth.LoginRequiredError as e:
DieWithError(str(e)) DieWithError(str(e))
except urllib_error.HTTPError as e: except urllib2.HTTPError as e:
if e.code != 500: if e.code != 500:
raise raise
DieWithError( DieWithError(
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
"""Generic presubmit checks that can be reused by other presubmit checks.""" """Generic presubmit checks that can be reused by other presubmit checks."""
from __future__ import print_function from __future__ import print_function
from __future__ import unicode_literals
import os as _os import os as _os
_HERE = _os.path.dirname(_os.path.abspath(__file__)) _HERE = _os.path.dirname(_os.path.abspath(__file__))
...@@ -246,7 +245,7 @@ def CheckGenderNeutral(input_api, output_api, source_file_filter=None): ...@@ -246,7 +245,7 @@ def CheckGenderNeutral(input_api, output_api, source_file_filter=None):
submitted. submitted.
""" """
gendered_re = input_api.re.compile( gendered_re = input_api.re.compile(
r'(^|\s|\(|\[)([Hh]e|[Hh]is|[Hh]ers?|[Hh]im|[Ss]he|[Gg]uys?)\\b') '(^|\s|\(|\[)([Hh]e|[Hh]is|[Hh]ers?|[Hh]im|[Ss]he|[Gg]uys?)\\b')
errors = [] errors = []
for f in input_api.AffectedFiles(include_deletes=False, for f in input_api.AffectedFiles(include_deletes=False,
...@@ -571,7 +570,7 @@ def CheckTreeIsOpen(input_api, output_api, ...@@ -571,7 +570,7 @@ def CheckTreeIsOpen(input_api, output_api,
return [] return []
try: try:
if json_url: if json_url:
connection = input_api.urllib_request.urlopen(json_url) connection = input_api.urllib2.urlopen(json_url)
status = input_api.json.loads(connection.read()) status = input_api.json.loads(connection.read())
connection.close() connection.close()
if not status['can_commit_freely']: if not status['can_commit_freely']:
...@@ -580,7 +579,7 @@ def CheckTreeIsOpen(input_api, output_api, ...@@ -580,7 +579,7 @@ def CheckTreeIsOpen(input_api, output_api,
return [output_api.PresubmitError(short_text, long_text=long_text)] return [output_api.PresubmitError(short_text, long_text=long_text)]
else: else:
# TODO(bradnelson): drop this once all users are gone. # TODO(bradnelson): drop this once all users are gone.
connection = input_api.urllib_request.urlopen(url) connection = input_api.urllib2.urlopen(url)
status = connection.read() status = connection.read()
connection.close() connection.close()
if input_api.re.match(closed, status): if input_api.re.match(closed, status):
...@@ -825,7 +824,7 @@ def GetPylint(input_api, output_api, white_list=None, black_list=None, ...@@ -825,7 +824,7 @@ def GetPylint(input_api, output_api, white_list=None, black_list=None,
The default white_list enforces looking only at *.py files. The default white_list enforces looking only at *.py files.
""" """
white_list = tuple(white_list or (r'.*\.py$',)) white_list = tuple(white_list or ('.*\.py$',))
black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
extra_paths_list = extra_paths_list or [] extra_paths_list = extra_paths_list or []
...@@ -871,11 +870,9 @@ def GetPylint(input_api, output_api, white_list=None, black_list=None, ...@@ -871,11 +870,9 @@ def GetPylint(input_api, output_api, white_list=None, black_list=None,
input_api.logging.info('Running pylint on %d files', len(files)) input_api.logging.info('Running pylint on %d files', len(files))
input_api.logging.debug('Running pylint on: %s', files) input_api.logging.debug('Running pylint on: %s', files)
env = input_api.environ.copy() env = input_api.environ.copy()
# We convert to str, since on Windows on Python 2 only strings are allowed env['PYTHONPATH'] = input_api.os_path.pathsep.join(
# as environment variables, but literals are unicode since we're importing extra_paths_list).encode('utf8')
# unicode_literals from __future__. env.pop('VPYTHON_CLEAR_PYTHONPATH', None)
env[str('PYTHONPATH')] = input_api.os_path.pathsep.join(extra_paths_list)
env.pop(str('VPYTHON_CLEAR_PYTHONPATH'), None)
input_api.logging.debug(' with extra PYTHONPATH: %r', extra_paths_list) input_api.logging.debug(' with extra PYTHONPATH: %r', extra_paths_list)
def GetPylintCmd(flist, extra, parallel): def GetPylintCmd(flist, extra, parallel):
...@@ -942,7 +939,7 @@ def RunPylint(input_api, *args, **kwargs): ...@@ -942,7 +939,7 @@ def RunPylint(input_api, *args, **kwargs):
def CheckBuildbotPendingBuilds(input_api, output_api, url, max_pendings, def CheckBuildbotPendingBuilds(input_api, output_api, url, max_pendings,
ignored): ignored):
try: try:
connection = input_api.urllib_request.urlopen(url) connection = input_api.urllib2.urlopen(url)
raw_data = connection.read() raw_data = connection.read()
connection.close() connection.close()
except IOError: except IOError:
...@@ -1007,7 +1004,7 @@ def CheckOwners(input_api, output_api, source_file_filter=None): ...@@ -1007,7 +1004,7 @@ def CheckOwners(input_api, output_api, source_file_filter=None):
input_api.change.RepositoryRoot(), input_api.change.RepositoryRoot(),
owner_email, owner_email,
reviewers, reviewers,
fopen=open, fopen=file,
os_path=input_api.os_path, os_path=input_api.os_path,
email_postfix='', email_postfix='',
disable_color=True, disable_color=True,
...@@ -1132,7 +1129,7 @@ def PanProjectChecks(input_api, output_api, ...@@ -1132,7 +1129,7 @@ def PanProjectChecks(input_api, output_api,
# 2006-20xx string used on the oldest files. 2006-20xx is deprecated, but # 2006-20xx string used on the oldest files. 2006-20xx is deprecated, but
# tolerated on old files. # tolerated on old files.
current_year = int(input_api.time.strftime('%Y')) current_year = int(input_api.time.strftime('%Y'))
allowed_years = (str(s) for s in reversed(range(2006, current_year + 1))) allowed_years = (str(s) for s in reversed(xrange(2006, current_year + 1)))
years_re = '(' + '|'.join(allowed_years) + '|2006-2008|2006-2009|2006-2010)' years_re = '(' + '|'.join(allowed_years) + '|2006-2008|2006-2009|2006-2010)'
# The (c) is deprecated, but tolerate it until it's removed from all files. # The (c) is deprecated, but tolerate it until it's removed from all files.
...@@ -1161,10 +1158,7 @@ def PanProjectChecks(input_api, output_api, ...@@ -1161,10 +1158,7 @@ def PanProjectChecks(input_api, output_api,
snapshot_memory = [] snapshot_memory = []
def snapshot(msg): def snapshot(msg):
"""Measures & prints performance warning if a rule is running slow.""" """Measures & prints performance warning if a rule is running slow."""
if input_api.sys.version_info.major == 2: dt2 = input_api.time.clock()
dt2 = input_api.time.clock()
else:
dt2 = input_api.time.process_time()
if snapshot_memory: if snapshot_memory:
delta_ms = int(1000*(dt2 - snapshot_memory[0])) delta_ms = int(1000*(dt2 - snapshot_memory[0]))
if delta_ms > 500: if delta_ms > 500:
...@@ -1397,6 +1391,7 @@ def CheckChangedLUCIConfigs(input_api, output_api): ...@@ -1397,6 +1391,7 @@ def CheckChangedLUCIConfigs(input_api, output_api):
import base64 import base64
import json import json
import logging import logging
import urllib2
import auth import auth
import git_cl import git_cl
...@@ -1433,16 +1428,16 @@ def CheckChangedLUCIConfigs(input_api, output_api): ...@@ -1433,16 +1428,16 @@ def CheckChangedLUCIConfigs(input_api, output_api):
def request(endpoint, body=None): def request(endpoint, body=None):
api_url = ('https://%s/_ah/api/config/v1/%s' api_url = ('https://%s/_ah/api/config/v1/%s'
% (LUCI_CONFIG_HOST_NAME, endpoint)) % (LUCI_CONFIG_HOST_NAME, endpoint))
req = input_api.urllib_request.Request(api_url) req = urllib2.Request(api_url)
req.add_header('Authorization', 'Bearer %s' % acc_tkn.token) req.add_header('Authorization', 'Bearer %s' % acc_tkn.token)
if body is not None: if body is not None:
req.add_header('Content-Type', 'application/json') req.add_header('Content-Type', 'application/json')
req.add_data(json.dumps(body)) req.add_data(json.dumps(body))
return json.load(input_api.urllib_request.urlopen(req)) return json.load(urllib2.urlopen(req))
try: try:
config_sets = request('config-sets').get('config_sets') config_sets = request('config-sets').get('config_sets')
except input_api.urllib_error.HTTPError as e: except urllib2.HTTPError as e:
return [output_api.PresubmitError( return [output_api.PresubmitError(
'Config set request to luci-config failed', long_text=str(e))] 'Config set request to luci-config failed', long_text=str(e))]
if not config_sets: if not config_sets:
...@@ -1480,7 +1475,7 @@ def CheckChangedLUCIConfigs(input_api, output_api): ...@@ -1480,7 +1475,7 @@ def CheckChangedLUCIConfigs(input_api, output_api):
cs_to_files[cs].append({ cs_to_files[cs].append({
'path': file_path[len(dr):] if dr != '/' else file_path, 'path': file_path[len(dr):] if dr != '/' else file_path,
'content': base64.b64encode( 'content': base64.b64encode(
'\n'.join(f.NewContents()).encode('utf-8')).decode('utf-8') '\n'.join(f.NewContents()).encode('utf-8'))
}) })
outputs = [] outputs = []
for cs, f in cs_to_files.items(): for cs, f in cs_to_files.items():
...@@ -1488,7 +1483,7 @@ def CheckChangedLUCIConfigs(input_api, output_api): ...@@ -1488,7 +1483,7 @@ def CheckChangedLUCIConfigs(input_api, output_api):
# TODO(myjang): parallelize # TODO(myjang): parallelize
res = request( res = request(
'validate-config', body={'config_set': cs, 'files': f}) 'validate-config', body={'config_set': cs, 'files': f})
except input_api.urllib_error.HTTPError as e: except urllib2.HTTPError as e:
return [output_api.PresubmitError( return [output_api.PresubmitError(
'Validation request to luci-config failed', long_text=str(e))] 'Validation request to luci-config failed', long_text=str(e))]
for msg in res.get('messages', []): for msg in res.get('messages', []):
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
""" """
from __future__ import print_function from __future__ import print_function
from __future__ import unicode_literals
__version__ = '1.8.0' __version__ = '1.8.0'
...@@ -34,6 +33,7 @@ import sys # Parts exposed through API. ...@@ -34,6 +33,7 @@ import sys # Parts exposed through API.
import tempfile # Exposed through the API. import tempfile # Exposed through the API.
import threading import threading
import time import time
import types
import unittest # Exposed through the API. import unittest # Exposed through the API.
from warnings import warn from warnings import warn
...@@ -542,12 +542,10 @@ class InputApi(object): ...@@ -542,12 +542,10 @@ class InputApi(object):
self.os_walk = os.walk self.os_walk = os.walk
self.re = re self.re = re
self.subprocess = subprocess self.subprocess = subprocess
self.sys = sys
self.tempfile = tempfile self.tempfile = tempfile
self.time = time self.time = time
self.unittest = unittest self.unittest = unittest
if sys.version_info.major == 2: self.urllib2 = urllib2
self.urllib2 = urllib2
self.urllib_request = urllib_request self.urllib_request = urllib_request
self.urllib_error = urllib_error self.urllib_error = urllib_error
...@@ -577,7 +575,7 @@ class InputApi(object): ...@@ -577,7 +575,7 @@ class InputApi(object):
# TODO(dpranke): figure out a list of all approved owners for a repo # TODO(dpranke): figure out a list of all approved owners for a repo
# in order to be able to handle wildcard OWNERS files? # in order to be able to handle wildcard OWNERS files?
self.owners_db = owners.Database(change.RepositoryRoot(), self.owners_db = owners.Database(change.RepositoryRoot(),
fopen=open, os_path=self.os_path) fopen=file, os_path=self.os_path)
self.owners_finder = owners_finder.OwnersFinder self.owners_finder = owners_finder.OwnersFinder
self.verbose = verbose self.verbose = verbose
self.Command = CommandData self.Command = CommandData
...@@ -611,9 +609,9 @@ class InputApi(object): ...@@ -611,9 +609,9 @@ class InputApi(object):
if len(dir_with_slash) == 1: if len(dir_with_slash) == 1:
dir_with_slash = '' dir_with_slash = ''
return list(filter( return filter(
lambda x: normpath(x.AbsoluteLocalPath()).startswith(dir_with_slash), lambda x: normpath(x.AbsoluteLocalPath()).startswith(dir_with_slash),
self.change.AffectedFiles(include_deletes, file_filter))) self.change.AffectedFiles(include_deletes, file_filter))
def LocalPaths(self): def LocalPaths(self):
"""Returns local paths of input_api.AffectedFiles().""" """Returns local paths of input_api.AffectedFiles()."""
...@@ -635,9 +633,8 @@ class InputApi(object): ...@@ -635,9 +633,8 @@ class InputApi(object):
" is deprecated and ignored" % str(include_deletes), " is deprecated and ignored" % str(include_deletes),
category=DeprecationWarning, category=DeprecationWarning,
stacklevel=2) stacklevel=2)
return list(filter( return filter(lambda x: x.IsTestableFile(),
lambda x: x.IsTestableFile(), self.AffectedFiles(include_deletes=False, **kwargs))
self.AffectedFiles(include_deletes=False, **kwargs)))
def AffectedTextFiles(self, include_deletes=None): def AffectedTextFiles(self, include_deletes=None):
"""An alias to AffectedTestableFiles for backwards compatibility.""" """An alias to AffectedTestableFiles for backwards compatibility."""
...@@ -670,7 +667,7 @@ class InputApi(object): ...@@ -670,7 +667,7 @@ class InputApi(object):
""" """
if not source_file: if not source_file:
source_file = self.FilterSourceFile source_file = self.FilterSourceFile
return list(filter(source_file, self.AffectedTestableFiles())) return filter(source_file, self.AffectedTestableFiles())
def RightHandSideLines(self, source_file_filter=None): def RightHandSideLines(self, source_file_filter=None):
"""An iterator over all text lines in "new" version of changed files. """An iterator over all text lines in "new" version of changed files.
...@@ -1097,11 +1094,11 @@ class Change(object): ...@@ -1097,11 +1094,11 @@ class Change(object):
Returns: Returns:
[AffectedFile(path, action), AffectedFile(path, action)] [AffectedFile(path, action), AffectedFile(path, action)]
""" """
affected = list(filter(file_filter, self._affected_files)) affected = filter(file_filter, self._affected_files)
if include_deletes: if include_deletes:
return affected return affected
return list(filter(lambda x: x.Action() != 'D', affected)) return filter(lambda x: x.Action() != 'D', affected)
def AffectedTestableFiles(self, include_deletes=None, **kwargs): def AffectedTestableFiles(self, include_deletes=None, **kwargs):
"""Return a list of the existing text files in a change.""" """Return a list of the existing text files in a change."""
...@@ -1110,9 +1107,8 @@ class Change(object): ...@@ -1110,9 +1107,8 @@ class Change(object):
" is deprecated and ignored" % str(include_deletes), " is deprecated and ignored" % str(include_deletes),
category=DeprecationWarning, category=DeprecationWarning,
stacklevel=2) stacklevel=2)
return list(filter( return filter(lambda x: x.IsTestableFile(),
lambda x: x.IsTestableFile(), self.AffectedFiles(include_deletes=False, **kwargs))
self.AffectedFiles(include_deletes=False, **kwargs)))
def AffectedTextFiles(self, include_deletes=None): def AffectedTextFiles(self, include_deletes=None):
"""An alias to AffectedTestableFiles for backwards compatibility.""" """An alias to AffectedTestableFiles for backwards compatibility."""
...@@ -1449,9 +1445,9 @@ class PresubmitExecuter(object): ...@@ -1449,9 +1445,9 @@ class PresubmitExecuter(object):
logging.debug('Running %s done.', function_name) logging.debug('Running %s done.', function_name)
self.more_cc.extend(output_api.more_cc) self.more_cc.extend(output_api.more_cc)
finally: finally:
for f in input_api._named_temporary_files: map(os.remove, input_api._named_temporary_files)
os.remove(f) if not (isinstance(result, types.TupleType) or
if not isinstance(result, (tuple, list)): isinstance(result, types.ListType)):
raise PresubmitFailure( raise PresubmitFailure(
'Presubmit functions must return a tuple or list') 'Presubmit functions must return a tuple or list')
for item in result: for item in result:
...@@ -1573,8 +1569,7 @@ def DoPresubmitChecks(change, ...@@ -1573,8 +1569,7 @@ def DoPresubmitChecks(change,
] ]
} }
gclient_utils.FileWrite( gclient_utils.FileWrite(json_output, json.dumps(presubmit_results))
json_output, json.dumps(presubmit_results, sort_keys=True))
output.write('\n') output.write('\n')
for name, items in (('Messages', notifications), for name, items in (('Messages', notifications),
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment