Stop using six library

Since we've dropped support for Python 2.7, it's time to look at
the bright future that Python 3.x will bring and stop forcing
compatibility with older versions.
This patch removes the six library from requirements, not
looking back.

Change-Id: I19384db89fc2a68376efc3f9f2e05fbd05046fd6
This commit is contained in:
Iury Gregory Melo Ferreira 2019-12-03 15:14:48 +01:00
parent 33871b187b
commit c765bbe8a8
8 changed files with 18 additions and 27 deletions

View File

@ -10,6 +10,5 @@ pbr==2.0.0
PrettyTable==0.7.2
Pygments==2.2.0
requests==2.18.4
six==1.10.0
stestr==1.0.0
testtools==2.2.0

View File

@ -17,7 +17,6 @@ import logging
from openstack import connection
from openstack import exceptions as os_exc
import six
from metalsmith import _instance
from metalsmith import _nics
@ -143,7 +142,7 @@ class Provisioner(object):
"""Create an allocation with given parameters."""
if candidates:
candidates = [
(node.id if not isinstance(node, six.string_types) else node)
(node.id if not isinstance(node, str) else node)
for node in candidates
]
@ -370,7 +369,7 @@ class Provisioner(object):
"""
if config is None:
config = instance_config.GenericConfig()
if isinstance(image, six.string_types):
if isinstance(image, str):
image = sources.GlanceImage(image)
_utils.check_hostname(hostname)
@ -620,7 +619,7 @@ class Provisioner(object):
def _get_node(self, node, refresh=False):
"""A helper to find and return a node."""
if isinstance(node, six.string_types):
if isinstance(node, str):
return self.connection.baremetal.get_node(node)
elif hasattr(node, 'node'):
# Instance object
@ -635,7 +634,7 @@ class Provisioner(object):
def _find_node_and_allocation(self, node, refresh=False):
try:
if (not isinstance(node, six.string_types)
if (not isinstance(node, str)
or not _utils.is_hostname_safe(node)):
return self._get_node(node, refresh=refresh), None

View File

@ -17,8 +17,6 @@ import abc
import collections
import logging
import six
from metalsmith import _utils
from metalsmith import exceptions
@ -26,8 +24,7 @@ from metalsmith import exceptions
LOG = logging.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class Filter(object):
class Filter(object, metaclass=abc.ABCMeta):
"""Base class for filters."""
@abc.abstractmethod

View File

@ -19,7 +19,6 @@ import re
import sys
from openstack import exceptions as os_exc
import six
from metalsmith import exceptions
@ -89,7 +88,7 @@ def is_hostname_safe(hostname):
:param hostname: The hostname to be validated.
:returns: True if valid. False if not.
"""
if not isinstance(hostname, six.string_types) or len(hostname) > 255:
if not isinstance(hostname, str) or len(hostname) > 255:
return False
return _HOSTNAME_RE.match(hostname) is not None
@ -144,4 +143,4 @@ def reraise_os_exc(reraise_as, failure_message='Clean up failed'):
if is_expected:
raise reraise_as(str(exc_info[1]))
else:
six.reraise(*exc_info)
raise exc_info[1]

View File

@ -18,11 +18,11 @@
import abc
import logging
import os
from urllib import parse as urlparse
import openstack.exceptions
import requests
import six
from six.moves.urllib import parse as urlparse
from metalsmith import _utils
from metalsmith import exceptions
@ -31,8 +31,7 @@ from metalsmith import exceptions
LOG = logging.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class _Source(object):
class _Source(object, metaclass=abc.ABCMeta):
def _validate(self, connection, root_size_gb):
"""Validate the source."""

View File

@ -13,12 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import io
import json
import tempfile
import fixtures
import mock
import six
import testtools
from metalsmith import _cmd
@ -146,7 +146,7 @@ class TestDeploy(testtools.TestCase):
args = ['deploy', '--network', 'mynet', '--image', 'myimg',
'--resource-class', 'compute']
fake_io = six.StringIO()
fake_io = io.StringIO()
with mock.patch('sys.stdout', fake_io):
self._check(mock_pr, args, {}, {}, formatter='json')
self.assertEqual(json.loads(fake_io.getvalue()),
@ -601,7 +601,7 @@ class TestUndeploy(testtools.TestCase):
node.to_dict.return_value = {'node': 'dict'}
args = ['--format', 'json', 'undeploy', '123456']
fake_io = six.StringIO()
fake_io = io.StringIO()
with mock.patch('sys.stdout', fake_io):
_cmd.main(args)
self.assertEqual(json.loads(fake_io.getvalue()),
@ -747,7 +747,7 @@ class TestShowWait(testtools.TestCase):
mock_pr.return_value.show_instances.return_value = self.instances
args = ['--format', 'json', 'show', 'uuid1', 'hostname2']
fake_io = six.StringIO()
fake_io = io.StringIO()
with mock.patch('sys.stdout', fake_io):
_cmd.main(args)
self.assertEqual(json.loads(fake_io.getvalue()),
@ -773,7 +773,7 @@ class TestShowWait(testtools.TestCase):
mock_pr.return_value.list_instances.return_value = self.instances
args = ['--format', 'json', 'list']
fake_io = six.StringIO()
fake_io = io.StringIO()
with mock.patch('sys.stdout', fake_io):
_cmd.main(args)
self.assertEqual(json.loads(fake_io.getvalue()),
@ -786,7 +786,7 @@ class TestShowWait(testtools.TestCase):
self.instances)
args = ['--format', 'json', 'wait', 'uuid1', 'hostname2']
fake_io = six.StringIO()
fake_io = io.StringIO()
with mock.patch('sys.stdout', fake_io):
_cmd.main(args)
self.assertEqual(json.loads(fake_io.getvalue()),

View File

@ -14,7 +14,6 @@
# limitations under the License.
import mock
import six
from metalsmith import _instance
from metalsmith.test import test_provisioner
@ -136,7 +135,7 @@ class TestInstanceStates(test_provisioner.Base):
'uuid': self.node.id},
to_dict)
# States are converted to strings
self.assertIsInstance(to_dict['state'], six.string_types)
self.assertIsInstance(to_dict['state'], str)
@mock.patch.object(_instance.Instance, 'ip_addresses', autospec=True)
def test_to_dict_with_allocation(self, mock_ips):
@ -156,4 +155,4 @@ class TestInstanceStates(test_provisioner.Base):
'uuid': self.node.id},
to_dict)
# States are converted to strings
self.assertIsInstance(to_dict['state'], six.string_types)
self.assertIsInstance(to_dict['state'], str)

View File

@ -4,5 +4,4 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0
openstacksdk>=0.29.0 # Apache-2.0
requests>=2.18.4 # Apache-2.0
six>=1.10.0 # MIT
PrettyTable<0.8,>=0.7.2 # BSD