Skip to content

Commit

Permalink
Remove six usage
Browse files Browse the repository at this point in the history
six library helped a lot for Py2/Py3 compatibility. Thanks the authors
for the great library.

Since we do not support Python 2, there is no need in six anymore

Change-Id: If5213c088964aa137e6ff5ac2c376a02a980aa72
  • Loading branch information
andreykurilin committed Feb 21, 2020
1 parent 2c6a3ba commit 1821656
Show file tree
Hide file tree
Showing 57 changed files with 212 additions and 320 deletions.
2 changes: 1 addition & 1 deletion rally/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def is_really_missing(mis, task_template):
# builtin functions (e.g. range()). Unfortunately,
# __builtins__ doesn't return them (when it is not
# main module)
from six.moves import builtins
import builtins

env = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_dir, encoding="utf8"))
Expand Down
7 changes: 3 additions & 4 deletions rally/cli/cliutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import jsonschema
import prettytable
import six
import sqlalchemy.exc

from rally import api
Expand Down Expand Up @@ -211,10 +210,10 @@ def print_dict(obj, fields=None, formatters=None, mixed_case_fields=False,
if isinstance(data, (dict, list)):
data = json.dumps(data)
if wrap > 0:
data = textwrap.fill(six.text_type(data), wrap)
data = textwrap.fill(str(data), wrap)
# if value has a newline, add in multiple rows
# e.g. fault with stacktrace
if (data and isinstance(data, six.string_types)
if (data and isinstance(data, str)
and (r"\n" in data or "\r" in data)):
# "\r" would break the table, so remove it.
if "\r" in data:
Expand Down Expand Up @@ -623,7 +622,7 @@ def run(argv, categories):
v = getattr(CONF.category, "action_kwarg_" + k)
if v is None:
continue
if isinstance(v, six.string_types):
if isinstance(v, str):
v = encodeutils.safe_decode(v)
fn_kwargs[k] = v

Expand Down
7 changes: 3 additions & 4 deletions rally/cli/commands/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import webbrowser

import jsonschema
import six

from rally.cli import cliutils
from rally.cli import envutils
Expand Down Expand Up @@ -179,7 +178,7 @@ def _load_and_validate_task(self, api, task_file, args_file=None,
if raw_args:
try:
data = yaml.safe_load(raw_args)
if isinstance(data, (six.text_type, six.string_types)):
if isinstance(data, str):
raise yaml.ParserError("String '%s' doesn't look like a "
"dictionary." % raw_args)
task_args.update(data)
Expand Down Expand Up @@ -709,7 +708,7 @@ def _load_task_results_file(self, api, task_id):
result, OLD_TASK_RESULT_SCHEMA)
except jsonschema.ValidationError as e:
raise FailedToLoadResults(source=task_id,
msg=six.text_type(e))
msg=str(e))

iter_count = 0
failed_iter_count = 0
Expand Down Expand Up @@ -795,7 +794,7 @@ def _load_task_results_file(self, api, task_id):
jsonschema.validate(task_result,
api.task.TASK_SCHEMA)
except jsonschema.ValidationError as e:
msg = six.text_type(e)
msg = str(e)
raise exceptions.RallyException(
"ERROR: Invalid task result format\n\n\t%s" % msg)
task_result.setdefault("env_name", "n/a")
Expand Down
3 changes: 1 addition & 2 deletions rally/cli/commands/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

from __future__ import print_function

import configparser
import datetime as dt
import json
import os
import webbrowser

from six.moves import configparser

from rally.cli import cliutils
from rally.cli import envutils
from rally.common import fileutils
Expand Down
6 changes: 2 additions & 4 deletions rally/common/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

import datetime as dt
import functools
import six
import tempfile
import time

Expand Down Expand Up @@ -101,9 +100,8 @@ def engine_reset():
def serialize(data):
if data is None:
return None
if isinstance(data, (six.integer_types,
six.string_types,
six.text_type,
if isinstance(data, (int,
str,
dt.date,
dt.time,
float,
Expand Down
3 changes: 1 addition & 2 deletions rally/common/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import datetime as dt
import uuid

import six
import sqlalchemy as sa
import sqlalchemy.ext.declarative
import sqlalchemy.orm # noqa (used as sa.orm)
Expand All @@ -34,7 +33,7 @@ def UUID():
return str(uuid.uuid4())


class RallyBase(six.Iterator):
class RallyBase(object):
"""Base class for models."""
__table_initialized__ = False
metadata = None
Expand Down
3 changes: 1 addition & 2 deletions rally/common/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from oslo_log import handlers
from oslo_log import log as oslogging
import six

from rally.common import cfg

Expand Down Expand Up @@ -107,7 +106,7 @@ def error(self, msg, *args, **kwargs):
self.log(log.ERROR, msg, *args, **kwargs)

def exception(self, msg, exc_info=True, *args, **kwargs):
if not isinstance(msg, (six.text_type, six.string_types)):
if not isinstance(msg, str):
caller = self._find_the_caller()
logger = getLogger("%s:%s" % (caller[0], caller[1]))
logger.warning("[%s] %s" % (caller[2], self._exc_msg))
Expand Down
3 changes: 1 addition & 2 deletions rally/common/objects/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import collections
import copy
import datetime as dt
import six
import uuid

from rally.common import db
Expand Down Expand Up @@ -451,7 +450,7 @@ def result_has_valid_schema(self, result):
actions_list.extend(action["children"])

for e in result["error"]:
if not isinstance(e, (six.string_types, six.text_type)):
if not isinstance(e, str):
LOG.warning("error value has wrong type '%s', should be 'str'"
% type(e))
return False
Expand Down
4 changes: 1 addition & 3 deletions rally/common/plugin/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import pkgutil
import sys

import six

import rally
from rally.common import logging

Expand Down Expand Up @@ -121,7 +119,7 @@ def import_modules_by_entry_point(_packages=None):
if logging.is_debug():
LOG.exception(msg)
else:
LOG.warning(msg + (": %s" % six.text_type(e)))
LOG.warning(msg + (": %s" % str(e)))
return loaded_packages


Expand Down
3 changes: 0 additions & 3 deletions rally/common/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ def base():
- Plugin lookup - one can easily get all plugins from some base.
Plugin bases by default initialize _default_meta
.. warning:: This decorator should be added the line before
six.add_metaclass if it is used.
"""
def wrapper(cls):
if not issubclass(cls, Plugin):
Expand Down
17 changes: 9 additions & 8 deletions rally/common/sshutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ def write(chunk):
"""

import io
import os
import select
import shlex
import socket
import time

import paramiko
import six

from rally.common import logging
from rally import exceptions
Expand Down Expand Up @@ -95,8 +96,8 @@ def __init__(self, user, host, port=22, pkey=None,
self._client = False

def _get_pkey(self, key):
if isinstance(key, six.string_types):
key = six.moves.StringIO(key)
if isinstance(key, str):
key = io.StringIO(key)
errors = []
key_pos = key.seek(0, 1)
for key_class in (paramiko.rsakey.RSAKey, paramiko.dsskey.DSSKey):
Expand Down Expand Up @@ -149,8 +150,8 @@ def run(self, cmd, stdin=None, stdout=None, stderr=None,

client = self._get_client()

if isinstance(stdin, six.string_types):
stdin = six.moves.StringIO(stdin)
if isinstance(stdin, str):
stdin = io.StringIO(stdin)

return self._run(client, cmd, stdin=stdin, stdout=stdout,
stderr=stderr, raise_on_error=raise_on_error,
Expand All @@ -160,7 +161,7 @@ def _run(self, client, cmd, stdin=None, stdout=None, stderr=None,
raise_on_error=True, timeout=3600):

if isinstance(cmd, (list, tuple)):
cmd = " ".join(six.moves.shlex_quote(str(p)) for p in cmd)
cmd = " ".join(shlex.quote(str(p)) for p in cmd)

transport = client.get_transport()
session = transport.open_session()
Expand Down Expand Up @@ -238,8 +239,8 @@ def execute(self, cmd, stdin=None, timeout=3600):
:returns: tuple (exit_status, stdout, stderr)
"""
stdout = six.moves.StringIO()
stderr = six.moves.StringIO()
stdout = io.StringIO()
stderr = io.StringIO()

exit_status, data = self.run(cmd, stderr=stderr, stdout=stdout,
stdin=stdin, timeout=timeout,
Expand Down
5 changes: 1 addition & 4 deletions rally/common/streaming_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
import math
import os

import six

from rally.common import utils as cutils


@six.add_metaclass(abc.ABCMeta)
class StreamingAlgorithm(object):
class StreamingAlgorithm(object, metaclass=abc.ABCMeta):
"""Base class for streaming computations that scale."""

@abc.abstractmethod
Expand Down
5 changes: 1 addition & 4 deletions rally/common/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import abc
import traceback

import six

from rally.common import logging
from rally.common.plugin import plugin
from rally import exceptions
Expand All @@ -38,8 +36,7 @@ def wrapper(cls):


@plugin.base()
@six.add_metaclass(abc.ABCMeta)
class Validator(plugin.Plugin):
class Validator(plugin.Plugin, metaclass=abc.ABCMeta):
"""A base class for all validators."""

def __init__(self):
Expand Down
4 changes: 1 addition & 3 deletions rally/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import six

from rally.common.plugin import discover


Expand All @@ -41,7 +39,7 @@ def __init__(self, message=None, **kwargs):
super(RallyException, self).__init__(self.msg_fmt % kwargs)

def format_message(self):
return six.text_type(self)
return str(self)


def find_exception(response):
Expand Down
3 changes: 1 addition & 2 deletions rally/plugins/common/exporters/elastic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import copy

import requests
import six

from rally.common import logging
from rally import exceptions
Expand Down Expand Up @@ -95,7 +94,7 @@ def push_documents(self, documents):
# in `documents` (action and document itself).
(len(documents) / 2, self.CHUNK_LENGTH / 2))

for pos in six.moves.range(0, len(documents), self.CHUNK_LENGTH):
for pos in range(0, len(documents), self.CHUNK_LENGTH):
data = "\n".join(documents[pos:pos + self.CHUNK_LENGTH]) + "\n"

raw_resp = requests.post(
Expand Down
4 changes: 1 addition & 3 deletions rally/plugins/common/exporters/elastic/flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import six


def _join_keys(first, second):
if not second:
Expand All @@ -25,7 +23,7 @@ def _join_keys(first, second):


def _process(obj):
if isinstance(obj, (six.string_types, six.binary_type)):
if isinstance(obj, (str, bytes)):
yield "", obj
elif isinstance(obj, dict):
for first, tmp_value in obj.items():
Expand Down
3 changes: 1 addition & 2 deletions rally/plugins/common/runners/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

import collections
import multiprocessing
import queue as Queue
import threading
import time

from six.moves import queue as Queue

from rally.common import utils
from rally.common import validation
from rally import consts
Expand Down
2 changes: 1 addition & 1 deletion rally/plugins/common/runners/rps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

import collections
import multiprocessing
import queue as Queue
import threading
import time

from six.moves import queue as Queue

from rally.common import logging
from rally.common import utils
Expand Down
5 changes: 2 additions & 3 deletions rally/plugins/common/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import os

import jsonschema
import six

from rally.common import logging
from rally.common import validation
Expand Down Expand Up @@ -193,7 +192,7 @@ def __init__(self, param_name, values, missed=False,
if self.case_insensitive:
self.values = []
for value in values:
if isinstance(value, (six.text_type, six.string_types)):
if isinstance(value, str):
value = value.lower()
self.values.append(value)
else:
Expand All @@ -203,7 +202,7 @@ def validate(self, context, config, plugin_cls, plugin_cfg):
value = config.get("args", {}).get(self.param_name)
if value:
if self.case_insensitive:
if isinstance(value, (six.text_type, six.string_types)):
if isinstance(value, str):
value = value.lower()

if value not in self.values:
Expand Down

0 comments on commit 1821656

Please sign in to comment.