Skip to content

Commit

Permalink
finish Python 2 -> 3 migration, remove dependecy on Six
Browse files Browse the repository at this point in the history
  • Loading branch information
a-detiste authored and tobias-urdin committed Aug 20, 2024
1 parent a7f9e4e commit 965d143
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 32 deletions.
19 changes: 9 additions & 10 deletions gnocchiclient/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import copyreg
import datetime
import functools
import itertools
Expand All @@ -27,8 +28,6 @@

import iso8601

import six.moves

from gnocchiclient import utils
from gnocchiclient.v1 import metric_cli

Expand All @@ -43,7 +42,7 @@ def _pickle_method(m):
return getattr, (m.im_self, m.im_func.func_name)


six.moves.copyreg.pickle(types.MethodType, _pickle_method)
copyreg.pickle(types.MethodType, _pickle_method)


def _positive_non_zero_int(argument_value):
Expand All @@ -60,7 +59,7 @@ def _positive_non_zero_int(argument_value):
return value


class StopWatch(object):
class StopWatch:
def __init__(self):
self.started_at = time.monotonic()

Expand All @@ -79,7 +78,7 @@ def submit_job(self, times, fn, *args, **kwargs):
self.sw = StopWatch()
self.times = times
return [self.submit(measure_job, fn, *args, **kwargs)
for i in six.moves.range(times)]
for i in range(times)]

def map_job(self, fn, iterable, **kwargs):
r = []
Expand Down Expand Up @@ -283,13 +282,13 @@ def take_action(self, parsed_args):
"for the number of points")

random_values = (random.randint(- 2 ** 32, 2 ** 32)
for _ in six.moves.range(count))
for _ in range(count))
measures = [{"timestamp": ts, "value": v}
for ts, v
in six.moves.zip(
six.moves.range(start,
end,
(end - start) // count),
in zip(
range(start,
end,
(end - start) // count),
random_values)]

times = parsed_args.count // parsed_args.batch
Expand Down
4 changes: 1 addition & 3 deletions gnocchiclient/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

import re

import six


class ClientException(Exception):
"""The base exception class for all exceptions this library raises."""
Expand Down Expand Up @@ -250,7 +248,7 @@ def from_response(response, method=None):
if 'description' in body:
# Gnocchi json
desc = body.get('description')
if desc and isinstance(desc, six.text_type):
if desc and isinstance(desc, str):
for enhanced_cls in enhanced_classes:
if enhanced_cls.match.match(desc):
cls = enhanced_cls
Expand Down
2 changes: 0 additions & 2 deletions gnocchiclient/gendoc.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.

from __future__ import absolute_import

import fnmatch

from cliff import sphinxext
Expand Down
6 changes: 0 additions & 6 deletions gnocchiclient/tests/functional/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import time
import unittest

import six


class ClientTestBase(unittest.TestCase):
"""Base class for gnocchiclient tests.
Expand Down Expand Up @@ -57,8 +55,6 @@ def _run(self, binary, action, flags='', params='',

cmd = ' '.join([os.path.join(self.cli_dir, binary),
flags, action, params, fmt])
if six.PY2:
cmd = cmd.encode('utf-8')
cmd = shlex.split(cmd)
result = ''
result_err = ''
Expand All @@ -73,8 +69,6 @@ def _run(self, binary, action, flags='', params='',
cmd,
result,
result_err)
if not six.PY2:
result = os.fsdecode(result)

if not has_output and not fail_ok and action != 'help':
self.assertEqual("", result)
Expand Down
8 changes: 3 additions & 5 deletions gnocchiclient/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import urllib.parse
from dateutil import tz

import iso8601

import six
from six.moves.urllib import parse as urllib_parse


def add_query_argument(cmd, parser, *args, **kwargs):
return parser.add_argument(
Expand Down Expand Up @@ -104,8 +102,8 @@ def dict_to_querystring(objs):
values = [values]
strings.append("&".join(
("%s=%s" % (k, v)
for v in map(urllib_parse.quote,
map(six.text_type, values)))))
for v in map(urllib.parse.quote,
map(str, values)))))
return "&".join(strings)


Expand Down
6 changes: 2 additions & 4 deletions gnocchiclient/v1/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.

import six


class Manager(object):
class Manager:
DEFAULT_HEADERS = {
"Accept": "application/json",
}
Expand All @@ -26,7 +24,7 @@ def __init__(self, client):

def _set_default_headers(self, kwargs):
headers = kwargs.get('headers', {})
for k, v in six.iteritems(self.DEFAULT_HEADERS):
for k, v in self.DEFAULT_HEADERS.items():
if k not in headers:
headers[k] = v
kwargs['headers'] = headers
Expand Down
2 changes: 1 addition & 1 deletion gnocchiclient/v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from gnocchiclient.v1 import status


class Client(object):
class Client:
"""Client for the Gnocchi v1 API.
:param session: keystoneauth1 session
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ install_requires =
cliff>=2.10 # Apache-2.0
ujson
keystoneauth1>=2.0.0
six
futurist
iso8601
python-dateutil
Expand Down

0 comments on commit 965d143

Please sign in to comment.