diff --git a/.gitignore b/.gitignore index adf36befa79de928565e37ccae0e1481e9950b1d..402479bcf754db2b6ffc1e7b09c147ee920a68a4 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,5 @@ ChangeLog # reno build releasenotes/build +RELEASENOTES.rst +releasenotes/notes/reno.cache diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9d945567450344fa94ec9e6280095e86a6c532b0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +# We from the Oslo project decided to pin repos based on the +# commit hash instead of the version tag to prevend arbitrary +# code from running in developer's machines. To update to a +# newer version, run `pre-commit autoupdate` and then replace +# the newer versions with their commit hash. + +default_language_version: + python: python3 + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: ebc15addedad713c86ef18ae9632c88e187dd0af # v3.1.0 + hooks: + - id: trailing-whitespace + # Replaces or checks mixed line ending + - id: mixed-line-ending + args: ['--fix', 'lf'] + exclude: '.*\.(svg)$' + # Forbid files which have a UTF-8 byte-order marker + - id: check-byte-order-marker + # Checks that non-binary executables have a proper shebang + - id: check-executables-have-shebangs + # Check for files that contain merge conflict strings. + - id: check-merge-conflict + # Check for debugger imports and py37+ breakpoint() + # calls in python source + - id: debug-statements + - id: check-yaml + files: .*\.(yaml|yml)$ + - repo: https://gitlab.com/pycqa/flake8 + rev: 181bb46098dddf7e2d45319ea654b4b4d58c2840 # 3.8.3 + hooks: + - id: flake8 + additional_dependencies: + - hacking>=3.0.1,<3.1.0 diff --git a/.zuul.yaml b/.zuul.yaml index 2c16442284303ff92d54a7f0014cd3c82e757b01..842503010e8067207e14a591251da141657d69b2 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -2,8 +2,7 @@ templates: - check-requirements - lib-forward-testing-python3 - - openstack-lower-constraints-jobs - - openstack-python3-victoria-jobs + - openstack-python3-wallaby-jobs - periodic-stable-jobs - publish-openstack-docs-pti - release-notes-jobs-python3 diff --git a/doc/source/conf.py b/doc/source/conf.py index 6870813c03ae10b88f5527dafdd9c1675c537e96..518016080f1bdc6ef872c34f432a3d435eccc6f6 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +# Copyright (C) 2020 Red Hat, Inc. +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -22,7 +24,6 @@ sys.path.insert(0, os.path.abspath('../..')) # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ 'sphinx.ext.autodoc', - #'sphinx.ext.intersphinx', 'openstackdocstheme' ] @@ -76,6 +77,3 @@ latex_documents = [ u'%s Documentation' % project, u'OpenStack Foundation', 'manual'), ] - -# Example configuration for intersphinx: refer to the Python standard library. -#intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/oslo_serialization/jsonutils.py b/oslo_serialization/jsonutils.py index 0e310b145846ef63946c2409796133c36deede05..a2a700b405b83167ab339637d4087b2bbcd47857 100644 --- a/oslo_serialization/jsonutils.py +++ b/oslo_serialization/jsonutils.py @@ -33,6 +33,7 @@ import codecs import datetime import functools import inspect +import io import itertools import json import uuid @@ -161,7 +162,7 @@ def to_primitive(value, convert_instances=False, convert_datetime=True, # Python 3 does not have iteritems elif hasattr(value, 'items'): return recursive(dict(value.items()), level=level + 1) - elif hasattr(value, '__iter__'): + elif hasattr(value, '__iter__') and not isinstance(value, io.IOBase): return list(map(recursive, value)) elif convert_instances and hasattr(value, '__dict__'): # Likely an instance of something. Watch for cycles. diff --git a/oslo_serialization/tests/test_jsonutils.py b/oslo_serialization/tests/test_jsonutils.py index e04b9dca6b6861fad3d84124fe1fe2cc1c4313a6..f07682203d76b8bc7805575197da0976e0d0fb7a 100644 --- a/oslo_serialization/tests/test_jsonutils.py +++ b/oslo_serialization/tests/test_jsonutils.py @@ -401,6 +401,16 @@ class ToPrimitiveTestCase(test_base.BaseTestCase): ret = jsonutils.to_primitive(obj, fallback=lambda _: 'fallback') self.assertEqual('fallback', ret) + def test_fallback_typeerror_IO_object(self): + # IO Objects are not callable, cause a TypeError in to_primitive() + obj = io.IOBase + + ret = jsonutils.to_primitive(obj) + self.assertEqual(str(obj), ret) + + ret = jsonutils.to_primitive(obj, fallback=lambda _: 'fallback') + self.assertEqual('fallback', ret) + def test_exception(self): self.assertIn(jsonutils.to_primitive(ValueError("an exception")), ["ValueError('an exception',)", diff --git a/releasenotes/notes/bug-1908607-fix-json-to_primitive-IO-OBjects-04faff4a1b5cf48f.yaml b/releasenotes/notes/bug-1908607-fix-json-to_primitive-IO-OBjects-04faff4a1b5cf48f.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0246ef77de79d5ef30ebb2605a877d2d063b51f1 --- /dev/null +++ b/releasenotes/notes/bug-1908607-fix-json-to_primitive-IO-OBjects-04faff4a1b5cf48f.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + `Bug #1908607 `_: Fix + json to_primitive when using IO OBjects. diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py index af9b55fde5eec58ebc1a97b86595ba5e0cd9ed00..36186ab48f03553ad4e7712a298172e257d73e45 100644 --- a/releasenotes/source/conf.py +++ b/releasenotes/source/conf.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +# Copyright (C) 2020 Red Hat, Inc. +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/releasenotes/source/index.rst b/releasenotes/source/index.rst index 82a132649f1597e86edf86653f12d36702259014..8e1b9fe0e4521a14f41cbff38f7063a6460bfba5 100644 --- a/releasenotes/source/index.rst +++ b/releasenotes/source/index.rst @@ -6,6 +6,7 @@ :maxdepth: 1 unreleased + victoria ussuri train stein diff --git a/releasenotes/source/victoria.rst b/releasenotes/source/victoria.rst new file mode 100644 index 0000000000000000000000000000000000000000..4efc7b6f3b1117aae27fed2a9a8a9f7cadc7af8b --- /dev/null +++ b/releasenotes/source/victoria.rst @@ -0,0 +1,6 @@ +============================= +Victoria Series Release Notes +============================= + +.. release-notes:: + :branch: stable/victoria diff --git a/test-requirements.txt b/test-requirements.txt index 5dd6fe0cf54f3b7589258bc6f1e047d60dcc80c1..145e8f7fa7768f686bea70e723817fbfcae4c7df 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>=3.0,<3.1.0 # Apache-2.0 +hacking>=3.0.1,<3.1.0 # Apache-2.0 netaddr>=0.7.18 # BSD stestr>=2.0.0 # Apache-2.0 @@ -11,3 +11,5 @@ coverage!=4.4,>=4.0 # Apache-2.0 # Bandit security code scanner bandit>=1.6.0,<1.7.0 # Apache-2.0 + +pre-commit>=2.6.0 # MIT diff --git a/tox.ini b/tox.ini index adbe63ff4e5d938fe20f3f838648421ee0436934..929b8dc4ca6dd038bd34f47623a8b03f9c37bf21 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 3.2.0 -envlist = py38,pep8 +envlist = py3,pep8 basepython = python3 ignore_basepython_conflict = true @@ -13,7 +13,7 @@ commands = stestr run --slowest {posargs} [testenv:pep8] commands = - flake8 + pre-commit run -a # Run security linter bandit -r oslo_serialization tests -n5