From 4afdc0a3d4bd6bac7a5b973f9d96ef35928b6c23 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Tue, 7 Apr 2020 10:37:49 +0200 Subject: [PATCH] Update hacking for Python3 The repo is Python 3 now, so update hacking to version 3.0 which supports Python 3. Fix problems found. Remove hacking and friends from lower-constraints, they are not needed for installation. Change-Id: If92e1e5e79b63497ca8bd29c403bbf2f0e907778 --- lower-constraints.txt | 5 ----- test-requirements.txt | 2 +- toscaparser/elements/constraints.py | 2 +- toscaparser/elements/nodetype.py | 4 +++- toscaparser/elements/scalarunit.py | 6 +++--- toscaparser/entity_template.py | 3 ++- toscaparser/functions.py | 9 +++++---- toscaparser/imports.py | 20 ++++++++++---------- toscaparser/nodetemplate.py | 5 +++-- toscaparser/tests/test_toscatpl.py | 20 ++++++++++---------- toscaparser/tests/test_toscatplvalidation.py | 20 ++++++++++---------- toscaparser/utils/validateutils.py | 10 +++++----- toscaparser/utils/yamlparser.py | 2 +- tox.ini | 4 ++++ 14 files changed, 58 insertions(+), 54 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 7c99ef39..1c4e7e80 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -7,15 +7,12 @@ coverage==4.0 docutils==0.11 extras==1.0.0 fixtures==3.0.0 -flake8==2.5.5 -hacking==0.12.0 imagesize==0.7.1 iso8601==0.1.11 Jinja2==2.10 keystoneauth1==3.4.0 linecache2==1.0.0 MarkupSafe==1.0 -mccabe==0.2.1 mock==2.0.0 mox3==0.20.0 openstackdocstheme==1.20.0 @@ -23,9 +20,7 @@ os-client-config==1.28.0 oslosphinx==4.7.0 oslotest==3.2.0 pbr==2.0.0 -pep8==1.5.7 prettytable==0.7.2 -pyflakes==0.8.1 Pygments==2.2.0 pyparsing==2.1.0 pyperclip==1.5.27 diff --git a/test-requirements.txt b/test-requirements.txt index 1fe45eef..4dcd288a 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,7 +1,7 @@ # The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 +hacking>=3.0,<3.1.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD oslotest>=3.2.0 # Apache-2.0 diff --git a/toscaparser/elements/constraints.py b/toscaparser/elements/constraints.py index b78a6e47..63d53785 100644 --- a/toscaparser/elements/constraints.py +++ b/toscaparser/elements/constraints.py @@ -608,7 +608,7 @@ constraint_mapping = { Constraint.MIN_LENGTH: MinLength, Constraint.MAX_LENGTH: MaxLength, Constraint.PATTERN: Pattern - } +} def get_constraint_class(type): diff --git a/toscaparser/elements/nodetype.py b/toscaparser/elements/nodetype.py index 79b5cc1e..aa92698b 100644 --- a/toscaparser/elements/nodetype.py +++ b/toscaparser/elements/nodetype.py @@ -21,7 +21,9 @@ from toscaparser.elements.statefulentitytype import StatefulEntityType class NodeType(StatefulEntityType): '''TOSCA built-in node type.''' - SECTIONS = (DERIVED_FROM, METADATA, PROPERTIES, VERSION, DESCRIPTION, ATTRIBUTES, REQUIREMENTS, CAPABILITIES, INTERFACES, ARTIFACTS) = \ + SECTIONS = (DERIVED_FROM, METADATA, PROPERTIES, VERSION, + DESCRIPTION, ATTRIBUTES, REQUIREMENTS, CAPABILITIES, + INTERFACES, ARTIFACTS) = \ ('derived_from', 'metadata', 'properties', 'version', 'description', 'attributes', 'requirements', 'capabilities', 'interfaces', 'artifacts') diff --git a/toscaparser/elements/scalarunit.py b/toscaparser/elements/scalarunit.py index d7f72e6b..3e240f6d 100644 --- a/toscaparser/elements/scalarunit.py +++ b/toscaparser/elements/scalarunit.py @@ -55,7 +55,7 @@ class ScalarUnit(object): ExceptionCollector.appendException(ValueError(msg)) def validate_scalar_unit(self): - regex = re.compile('([0-9.]+)\s*(\w+)') + regex = re.compile(r'([0-9.]+)\s*(\w+)') try: result = regex.match(str(self.value)).groups() validateutils.str_to_num(result[0]) @@ -75,7 +75,7 @@ class ScalarUnit(object): unit = self.SCALAR_UNIT_DEFAULT self.validate_scalar_unit() - regex = re.compile('([0-9.]+)\s*(\w+)') + regex = re.compile(r'([0-9.]+)\s*(\w+)') result = regex.match(str(self.value)).groups() converted = (float(validateutils.str_to_num(result[0])) * self.SCALAR_UNIT_DICT[result[1]] @@ -112,7 +112,7 @@ scalarunit_mapping = { ScalarUnit.SCALAR_UNIT_FREQUENCY: ScalarUnit_Frequency, ScalarUnit.SCALAR_UNIT_SIZE: ScalarUnit_Size, ScalarUnit.SCALAR_UNIT_TIME: ScalarUnit_Time, - } +} def get_scalarunit_class(type): diff --git a/toscaparser/entity_template.py b/toscaparser/entity_template.py index d454ac0f..f7e67b09 100644 --- a/toscaparser/entity_template.py +++ b/toscaparser/entity_template.py @@ -34,7 +34,8 @@ class EntityTemplate(object): ('derived_from', 'properties', 'requirements', 'interfaces', 'capabilities', 'type', 'description', 'directives', 'attributes', 'artifacts', 'node_filter', 'copy') - REQUIREMENTS_SECTION = (NODE, CAPABILITY, RELATIONSHIP, OCCURRENCES, NODE_FILTER) = \ + REQUIREMENTS_SECTION = (NODE, CAPABILITY, RELATIONSHIP, OCCURRENCES, + NODE_FILTER) = \ ('node', 'capability', 'relationship', 'occurrences', 'node_filter') # Special key names diff --git a/toscaparser/functions.py b/toscaparser/functions.py index 935e965d..f5895ea1 100644 --- a/toscaparser/functions.py +++ b/toscaparser/functions.py @@ -298,7 +298,7 @@ class GetAttribute(Function): ExceptionCollector.appendException( KeyError(_( 'Node template "{0}" was not found.' - ).format(node_template_name))) + ).format(node_template_name))) def _find_req_or_cap_attribute(self, req_or_cap, attr_name): node_tpl = self._find_node_template(self.args[0]) @@ -536,8 +536,8 @@ class GetProperty(Function): KeyError(_( 'Node template "{0}" was not found.' ' referenced from node template {1}' - ).format(node_template_name, - self.context.name))) + ).format(node_template_name, + self.context.name))) def _get_index_value(self, value, index): if isinstance(value, list): @@ -742,7 +742,7 @@ class GetOperationOutput(Function): ExceptionCollector.appendException( KeyError(_( 'Node template "{0}" was not found.' - ).format(node_template_name))) + ).format(node_template_name))) def result(self): return self @@ -822,6 +822,7 @@ class Token(Function): def result(self): return self + function_mappings = { GET_PROPERTY: GetProperty, GET_INPUT: GetInput, diff --git a/toscaparser/imports.py b/toscaparser/imports.py index 107e439d..dce916ed 100644 --- a/toscaparser/imports.py +++ b/toscaparser/imports.py @@ -232,16 +232,16 @@ class ImportsLoader(object): self.path)) if file_path[0] != '' and dir_path.endswith( file_path[0]): - import_template = dir_path + "/" +\ - file_path[2] - if not os.path.isfile(import_template): - msg = (_('"%(import_template)s" is' - 'not a valid file') - % {'import_template': - import_template}) - log.error(msg) - ExceptionCollector.appendException - (ValueError(msg)) + import_template = dir_path + "/" +\ + file_path[2] + if not os.path.isfile(import_template): + msg = (_('"%(import_template)s" is ' + 'not a valid file') + % {'import_template': + import_template}) + log.error(msg) + ExceptionCollector.appendException + (ValueError(msg)) else: # template is pre-parsed if os.path.isabs(file_name) and os.path.isfile(file_name): a_file = True diff --git a/toscaparser/nodetemplate.py b/toscaparser/nodetemplate.py index 3c06d3f4..82b72d18 100644 --- a/toscaparser/nodetemplate.py +++ b/toscaparser/nodetemplate.py @@ -235,8 +235,9 @@ class NodeTemplate(EntityTemplate): DataEntity.validate_datatype('list', occurrences) for value in occurrences: DataEntity.validate_datatype('integer', value) - if len(occurrences) != 2 or not (0 <= occurrences[0] <= occurrences[1]) \ - or occurrences[1] == 0: + if (len(occurrences) != 2 + or not (0 <= occurrences[0] <= occurrences[1]) + or occurrences[1] == 0): ExceptionCollector.appendException( InvalidPropertyValueError(what=(occurrences))) diff --git a/toscaparser/tests/test_toscatpl.py b/toscaparser/tests/test_toscatpl.py index d43f3a4d..f0d470f6 100644 --- a/toscaparser/tests/test_toscatpl.py +++ b/toscaparser/tests/test_toscatpl.py @@ -334,17 +334,17 @@ class ToscaTemplateTest(TestCase): relation, node in node_tpl.relationships.items()]) self.assertEqual(expected_relationship, actual_relationship) if node_tpl.name == 'mysql_database': - self.assertEqual( - [('tosca.relationships.HostedOn', 'my_dbms')], - [(relation.type, node.name) for - relation, - node in node_tpl.relationships.items()]) + self.assertEqual( + [('tosca.relationships.HostedOn', 'my_dbms')], + [(relation.type, node.name) for + relation, + node in node_tpl.relationships.items()]) if node_tpl.name == 'my_server': - self.assertEqual( - [('tosca.relationships.AttachesTo', 'my_storage')], - [(relation.type, node.name) for - relation, - node in node_tpl.relationships.items()]) + self.assertEqual( + [('tosca.relationships.AttachesTo', 'my_storage')], + [(relation.type, node.name) for + relation, + node in node_tpl.relationships.items()]) def test_template_requirements_not_implemented(self): # TODO(spzala): replace this test with new one once TOSCA types look up diff --git a/toscaparser/tests/test_toscatplvalidation.py b/toscaparser/tests/test_toscatplvalidation.py index 4aae93cb..6982cfd7 100644 --- a/toscaparser/tests/test_toscatplvalidation.py +++ b/toscaparser/tests/test_toscatplvalidation.py @@ -448,16 +448,16 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml "WebApplication.WordPress")) def test_imports_file_with_suffix_yml(self): - tpl_snippet = ''' - imports: - - custom_types/wordpress.yml - ''' - path = 'toscaparser/tests/data/tosca_elk.yaml' - custom_defs = self._imports_content_test(tpl_snippet, - path, - "node_types") - self.assertTrue(custom_defs.get("tosca.nodes." - "WebApplication.WordPress")) + tpl_snippet = ''' + imports: + - custom_types/wordpress.yml + ''' + path = 'toscaparser/tests/data/tosca_elk.yaml' + custom_defs = self._imports_content_test(tpl_snippet, + path, + "node_types") + self.assertTrue(custom_defs.get("tosca.nodes." + "WebApplication.WordPress")) def test_import_error_file_uri(self): tpl_snippet = ''' diff --git a/toscaparser/utils/validateutils.py b/toscaparser/utils/validateutils.py index b280576f..782f01f4 100644 --- a/toscaparser/utils/validateutils.py +++ b/toscaparser/utils/validateutils.py @@ -165,11 +165,11 @@ def validate_timestamp(value): class TOSCAVersionProperty(object): - VERSION_RE = re.compile('^(?P([0-9][0-9]*))' - '(\.(?P([0-9][0-9]*)))?' - '(\.(?P([0-9][0-9]*)))?' - '(\.(?P([0-9A-Za-z]+)))?' - '(\-(?P[0-9])*)?$') + VERSION_RE = re.compile(r'^(?P([0-9][0-9]*))' + r'(\.(?P([0-9][0-9]*)))?' + r'(\.(?P([0-9][0-9]*)))?' + r'(\.(?P([0-9A-Za-z]+)))?' + r'(\-(?P[0-9])*)?$') def __init__(self, version): self.version = str(version) diff --git a/toscaparser/utils/yamlparser.py b/toscaparser/utils/yamlparser.py index 713650d8..9aa3accd 100644 --- a/toscaparser/utils/yamlparser.py +++ b/toscaparser/utils/yamlparser.py @@ -45,7 +45,7 @@ def load_yaml(path, a_file=True): % {'path': path, 'code': e.code}) ExceptionCollector.appendException(URLException(what=msg)) return - except Exception as e: + except Exception: raise return yaml.load(f.read(), Loader=yaml_loader) diff --git a/tox.ini b/tox.ini index 7d963dc2..29a0f751 100644 --- a/tox.ini +++ b/tox.ini @@ -41,6 +41,10 @@ commands = oslo_debug_helper -t toscaparser/tests {posargs} [flake8] show-source = True builtins = _ +# Enable either of these: +# W503 line break before binary operator +# W504 line break after binary operator +ignore = W503,W504 exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build [testenv:lower-constraints]