Commit 16af3560 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

presubmit: Remove unused imports.

Some of the modules imported by presubmit_support are unused, and some of those (cPickle, cStringIO) are not available on Python3, so remove them.
Also expose urllib2 via urllib_request and urllib_error to improve compatibility with Python3.

Bug: 1009814
Change-Id: I9f758df4270cc039df092e814c981a7a87b2c350
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1866170
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent fd843fa4
......@@ -16,20 +16,16 @@ __version__ = '1.8.0'
import ast # Exposed through the API.
import contextlib
import cPickle # Exposed through the API.
import cpplint
import cStringIO # Exposed through the API.
import fnmatch # Exposed through the API.
import glob
import inspect
import itertools
import json # Exposed through the API.
import logging
import marshal # Exposed through the API.
import multiprocessing
import optparse
import os # Somewhat exposed through the API.
import pickle # Exposed through the API.
import random
import re # Exposed through the API.
import signal
......@@ -37,11 +33,8 @@ import sys # Parts exposed through API.
import tempfile # Exposed through the API.
import threading
import time
import traceback # Exposed through the API.
import types
import unittest # Exposed through the API.
import urllib2 # Exposed through the API.
import urlparse
from warnings import warn
# Local imports.
......@@ -56,6 +49,16 @@ import presubmit_canned_checks
import scm
import subprocess2 as subprocess # Exposed through the API.
if sys.version_info.major == 2:
# TODO(1009814): Expose urllib2 only through urllib_request and urllib_error
import urllib2 # Exposed through the API.
import urlparse
import urllib2 as urllib_request
import urllib2 as urllib_error
else:
import urllib.parse as urlparse
import urllib.request as urllib_request
import urllib.error as urllib_error
# Ask for feedback only once in program lifetime.
_ASKED_FOR_FEEDBACK = False
......@@ -524,9 +527,7 @@ class InputApi(object):
# so that presubmit scripts don't have to import them.
self.ast = ast
self.basename = os.path.basename
self.cPickle = cPickle
self.cpplint = cpplint
self.cStringIO = cStringIO
self.fnmatch = fnmatch
self.gclient_paths = gclient_paths
# TODO(yyanagisawa): stop exposing this when python3 become default.
......@@ -535,19 +536,18 @@ class InputApi(object):
self.glob = glob.glob
self.json = json
self.logging = logging.getLogger('PRESUBMIT')
self.marshal = marshal
self.os_listdir = os.listdir
self.os_path = os.path
self.os_stat = os.stat
self.os_walk = os.walk
self.pickle = pickle
self.re = re
self.subprocess = subprocess
self.tempfile = tempfile
self.time = time
self.traceback = traceback
self.unittest = unittest
self.urllib2 = urllib2
self.urllib_request = urllib_request
self.urllib_error = urllib_error
self.is_windows = sys.platform == 'win32'
......
......@@ -1425,7 +1425,6 @@ class CannedChecksUnittest(PresubmitTestsBase):
input_api = mock.MagicMock(presubmit.InputApi)
input_api.thread_pool = presubmit.ThreadPool()
input_api.parallel = False
input_api.cStringIO = presubmit.cStringIO
input_api.json = presubmit.json
input_api.logging = logging
input_api.os_listdir = mock.Mock()
......@@ -1433,8 +1432,9 @@ class CannedChecksUnittest(PresubmitTestsBase):
input_api.os_path = os.path
input_api.re = presubmit.re
input_api.gerrit = mock.MagicMock(presubmit.GerritAccessor)
input_api.traceback = presubmit.traceback
input_api.urllib2 = mock.MagicMock(presubmit.urllib2)
input_api.urllib_request = mock.MagicMock(presubmit.urllib_request)
input_api.urllib_error = mock.MagicMock(presubmit.urllib_error)
input_api.unittest = unittest
input_api.subprocess = subprocess
class fake_CalledProcessError(Exception):
......@@ -2041,7 +2041,6 @@ the current line as well!
def testRunPythonUnitTestsFailureUpload(self):
input_api = self.MockInputApi(None, False)
input_api.unittest = mock.MagicMock(unittest)
input_api.cStringIO = mock.MagicMock(presubmit.cStringIO)
subprocess.Popen().returncode = 1 # pylint: disable=no-value-for-parameter
presubmit.sigint_handler.wait.return_value = ('foo', None)
......@@ -2065,7 +2064,6 @@ the current line as well!
def testRunPythonUnitTestsSuccess(self):
input_api = self.MockInputApi(None, False)
input_api.cStringIO = mock.MagicMock(presubmit.cStringIO)
input_api.unittest = mock.MagicMock(unittest)
subprocess.Popen().returncode = 0 # pylint: disable=no-value-for-parameter
presubmit.sigint_handler.wait.return_value = ('', None)
......@@ -2157,7 +2155,7 @@ the current line as well!
os.path.exists = lambda _: True
owners_file = presubmit.cStringIO.StringIO(owners_content)
owners_file = StringIO.StringIO(owners_content)
fopen = lambda *args: owners_file
input_api.owners_db = owners.Database('', fopen, os.path)
......
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