From 052de8653bf5d62a8919422ca8b8c9052103353c Mon Sep 17 00:00:00 2001 From: Martin Kopec Date: Sat, 9 Jan 2021 15:04:35 +0000 Subject: [PATCH] Replace six by python3 code style As we have already dropped python2 support, usage of six module is redundant. The patch also edits the classifiers in setup.cfg which comply with the wallaby cycle goals. Change-Id: I2b0e4050e489ddfc7cbabe4165d5499ba6788422 --- refstack/api/app.py | 3 +-- refstack/api/controllers/auth.py | 2 +- refstack/api/controllers/products.py | 3 +-- refstack/api/controllers/results.py | 2 +- refstack/api/controllers/vendors.py | 3 +-- refstack/api/utils.py | 2 +- refstack/api/validators.py | 3 +-- refstack/db/sqlalchemy/models.py | 11 +++++------ refstack/tests/api/test_results.py | 5 ++--- refstack/tests/unit/test_api.py | 2 +- refstack/tests/unit/test_api_utils.py | 2 +- refstack/tests/unit/test_db.py | 11 +++++------ setup.cfg | 5 +++++ tox.ini | 2 +- 14 files changed, 27 insertions(+), 29 deletions(-) diff --git a/refstack/api/app.py b/refstack/api/app.py index f88afb11..b43bcf68 100644 --- a/refstack/api/app.py +++ b/refstack/api/app.py @@ -23,7 +23,6 @@ from beaker.middleware import SessionMiddleware from oslo_config import cfg from oslo_log import log import pecan -import six import webob from refstack.api import exceptions as api_exc @@ -159,7 +158,7 @@ class JSONErrorHook(pecan.hooks.PecanHook): body = {'title': title or exc.args[0], 'code': status_code} if self.debug: - body['detail'] = six.text_type(exc) + body['detail'] = str(exc) return webob.Response( body=json.dumps(body), status=status_code, diff --git a/refstack/api/controllers/auth.py b/refstack/api/controllers/auth.py index 178220fa..012a675a 100644 --- a/refstack/api/controllers/auth.py +++ b/refstack/api/controllers/auth.py @@ -18,7 +18,7 @@ from oslo_config import cfg import pecan from pecan import rest -from six.moves.urllib import parse +from urllib import parse from refstack.api import constants as const from refstack.api import utils as api_utils diff --git a/refstack/api/controllers/products.py b/refstack/api/controllers/products.py index 7e1ca971..e2d5e995 100644 --- a/refstack/api/controllers/products.py +++ b/refstack/api/controllers/products.py @@ -22,7 +22,6 @@ from oslo_db.exception import DBReferenceError from oslo_log import log import pecan from pecan.secure import secure -import six from refstack.api import constants as const from refstack.api.controllers import validation @@ -222,7 +221,7 @@ class ProductsController(validation.BaseRestControllerWithValidation): if product['product_type'] == const.DISTRO else const.CLOUD) if product['type'] == const.SOFTWARE: - product['product_ref_id'] = six.text_type(uuid.uuid4()) + product['product_ref_id'] = str(uuid.uuid4()) vendor_id = product.pop('organization_id', None) if not vendor_id: # find or create default vendor for new product diff --git a/refstack/api/controllers/results.py b/refstack/api/controllers/results.py index 010b33db..79cdeb8a 100644 --- a/refstack/api/controllers/results.py +++ b/refstack/api/controllers/results.py @@ -21,7 +21,7 @@ from oslo_log import log import pecan from pecan import rest -from six.moves.urllib import parse +from urllib import parse from refstack import db from refstack.api import constants as const diff --git a/refstack/api/controllers/vendors.py b/refstack/api/controllers/vendors.py index 443546dd..d55f4c79 100644 --- a/refstack/api/controllers/vendors.py +++ b/refstack/api/controllers/vendors.py @@ -16,7 +16,6 @@ import base64 import json -import six from oslo_config import cfg from oslo_db.exception import DBReferenceError @@ -55,7 +54,7 @@ class UsersController(rest.RestController): return None org_users = db.get_organization_users(vendor_id) - return [x for x in six.itervalues(org_users)] + return [x for x in org_users.values()] @secure(api_utils.is_authenticated) @pecan.expose('json') diff --git a/refstack/api/utils.py b/refstack/api/utils.py index 44699e19..c31b306b 100644 --- a/refstack/api/utils.py +++ b/refstack/api/utils.py @@ -31,7 +31,7 @@ import pecan import pecan.rest import jwt -from six.moves.urllib import parse +from urllib import parse from refstack import db from refstack.api import constants as const diff --git a/refstack/api/validators.py b/refstack/api/validators.py index 02602803..1b797ad4 100644 --- a/refstack/api/validators.py +++ b/refstack/api/validators.py @@ -16,7 +16,6 @@ """Validators module.""" import binascii -import six import uuid import json @@ -79,7 +78,7 @@ class BaseValidator(object): """Check that all values are not empty.""" for key in keys: value = body[key] - if isinstance(value, six.string_types): + if isinstance(value, str): value = value.strip() if not value: raise api_exc.ValidationError(key + ' should not be empty') diff --git a/refstack/db/sqlalchemy/models.py b/refstack/db/sqlalchemy/models.py index 0d8ef073..f0c2b8a9 100644 --- a/refstack/db/sqlalchemy/models.py +++ b/refstack/db/sqlalchemy/models.py @@ -19,7 +19,6 @@ import uuid from oslo_db.sqlalchemy import models -import six import sqlalchemy as sa from sqlalchemy import orm from sqlalchemy.ext.declarative import declarative_base @@ -151,7 +150,7 @@ class PubKey(BASE, RefStackBase): # pragma: no cover __tablename__ = 'pubkeys' id = sa.Column(sa.String(36), primary_key=True, - default=lambda: six.text_type(uuid.uuid4())) + default=lambda: str(uuid.uuid4())) openid = sa.Column(sa.String(128), sa.ForeignKey('user.openid'), nullable=False, unique=True, index=True) format = sa.Column(sa.String(24), nullable=False) @@ -171,7 +170,7 @@ class Group(BASE, RefStackBase): # pragma: no cover __tablename__ = 'group' id = sa.Column(sa.String(36), primary_key=True, - default=lambda: six.text_type(uuid.uuid4())) + default=lambda: str(uuid.uuid4())) name = sa.Column(sa.String(80), nullable=False) description = sa.Column(sa.Text()) @@ -205,7 +204,7 @@ class Organization(BASE, RefStackBase): # pragma: no cover __tablename__ = 'organization' id = sa.Column(sa.String(36), primary_key=True, - default=lambda: six.text_type(uuid.uuid4())) + default=lambda: str(uuid.uuid4())) type = sa.Column(sa.Integer, nullable=False) name = sa.Column(sa.String(80), nullable=False) description = sa.Column(sa.Text()) @@ -228,7 +227,7 @@ class Product(BASE, RefStackBase): # pragma: no cover __tablename__ = 'product' id = sa.Column(sa.String(36), primary_key=True, - default=lambda: six.text_type(uuid.uuid4())) + default=lambda: str(uuid.uuid4())) name = sa.Column(sa.String(80), nullable=False) description = sa.Column(sa.Text()) organization_id = sa.Column(sa.String(36), @@ -256,7 +255,7 @@ class ProductVersion(BASE, RefStackBase): ) id = sa.Column(sa.String(36), primary_key=True, - default=lambda: six.text_type(uuid.uuid4())) + default=lambda: str(uuid.uuid4())) product_id = sa.Column(sa.String(36), sa.ForeignKey('product.id'), index=True, nullable=False, unique=False) version = sa.Column(sa.String(length=36), nullable=True) diff --git a/refstack/tests/api/test_results.py b/refstack/tests/api/test_results.py index 73b29d8d..27ebc9ec 100644 --- a/refstack/tests/api/test_results.py +++ b/refstack/tests/api/test_results.py @@ -17,7 +17,6 @@ import uuid import mock from oslo_config import fixture as config_fixture -import six import webtest.app from refstack.api import constants as api_const @@ -207,7 +206,7 @@ class TestResultsEndpoint(api.FunctionalTest): """Test get request with nonexistent uuid.""" self.assertRaises(webtest.app.AppError, self.get_json, - self.URL + six.text_type(uuid.uuid4())) + self.URL + str(uuid.uuid4())) def test_get_one_schema(self): """Test get request for getting JSON schema.""" @@ -230,7 +229,7 @@ class TestResultsEndpoint(api.FunctionalTest): responses = [] for i in range(3): fake_results = { - 'cpid': six.text_type(i), + 'cpid': str(i), 'duration_seconds': i, 'results': [ {'name': 'tempest.foo.bar'}, diff --git a/refstack/tests/unit/test_api.py b/refstack/tests/unit/test_api.py index 8ce343fa..b2f14fba 100644 --- a/refstack/tests/unit/test_api.py +++ b/refstack/tests/unit/test_api.py @@ -19,7 +19,7 @@ import json import mock from oslo_config import fixture as config_fixture -from six.moves.urllib import parse +from urllib import parse import webob.exc from refstack.api import constants as const diff --git a/refstack/tests/unit/test_api_utils.py b/refstack/tests/unit/test_api_utils.py index 25c54f61..72f0ff63 100644 --- a/refstack/tests/unit/test_api_utils.py +++ b/refstack/tests/unit/test_api_utils.py @@ -22,7 +22,7 @@ from oslo_utils import timeutils from oslotest import base from pecan import rest import jwt -from six.moves.urllib import parse +from urllib import parse from webob import exc from refstack.api import constants as const diff --git a/refstack/tests/unit/test_db.py b/refstack/tests/unit/test_db.py index 1dbab28c..4ea9eb77 100644 --- a/refstack/tests/unit/test_db.py +++ b/refstack/tests/unit/test_db.py @@ -17,7 +17,6 @@ import base64 import hashlib -import six import mock from oslo_config import fixture as config_fixture from oslotest import base @@ -191,7 +190,7 @@ class DBBackendTestCase(base.BaseTestCase): test.save.assert_called_once_with(session) session.begin.assert_called_once_with() - self.assertEqual(test_id, six.text_type(_id)) + self.assertEqual(test_id, str(_id)) self.assertEqual(test.cpid, fake_tests_result['cpid']) self.assertEqual(test.duration_seconds, fake_tests_result['duration_seconds']) @@ -362,8 +361,8 @@ class DBBackendTestCase(base.BaseTestCase): def test_apply_filters_for_query_unsigned(self, mock_meta, mock_test): query = mock.Mock() - mock_test.created_at = six.text_type() - mock_meta.test_id = six.text_type() + mock_test.created_at = str() + mock_meta.test_id = str() filters = { api_const.START_DATE: 'fake1', @@ -413,8 +412,8 @@ class DBBackendTestCase(base.BaseTestCase): def test_apply_filters_for_query_signed(self, mock_meta, mock_test): query = mock.Mock() - mock_test.created_at = six.text_type() - mock_meta.test_id = six.text_type() + mock_test.created_at = str() + mock_meta.test_id = str() mock_meta.meta_key = 'user' mock_meta.value = 'test-openid' diff --git a/setup.cfg b/setup.cfg index 95c9951a..a94a1500 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,6 +6,7 @@ description-file = author = OpenStack author-email = openstack-discuss@lists.openstack.org home-page = https://refstack.openstack.org +python_requires = >=3.6 classifier = Environment :: OpenStack Intended Audience :: Developers @@ -15,6 +16,10 @@ classifier = Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: Implementation :: CPython [files] packages = diff --git a/tox.ini b/tox.ini index 7403ca7f..57be49a2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py36,pep8,pip-check-reqs +envlist = py36,py38,pep8,pip-check-reqs minversion = 3.18 skipsdist = True