aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-07-15 00:55:02 -0400
committerMike Frysinger <vapier@google.com>2020-11-03 16:00:14 -0500
commit737bf2785d1be8e857943224b401750d0b5f2184 (patch)
tree7a7427da8429c269aceb4b7096f53b2a11ede9ca
parent239625cee5e913e15ea070862a7921759d27dca6 (diff)
downloadrepohooks-737bf2785d1be8e857943224b401750d0b5f2184.tar.gz
sixish: delete Python 2/3 compat module
We require Python 3 everywhere, so no point in this. Bug: None Test: unittests pass Change-Id: If47bc351829610f7d7677f5255dc433ca1294079
-rwxr-xr-xpre-upload.py3
-rw-r--r--rh/config.py2
-rw-r--r--rh/hooks.py5
-rwxr-xr-xrh/hooks_unittest.py7
-rw-r--r--rh/shell.py5
-rw-r--r--rh/sixish.py69
-rw-r--r--rh/utils.py5
7 files changed, 10 insertions, 86 deletions
diff --git a/pre-upload.py b/pre-upload.py
index e7ef564..eaf611e 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -47,7 +47,6 @@ import rh.results
import rh.config
import rh.git
import rh.hooks
-import rh.sixish
import rh.terminal
import rh.utils
@@ -297,7 +296,7 @@ def _run_project_hooks_in_cwd(project_name, proj_dir, output, commit_list=None):
os.environ['PREUPLOAD_COMMIT'] = commit
diff = rh.git.get_affected_files(commit)
desc = rh.git.get_commit_desc(commit)
- rh.sixish.setenv('PREUPLOAD_COMMIT_MESSAGE', desc)
+ os.environ['PREUPLOAD_COMMIT_MESSAGE'] = desc
commit_summary = desc.split('\n', 1)[0]
output.commit_start(commit=commit, commit_summary=commit_summary)
diff --git a/rh/config.py b/rh/config.py
index e2ad713..b75e03b 100644
--- a/rh/config.py
+++ b/rh/config.py
@@ -17,6 +17,7 @@
from __future__ import print_function
+import configparser
import functools
import itertools
import os
@@ -31,7 +32,6 @@ del _path
# pylint: disable=wrong-import-position
import rh.hooks
import rh.shell
-from rh.sixish import configparser
class Error(Exception):
diff --git a/rh/hooks.py b/rh/hooks.py
index dd4cab3..31de509 100644
--- a/rh/hooks.py
+++ b/rh/hooks.py
@@ -33,7 +33,6 @@ del _path
# pylint: disable=wrong-import-position
import rh.git
import rh.results
-from rh.sixish import string_types
import rh.utils
@@ -89,7 +88,7 @@ class Placeholders(object):
for key, val in replacements.items():
var = '${%s}' % (key,)
if arg == var:
- if isinstance(val, string_types):
+ if isinstance(val, str):
ret.append(val)
else:
ret.extend(val)
@@ -99,7 +98,7 @@ class Placeholders(object):
# If no exact matches, do an inline replacement.
def replace(m):
val = self.get(m.group(1))
- if isinstance(val, string_types):
+ if isinstance(val, str):
return val
return ' '.join(val)
ret.append(re.sub(r'\$\{(%s)\}' % ('|'.join(all_vars),),
diff --git a/rh/hooks_unittest.py b/rh/hooks_unittest.py
index 12059f8..33b911d 100755
--- a/rh/hooks_unittest.py
+++ b/rh/hooks_unittest.py
@@ -21,6 +21,7 @@ from __future__ import print_function
import os
import sys
import unittest
+from unittest import mock
_path = os.path.realpath(__file__ + '/../..')
if sys.path[0] != _path:
@@ -33,8 +34,6 @@ del _path
import rh
import rh.config
import rh.hooks
-from rh.sixish import mock
-from rh.sixish import string_types
class HooksDocsTests(unittest.TestCase):
@@ -261,14 +260,14 @@ class UtilsTests(unittest.TestCase):
# Just verify it returns something and doesn't crash.
# pylint: disable=protected-access
ret = rh.hooks._get_build_os_name()
- self.assertTrue(isinstance(ret, string_types))
+ self.assertTrue(isinstance(ret, str))
self.assertNotEqual(ret, '')
def testGetHelperPath(self):
"""Check get_helper_path behavior."""
# Just verify it doesn't crash. It's a dirt simple func.
ret = rh.hooks.get_helper_path('booga')
- self.assertTrue(isinstance(ret, string_types))
+ self.assertTrue(isinstance(ret, str))
self.assertNotEqual(ret, '')
diff --git a/rh/shell.py b/rh/shell.py
index f466f63..4c6c45c 100644
--- a/rh/shell.py
+++ b/rh/shell.py
@@ -25,9 +25,6 @@ if sys.path[0] != _path:
sys.path.insert(0, _path)
del _path
-# pylint: disable=wrong-import-position
-from rh.sixish import string_types
-
# For use by ShellQuote. Match all characters that the shell might treat
# specially. This means a number of things:
@@ -156,7 +153,7 @@ def boolean_shell_value(sval, default):
if sval is None:
return default
- if isinstance(sval, string_types):
+ if isinstance(sval, str):
s = sval.lower()
if s in ('yes', 'y', '1', 'true'):
return True
diff --git a/rh/sixish.py b/rh/sixish.py
deleted file mode 100644
index 693598c..0000000
--- a/rh/sixish.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# -*- coding:utf-8 -*-
-# Copyright 2017 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Local version of the standard six module.
-
-Since this module is often unavailable by default on distros (or only available
-for specific versions), manage our own little copy.
-"""
-
-from __future__ import print_function
-
-import os
-import sys
-
-_path = os.path.realpath(__file__ + '/../..')
-if sys.path[0] != _path:
- sys.path.insert(0, _path)
-del _path
-
-
-# Our attempts to wrap things below for diff versions of python confuse pylint.
-# pylint: disable=import-error,no-name-in-module,unused-import
-
-
-try:
- import configparser
-except ImportError:
- import ConfigParser as configparser
-
-
-# We allow mock to be disabled as it's not needed by non-unittest code.
-try:
- import unittest.mock as mock
-except ImportError:
- try:
- import mock
- except ImportError:
- pass
-
-
-if sys.version_info.major < 3:
- # pylint: disable=basestring-builtin,undefined-variable
- string_types = basestring
-else:
- string_types = str
-
-
-def setenv(var, val):
- """Set |var| in the environment to |val|.
-
- Python 2 wants ASCII strings, not unicode.
- Python 3 only wants unicode strings.
- """
- try:
- os.environ[var] = val
- except UnicodeEncodeError:
- os.environ[var] = val.encode('utf-8')
diff --git a/rh/utils.py b/rh/utils.py
index 6486e1b..5c3e753 100644
--- a/rh/utils.py
+++ b/rh/utils.py
@@ -34,7 +34,6 @@ del _path
# pylint: disable=wrong-import-position
import rh.shell
import rh.signals
-from rh.sixish import string_types
def timedelta_str(delta):
@@ -354,14 +353,14 @@ def run(cmd, redirect_stdout=False, redirect_stderr=False, cwd=None, input=None,
# If input is a string, we'll create a pipe and send it through that.
# Otherwise we assume it's a file object that can be read from directly.
- if isinstance(input, string_types):
+ if isinstance(input, str):
stdin = subprocess.PIPE
input = input.encode('utf-8')
elif input is not None:
stdin = input
input = None
- if isinstance(cmd, string_types):
+ if isinstance(cmd, str):
if not shell:
raise Exception('Cannot run a string command without a shell')
cmd = ['/bin/bash', '-c', cmd]