Remove six murano/dsl

Change-Id: Iac776e29eb63421577cb928692f2945200f32b1d
This commit is contained in:
zhurong 2020-04-17 19:39:05 -07:00
parent f3f2a4019a
commit 91c0f48a30
29 changed files with 78 additions and 113 deletions

View File

@ -299,3 +299,15 @@ def split_for_quotes(value):
val_split = [val[0] or val[1] for val in re.findall(tmp, value)]
replaced_inner_quotes = [s.replace(r'\"', '"') for s in val_split]
return replaced_inner_quotes
def reraise(tp, value, tb=None):
try:
if value is None:
value = tp()
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
finally:
value = None
tb = None

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from murano.dsl import contracts
from murano.dsl import dsl_types
from murano.dsl import exceptions
@ -26,11 +24,11 @@ class String(contracts.ContractMethod):
def transform(self):
if self.value is None:
return None
if isinstance(self.value, six.text_type):
if isinstance(self.value, str):
return self.value
if isinstance(self.value, six.string_types) or \
isinstance(self.value, six.integer_types):
return six.text_type(self.value)
if isinstance(self.value, str) or \
isinstance(self.value, int):
return str(self.value)
if isinstance(self.value, dsl_types.MuranoObject):
return self.value.object_id
if isinstance(self.value, dsl_types.MuranoObjectInterface):
@ -40,7 +38,7 @@ class String(contracts.ContractMethod):
helpers.format_scalar(self.value)))
def validate(self):
if self.value is None or isinstance(self.value, six.string_types):
if self.value is None or isinstance(self.value, str):
return self.value
raise exceptions.ContractViolationException()

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from yaql.language import specs
from yaql.language import utils
from yaql.language import yaqltypes
@ -70,7 +68,7 @@ class Class(contracts.ContractMethod):
value, self.owner, context=self.root_context,
default_type=self.default_type,
scope_type=self.calling_type)
elif isinstance(value, six.string_types):
elif isinstance(value, str):
obj = object_store.get(value)
if obj is None:
if not object_store.initializing:

View File

@ -17,7 +17,6 @@ import os.path
import eventlet
from oslo_config import cfg
import six
from yaql.language import expressions as yaql_expressions
from yaql.language import specs
from yaql.language import utils
@ -61,7 +60,7 @@ class MuranoObjectParameter(yaqltypes.PythonType):
return False
if self.murano_class:
murano_class = self.murano_class
if isinstance(murano_class, six.string_types):
if isinstance(murano_class, str):
return helpers.is_instance_of(
value, murano_class,
self.version_spec or helpers.get_type(context))
@ -110,14 +109,13 @@ class MuranoTypeParameter(yaqltypes.PythonType):
self._resolve_strings = resolve_strings
self._lazy = lazy
super(MuranoTypeParameter, self).__init__(
(dsl_types.MuranoTypeReference,
six.string_types), nullable)
(dsl_types.MuranoTypeReference, str), nullable)
def check(self, value, context, *args, **kwargs):
if not super(MuranoTypeParameter, self).check(
value, context, *args, **kwargs):
return False
if isinstance(value, six.string_types):
if isinstance(value, str):
if not self._resolve_strings:
return False
value = helpers.get_class(value, context).get_reference()
@ -138,7 +136,7 @@ class MuranoTypeParameter(yaqltypes.PythonType):
value2 = value2(utils.NO_VALUE, ctx, engine)
value2 = super(MuranoTypeParameter, self).convert(
value2, sender, ctx, function_spec, engine)
if isinstance(value2, six.string_types):
if isinstance(value2, str):
value2 = helpers.get_class(value2, ctx).get_reference()
if self._base_type and not self._base_type.is_compatible(value):
raise ValueError('Value must be subtype of {0}'.format(
@ -215,7 +213,7 @@ class MuranoObjectInterface(dsl_types.MuranoObjectInterface):
return MuranoObjectInterface.create(owner)
def find_owner(self, type, optional=False):
if isinstance(type, six.string_types):
if isinstance(type, str):
type = helpers.get_class(type)
elif isinstance(type, dsl_types.MuranoTypeReference):
type = type.type

View File

@ -14,8 +14,6 @@
import sys
import six
from murano.dsl.principal_objects import stack_trace
@ -55,7 +53,7 @@ class MuranoPlException(Exception):
def from_python_exception(exception, context):
stacktrace = stack_trace.create_stack_trace(context)
exception_type = type(exception)
builtins_module = 'builtins' if six.PY3 else 'exceptions'
builtins_module = 'builtins'
module = exception_type.__module__
if module == builtins_module:
names = [exception_type.__name__]

View File

@ -19,7 +19,6 @@ import traceback
import eventlet
import eventlet.event
from oslo_log import log as logging
import six
from yaql.language import exceptions as yaql_exceptions
from yaql.language import specs
from yaql.language import utils
@ -236,7 +235,7 @@ class MuranoDslExecutor(object):
def _log_method(self, context, args, kwargs):
method = helpers.get_current_method(context)
param_gen = itertools.chain(
(six.text_type(arg) for arg in args),
(str(arg) for arg in args),
(u'{0} => {1}'.format(name, value)
for name, value in kwargs.items()))
params_str = u', '.join(param_gen)

View File

@ -23,18 +23,16 @@ import sys
import uuid
import weakref
import eventlet.greenpool
import eventlet.greenthread
from oslo_config import cfg
import semantic_version
import six
from yaql.language import contexts
import yaql.language.exceptions
import yaql.language.expressions
from yaql.language import utils as yaqlutils
from murano.common import utils
from murano.dsl import constants
from murano.dsl import dsl_types
from murano.dsl import exceptions
@ -88,10 +86,8 @@ def merge_dicts(dict1, dict2, max_levels=0):
if key in dict2:
value2 = dict2[key]
if type(value2) != type(value1):
if ((isinstance(value1,
six.string_types) or value1 is None) and
(isinstance(value2,
six.string_types) or value2 is None)):
if ((isinstance(value1, str) or value1 is None) and
(isinstance(value2, str) or value2 is None)):
continue
raise TypeError()
if max_levels != 1 and isinstance(value2, dict):
@ -132,7 +128,7 @@ def parallel_select(collection, func, limit=1000):
except StopIteration:
return map(lambda t: t[0], result)
else:
six.reraise(type(exception[0]), exception[0], exception[2])
utils.reraise(type(exception[0]), exception[0], exception[2])
def enum(**enums):
@ -320,7 +316,7 @@ def cast(obj, murano_class, pov_or_version_spec=None):
obj = obj.object
if isinstance(pov_or_version_spec, dsl_types.MuranoType):
pov_or_version_spec = pov_or_version_spec.package
elif isinstance(pov_or_version_spec, six.string_types):
elif isinstance(pov_or_version_spec, str):
pov_or_version_spec = parse_version_spec(pov_or_version_spec)
if isinstance(murano_class, dsl_types.MuranoTypeReference):
@ -425,7 +421,7 @@ def normalize_version_spec(version_spec):
for op, funcs in transformations[item.kind]:
new_parts.append('{0}{1}'.format(
op,
six.moves.reduce(lambda v, f: f(v), funcs, item.spec)
functools.reduce(lambda v, f: f(v), funcs, item.spec)
))
if not new_parts:
return semantic_version.Spec('*')
@ -701,9 +697,9 @@ def patch_dict(dct, path, value):
def format_scalar(value):
if isinstance(value, six.string_types):
if isinstance(value, str):
return "'{0}'".format(value)
return six.text_type(value)
return str(value)
def is_passkey(value):

View File

@ -12,9 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from murano.dsl import constants
from murano.dsl import dsl_exception
from murano.dsl import exceptions
@ -140,7 +137,7 @@ class WhileDoMacro(expressions.DslExpression):
class ForMacro(expressions.DslExpression):
def __init__(self, For, In, Do):
if not isinstance(For, six.string_types):
if not isinstance(For, str):
raise exceptions.DslSyntaxError(
'For value must be of string type')
self._code = CodeBlock(Do)

View File

@ -16,8 +16,6 @@ import abc
import operator
import weakref
import six
from murano.dsl import dsl_types
from murano.dsl import helpers
@ -112,7 +110,7 @@ def merge_providers(initial_class, producer, context):
return result
meta = merger([initial_class], set())
return list(six.moves.map(operator.itemgetter(1), meta))
return list(map(operator.itemgetter(1), meta))
def aggregate_meta(provider, context, group_by_name=True):

View File

@ -17,9 +17,9 @@ import sys
import weakref
from oslo_log import log as logging
import six
from yaql.language import specs
from murano.common import utils
from murano.dsl import constants
from murano.dsl import dsl
from murano.dsl import dsl_types
@ -260,10 +260,10 @@ class MuranoMethodArgument(dsl_types.MuranoMethodArgument, typespec.Spec,
msg = u'[{0}::{1}({2}{3})] {4}'.format(
self.murano_method.declaring_type.name,
self.murano_method.name, self.name,
e.path, six.text_type(e))
six.reraise(exceptions.ContractViolationException,
exceptions.ContractViolationException(msg),
sys.exc_info()[2])
e.path, str(e))
utils.reraise(exceptions.ContractViolationException,
exceptions.ContractViolationException(msg),
sys.exc_info()[2])
@property
def murano_method(self):

View File

@ -18,7 +18,6 @@ import weakref
import debtcollector
import semantic_version
import six
from yaql.language import specs
from yaql.language import utils
@ -224,7 +223,7 @@ class MuranoPackage(dsl_types.MuranoPackage, dslmeta.MetaProvider):
ns_resolver, self.name, self, utils.NO_VALUE)
def get_meta(self, context):
if six.callable(self._meta):
if callable(self._meta):
executor = helpers.get_executor()
context = executor.create_package_context(self)
self._meta = self._meta().get_meta(context)

View File

@ -15,8 +15,7 @@
import sys
import weakref
import six
from murano.common import utils
from murano.dsl import dsl_types
from murano.dsl import exceptions
from murano.dsl import helpers
@ -45,10 +44,10 @@ class MuranoProperty(dsl_types.MuranoProperty, typespec.Spec,
return super(MuranoProperty, self).transform(*args, **kwargs)
except exceptions.ContractViolationException as e:
msg = u'[{0}.{1}{2}] {3}'.format(
self.declaring_type.name, self.name, e.path, six.text_type(e))
six.reraise(exceptions.ContractViolationException,
exceptions.ContractViolationException(msg),
sys.exc_info()[2])
self.declaring_type.name, self.name, e.path, str(e))
utils.reraise(exceptions.ContractViolationException,
exceptions.ContractViolationException(msg),
sys.exc_info()[2])
@property
def name(self):

View File

@ -18,7 +18,6 @@ import copy
import weakref
import semantic_version
import six
from yaql.language import utils
from murano.dsl import constants
@ -529,7 +528,7 @@ def _create_meta_class(cls, name, ns_resolver, data, package, *args, **kwargs):
raise ValueError(u'Invalid MetaClass Cardinality "{}"'.format(
cardinality))
applies_to = data.get('Applies', dsl_types.MetaTargets.All)
if isinstance(applies_to, six.string_types):
if isinstance(applies_to, str):
applies_to = [applies_to]
if isinstance(applies_to, list):
applies_to = set(applies_to)
@ -564,7 +563,7 @@ def weigh_type_hierarchy(cls):
result = {}
for c, w in helpers.traverse(
[(cls, 0)], lambda t: six.moves.map(
[(cls, 0)], lambda t: map(
lambda p: (p, t[1] + 1), t[0].parents)):
result.setdefault(c.name, w)
return result

View File

@ -14,8 +14,6 @@
import re
import six
TYPE_NAME_RE = re.compile(r'^([a-zA-Z_]\w*:|:)?[a-zA-Z_]\w*(\.[a-zA-Z_]\w*)*$')
NS_RE = re.compile(r'^([a-zA-Z_]\w*(\.[a-zA-Z_]\w*)*)?$')
PREFIX_RE = re.compile(r'^([a-zA-Z_]\w*|=)$')
@ -40,7 +38,7 @@ class NamespaceResolver(object):
def resolve_name(self, name):
if not self.is_typename(name, True):
raise ValueError('Invalid type name "{0}"'.format(name))
name = six.text_type(name)
name = str(name)
if ':' not in name:
if '.' in name:
parts = ['', name]
@ -63,7 +61,7 @@ class NamespaceResolver(object):
def is_typename(name, relaxed):
if not name:
return False
name = six.text_type(name)
name = str(name)
if not relaxed and ':' not in name:
return False
return TYPE_NAME_RE.match(name) is not None

View File

@ -14,11 +14,8 @@
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class MuranoPackageLoader(object):
class MuranoPackageLoader(object, metaclass=abc.ABCMeta):
@abc.abstractmethod
def load_package(self, package_name, version_spec):
pass

View File

@ -15,7 +15,6 @@
import inspect
import os.path
import six
from yaql import specs
from murano.dsl import constants
@ -67,7 +66,7 @@ def compose_stack_frame(context):
method = helpers.get_current_method(context)
return {
'instruction': None if instruction is None
else six.text_type(instruction),
else str(instruction),
'location': None if instruction is None
else instruction.source_file_position,

View File

@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from murano.dsl.contracts import contracts
from murano.dsl import dsl_types
from murano.dsl import executor
@ -219,9 +217,9 @@ def generate_ui_hints(entity, context, type_weights):
def sort_by_index(meta, type_weights, property_name='index'):
"""Sorts meta definitions by its distance in the class hierarchy"""
has_index = six.moves.filter(
has_index = filter(
lambda m: m.get_property(property_name) is not None, meta)
has_no_index = six.moves.filter(
has_no_index = filter(
lambda m: m.get_property(property_name) is None, meta)
return (

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from yaql import utils
from murano.dsl import dsl
@ -127,8 +125,7 @@ def _pass12_serialize(value, parent, serialized_objects,
with_destruction_dependencies):
if isinstance(value, dsl.MuranoObjectInterface):
value = value.object
if isinstance(value, (six.string_types,
int, float, bool)) or value is None:
if isinstance(value, (str, int, float, bool)) or value is None:
return value, False
if isinstance(value, dsl_types.MuranoObject):
if value.owner is not parent or value.object_id in serialized_objects:

View File

@ -15,10 +15,9 @@
# This code is almost a complete copy of eventlet.corolocal with only
# the concept of current thread replaced with current session
import collections
import weakref
import six
from murano.dsl import helpers
@ -70,7 +69,7 @@ def session_local(cls):
return type(cls.__name__, (cls, _local), {})
class SessionLocalDict(six.moves.UserDict, object):
class SessionLocalDict(collections.UserDict, object):
def __init__(self, **kwargs):
self.__session_data = weakref.WeakKeyDictionary()
self.__default = {}

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from murano.dsl import constants
from murano.dsl import dsl_exception
from murano.dsl import expressions
@ -55,7 +53,7 @@ class ThrowMacro(expressions.DslExpression):
def __unicode__(self):
if self._message:
return u'Throw {0}: {1}'.format(self._names, self._message)
return u'Throw ' + six.text_type(self._names)
return u'Throw ' + str(self._names)
class CatchBlock(expressions.DslExpression):

View File

@ -14,7 +14,6 @@
import re
import six
from yaql.language import exceptions as yaql_exceptions
from yaql.language import expressions
@ -29,8 +28,8 @@ EXPRESSION_REGEX = re.compile('^[\s\w\d.]*$')
class YaqlExpression(dsl_types.YaqlExpression):
def __init__(self, expression, version):
self._version = version
if isinstance(expression, six.string_types):
self._expression = six.text_type(expression)
if isinstance(expression, str):
self._expression = str(expression)
self._parsed_expression = yaql_integration.parse(
self._expression, version)
self._file_position = None
@ -39,7 +38,7 @@ class YaqlExpression(dsl_types.YaqlExpression):
self._parsed_expression = expression._parsed_expression
self._file_position = expression._file_position
elif isinstance(expression, expressions.Statement):
self._expression = six.text_type(expression)
self._expression = str(expression)
self._parsed_expression = expression
self._file_position = None
else:
@ -69,7 +68,7 @@ class YaqlExpression(dsl_types.YaqlExpression):
@staticmethod
def is_expression(expression, version):
if not isinstance(expression, six.string_types):
if not isinstance(expression, str):
return False
if EXPRESSION_REGEX.match(expression):
return False

View File

@ -13,7 +13,6 @@
# under the License.
import eventlet
import six
from yaql.language import expressions
from yaql.language import specs
from yaql.language import utils
@ -91,7 +90,7 @@ def super_(context, object_, func=None):
cast_type = helpers.get_type(context)
if func is None:
return [object_.cast(type) for type in cast_type.parents]
return six.moves.map(func, super_(context, object_))
return map(func, super_(context, object_))
@specs.parameter('object_', dsl.MuranoObjectParameter(decorate=False))

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from murano.dsl import helpers
@ -71,7 +69,7 @@ class Attribute(object):
class Ref(object):
def __init__(self, obj):
if isinstance(obj, six.string_types):
if isinstance(obj, str):
self._id = obj
else:
self._id = obj.id

View File

@ -14,8 +14,7 @@
import sys
import six
from murano.common import utils
from murano.dsl import context_manager
from murano.dsl import dsl
from murano.dsl import dsl_exception
@ -49,7 +48,7 @@ class Runner(object):
class DslObjectWrapper(object):
def __init__(self, obj, runner):
self._runner = runner
if isinstance(obj, six.string_types + (dsl_types.MuranoType,)):
if isinstance(obj, (str,) + (dsl_types.MuranoType,)):
pass
elif isinstance(obj, (object_model.Object, object_model.Ref)):
obj = obj.id
@ -59,7 +58,7 @@ class Runner(object):
raise ValueError(
'obj must be object ID string, MuranoObject, MuranoType '
'or one of object_model helper classes (Object, Ref)')
if isinstance(obj, six.string_types):
if isinstance(obj, str):
self._receiver = runner.executor.object_store.get(obj)
else:
self._receiver = obj
@ -74,7 +73,7 @@ class Runner(object):
return call
def __init__(self, model, package_loader, functions):
if isinstance(model, six.string_types):
if isinstance(model, str):
model = object_model.Object(model)
model = object_model.build_model(model)
if 'Objects' not in model:
@ -114,7 +113,7 @@ class Runner(object):
original_exception, dsl_exception.MuranoPlException):
exc_traceback = getattr(
e, 'original_traceback', None) or sys.exc_info()[2]
six.reraise(
utils.reraise(
type(original_exception),
original_exception,
exc_traceback)

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from murano.dsl import dsl
from murano.dsl import exceptions
from murano.tests.unit.dsl.foundation import object_model as om
@ -36,12 +34,12 @@ class TestContracts(test_case.DslTestCase):
def test_string_contract(self):
result = self._runner.testStringContract('qwerty')
self.assertIsInstance(result, six.string_types)
self.assertIsInstance(result, str)
self.assertEqual('qwerty', result)
def test_string_from_number_contract(self):
result = self._runner.testStringContract(123)
self.assertIsInstance(result, six.string_types)
self.assertIsInstance(result, str)
self.assertEqual('123', result)
def test_string_null_contract(self):

View File

@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from murano.dsl import dsl_types
from murano.tests.unit.dsl.foundation import object_model as om
from murano.tests.unit.dsl.foundation import test_case
@ -75,7 +73,7 @@ class TestDump(test_case.DslTestCase):
result = self._runner.testDump(source)
res = self._get_body(result)
string_keys = [k for k in res.keys()
if isinstance(res[k], six.string_types)]
if isinstance(res[k], str)]
obj_keys = [k for k in res.keys()
if isinstance(res[k], dict)]
self.assertEqual(2, len(string_keys))
@ -92,7 +90,7 @@ class TestDump(test_case.DslTestCase):
result = self._runner.testDump(source)
res = self._get_body(result)
self._get_body(res['a'])
self.assertIsInstance(res['b'], six.string_types)
self.assertIsInstance(res['b'], str)
def test_dump_with_inheritance(self):
source = om.Object('dumptests.DumpTarget4', foo='FOO', qux='QUX')

View File

@ -13,7 +13,6 @@
# under the License.
import mock
import six
from testtools import matchers
from yaql.language import exceptions as yaql_exceptions
@ -163,8 +162,8 @@ class TestEngineYaqlFunctions(test_case.DslTestCase):
name1 = self._runner.testRandomName()
name2 = self._runner.testRandomName()
self.assertIsInstance(name1, six.string_types)
self.assertIsInstance(name2, six.string_types)
self.assertIsInstance(name1, str)
self.assertIsInstance(name2, str)
self.assertThat(len(name1), matchers.GreaterThan(12))
self.assertThat(len(name2), matchers.GreaterThan(12))
self.assertThat(name1, matchers.NotEquals(name2))

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
import warnings
from murano.dsl import exceptions
@ -37,7 +36,7 @@ class TestFindClass(test_case.DslTestCase):
"recent change in plugin naming scheme. If you are "
"developing applications targeting this plugin consider "
"changing its name")
self.assertEqual(expected, six.text_type(observed))
self.assertEqual(expected, str(observed))
def test_find_class_short_name(self):
self.assertIsNone(self._runner.testFindClassShortName())
@ -47,4 +46,4 @@ class TestFindClass(test_case.DslTestCase):
self._runner.testClassWithPrefixNotFound)
expected = ('Class "io.murano.extensions.io.murano.test.TestFixture1" '
'is not found in io.murano/0.0.0, tests/0.0.0')
self.assertEqual(expected, six.text_type(observed))
self.assertEqual(expected, str(observed))

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from testtools import matchers
from murano.dsl import serializer
@ -96,7 +95,7 @@ class TestResultsSerializer(test_case.DslTestCase):
action_meta = None
for action in actions.values():
self.assertIsInstance(action.get('enabled'), bool)
self.assertIsInstance(action.get('name'), six.string_types)
self.assertIsInstance(action.get('name'), str)
self.assertThat(
action['name'],
matchers.StartsWith('test'))