Hello community, here is the log from the commit of package python-json_tricks for openSUSE:Factory checked in at 2019-03-26 22:34:22 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-json_tricks (Old) and /work/SRC/openSUSE:Factory/.python-json_tricks.new.25356 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-json_tricks" Tue Mar 26 22:34:22 2019 rev:4 rq:688772 version:3.13.1 Changes: -------- --- /work/SRC/openSUSE:Factory/python-json_tricks/python-json_tricks.changes 2018-12-24 11:38:42.489595001 +0100 +++ /work/SRC/openSUSE:Factory/.python-json_tricks.new.25356/python-json_tricks.changes 2019-03-26 22:34:51.733669000 +0100 @@ -1,0 +2,6 @@ +Tue Mar 26 14:53:58 UTC 2019 - Tomáš Chvátal <[email protected]> + +- Update to 3.13.1: + * add support for pathlib + +------------------------------------------------------------------- Old: ---- json_tricks-3.12.2.tar.gz New: ---- json_tricks-3.13.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-json_tricks.spec ++++++ --- /var/tmp/diff_new_pack.ZTsUE4/_old 2019-03-26 22:34:52.933668483 +0100 +++ /var/tmp/diff_new_pack.ZTsUE4/_new 2019-03-26 22:34:52.961668471 +0100 @@ -1,7 +1,7 @@ # # spec file for package python-json_tricks # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,31 +18,32 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-json_tricks -Version: 3.12.2 +Version: 3.13.1 Release: 0 Summary: Extra features for Python's JSON License: BSD-3-Clause Group: Development/Languages/Python -Url: https://github.com/mverleg/pyjson_tricks +URL: https://github.com/mverleg/pyjson_tricks Source: https://files.pythonhosted.org/packages/source/j/json_tricks/json_tricks-%{version}.tar.gz BuildRequires: %{python_module setuptools} BuildRequires: fdupes BuildRequires: python-rpm-macros +Recommends: python-numpy +Recommends: python-pandas +Recommends: python-pathlib +Recommends: python-pytz +BuildArch: noarch # SECTION test requirements BuildRequires: %{python_module numpy} BuildRequires: %{python_module pandas} +BuildRequires: %{python_module pathlib} BuildRequires: %{python_module pytest} BuildRequires: %{python_module pytz} BuildRequires: python-enum34 # /SECTION -Recommends: python-numpy -Recommends: python-pandas -Recommends: python-pytz %ifpython2 Recommends: python-enum34 %endif -BuildArch: noarch - %python_subpackages %description @@ -69,7 +70,7 @@ %python_expand %fdupes %{buildroot}%{$python_sitelib} %check -%python_expand py.test-%{$python_bin_suffix} +%pytest %files %{python_files} %doc README.rst ++++++ json_tricks-3.12.2.tar.gz -> json_tricks-3.13.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/PKG-INFO new/json_tricks-3.13.1/PKG-INFO --- old/json_tricks-3.12.2/PKG-INFO 2018-07-12 21:24:35.000000000 +0200 +++ new/json_tricks-3.13.1/PKG-INFO 2019-03-24 12:28:21.000000000 +0100 @@ -1,11 +1,12 @@ Metadata-Version: 1.1 Name: json_tricks -Version: 3.12.2 +Version: 3.13.1 Summary: Extra features for Python's JSON: comments, order, numpy, pandas, datetimes, and many more! Simple but customizable. Home-page: https://github.com/mverleg/pyjson_tricks Author: Mark V Author-email: [email protected] License: Revised BSD License (LICENSE.txt) +Description-Content-Type: UNKNOWN Description: JSON tricks (python) --------------------------------------- @@ -17,7 +18,7 @@ 3. **Store and load date/times** as a dictionary (including timezone). 4. **Preserve map order** ``{}`` using ``OrderedDict``. 5. **Allow for comments** in json files by starting lines with ``#``. - 6. Sets, complex numbers, Decimal, Fraction, enums, compression, duplicate keys, ... + 6. Sets, complex numbers, Decimal, Fraction, enums, compression, duplicate keys, pathlib Paths ... As well as compression and disallowing duplicate keys. @@ -352,6 +353,7 @@ * Save and load ``Enum`` (thanks to ``Jenselme``), either built-in in python3.4+, or with the enum34_ package in earlier versions. ``IntEnum`` needs encode_intenums_inplace_. * ``json_tricks`` allows for gzip compression using the ``compression=True`` argument (off by default). * ``json_tricks`` can check for duplicate keys in maps by setting ``allow_duplicates`` to False. These are `kind of allowed`_, but are handled inconsistently between json implementations. In Python, for ``dict`` and ``OrderedDict``, duplicate keys are silently overwritten. + * Save and load ``pathlib.Path`` objects (e.g., the current path, `Path('.')`, serializes as ``{"__pathlib__": "."}``) (thanks to ``bburan``). Usage & contributions --------------------------------------- @@ -360,6 +362,8 @@ Contributions are very welcome! Bug reports, feature suggestions and code contributions help this project become more useful for everyone! There is a short `contribution guide`_. + Contributors not yet mentioned: ``janLo`` (performance boost). + Tests --------------------------------------- @@ -401,6 +405,7 @@ Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries :: Python Modules diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/README.rst new/json_tricks-3.13.1/README.rst --- old/json_tricks-3.12.2/README.rst 2018-01-05 22:31:45.000000000 +0100 +++ new/json_tricks-3.13.1/README.rst 2019-03-24 12:23:15.000000000 +0100 @@ -9,7 +9,7 @@ 3. **Store and load date/times** as a dictionary (including timezone). 4. **Preserve map order** ``{}`` using ``OrderedDict``. 5. **Allow for comments** in json files by starting lines with ``#``. -6. Sets, complex numbers, Decimal, Fraction, enums, compression, duplicate keys, ... +6. Sets, complex numbers, Decimal, Fraction, enums, compression, duplicate keys, pathlib Paths ... As well as compression and disallowing duplicate keys. @@ -344,6 +344,7 @@ * Save and load ``Enum`` (thanks to ``Jenselme``), either built-in in python3.4+, or with the enum34_ package in earlier versions. ``IntEnum`` needs encode_intenums_inplace_. * ``json_tricks`` allows for gzip compression using the ``compression=True`` argument (off by default). * ``json_tricks`` can check for duplicate keys in maps by setting ``allow_duplicates`` to False. These are `kind of allowed`_, but are handled inconsistently between json implementations. In Python, for ``dict`` and ``OrderedDict``, duplicate keys are silently overwritten. +* Save and load ``pathlib.Path`` objects (e.g., the current path, `Path('.')`, serializes as ``{"__pathlib__": "."}``) (thanks to ``bburan``). Usage & contributions --------------------------------------- @@ -352,6 +353,8 @@ Contributions are very welcome! Bug reports, feature suggestions and code contributions help this project become more useful for everyone! There is a short `contribution guide`_. +Contributors not yet mentioned: ``janLo`` (performance boost). + Tests --------------------------------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/json_tricks/__init__.py new/json_tricks-3.13.1/json_tricks/__init__.py --- old/json_tricks-3.12.2/json_tricks/__init__.py 2018-05-17 19:31:02.000000000 +0200 +++ new/json_tricks-3.13.1/json_tricks/__init__.py 2019-03-02 23:59:31.000000000 +0100 @@ -7,10 +7,10 @@ from .comment import strip_comment_line_with_symbol, strip_comments from .encoders import TricksEncoder, json_date_time_encode, class_instance_encode, json_complex_encode, \ numeric_types_encode, ClassInstanceEncoder, json_set_encode, pandas_encode, nopandas_encode, \ - numpy_encode, NumpyEncoder, nonumpy_encode, NoNumpyEncoder, fallback_ignore_unknown + numpy_encode, NumpyEncoder, nonumpy_encode, NoNumpyEncoder, fallback_ignore_unknown, pathlib_encode from .decoders import DuplicateJsonKeyException, TricksPairHook, json_date_time_hook, json_complex_hook, \ numeric_types_hook, ClassInstanceHook, json_set_hook, pandas_hook, nopandas_hook, json_numpy_obj_hook, \ - json_nonumpy_obj_hook + json_nonumpy_obj_hook, pathlib_hook from .nonp import dumps, dump, loads, load diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/json_tricks/decoders.py new/json_tricks-3.13.1/json_tricks/decoders.py --- old/json_tricks-3.12.2/json_tricks/decoders.py 2018-05-17 21:25:01.000000000 +0200 +++ new/json_tricks-3.13.1/json_tricks/decoders.py 2019-03-02 23:59:31.000000000 +0100 @@ -5,7 +5,7 @@ from decimal import Decimal from logging import warning from json_tricks import NoEnumException, NoPandasException, NoNumpyException -from .utils import ClassInstanceHookBase +from .utils import ClassInstanceHookBase, nested_index class DuplicateJsonKeyException(Exception): @@ -117,6 +117,23 @@ return dct +def pathlib_hook(dct): + if not isinstance(dct, dict): + return dct + if not '__pathlib__' in dct: + return dct + from pathlib import Path + return Path(dct['__pathlib__']) + + +def nopathlib_hook(dct): + if isinstance(dct, dict) and '__pathlib__' in dct: + raise NoPathlib(('Trying to decode a map which appears to represent a ' + 'pathlib.Path data structure, but pathlib support ' + 'is not enabled.')) + return dct + + class EnumInstanceHook(ClassInstanceHookBase): """ This hook tries to convert json encoded by enum_instance_encode back to it's original instance. @@ -214,7 +231,7 @@ name=meta['name'], dtype=dtype(meta['type']), ) - return dct # impossible + return dct # impossible def nopandas_hook(dct): @@ -237,7 +254,7 @@ if not '__ndarray__' in dct: return dct try: - from numpy import asarray + from numpy import asarray, empty, ndindex import numpy as nptypes except ImportError: raise NoNumpyException('Trying to decode a map which appears to represent a numpy ' @@ -246,6 +263,12 @@ if 'Corder' in dct: order = 'C' if dct['Corder'] else 'F' if dct['shape']: + if dct['dtype'] == 'object': + dec_data = dct['__ndarray__'] + arr = empty(dct['shape'], dtype=dct['dtype'], order=order) + for indx in ndindex(arr.shape): + arr[indx] = nested_index(dec_data, indx) + return arr return asarray(dct['__ndarray__'], dtype=dct['dtype'], order=order) else: dtype = getattr(nptypes, dct['dtype']) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/json_tricks/encoders.py new/json_tricks-3.13.1/json_tricks/encoders.py --- old/json_tricks-3.12.2/json_tricks/encoders.py 2018-05-19 11:12:30.000000000 +0200 +++ new/json_tricks-3.13.1/json_tricks/encoders.py 2019-03-24 12:17:23.000000000 +0100 @@ -6,7 +6,7 @@ from json import JSONEncoder from sys import version, stderr from decimal import Decimal -from .utils import hashodict, call_with_optional_kwargs, \ +from .utils import hashodict, get_arg_names, \ get_module_name_from_object, NoEnumException, NoPandasException, \ NoNumpyException, str_type @@ -35,6 +35,21 @@ return fallback_value +def filtered_wrapper(encoder): + """ + Filter kwargs passed to encoder. + """ + if hasattr(encoder, "default"): + encoder = encoder.default + elif not hasattr(encoder, '__call__'): + raise TypeError('`obj_encoder` {0:} does not have `default` method and is not callable'.format(enc)) + names = get_arg_names(encoder) + + def wrapper(*args, **kwargs): + return encoder(*args, **{k: v for k, v in kwargs.items() if k in names}) + return wrapper + + class TricksEncoder(JSONEncoder): """ Encoder that runs any number of encoder functions or instances on @@ -55,6 +70,7 @@ if obj_encoders: self.obj_encoders = list(obj_encoders) self.obj_encoders.extend(_fallback_wrapper(encoder) for encoder in list(fallback_encoders)) + self.obj_encoders = [filtered_wrapper(enc) for enc in self.obj_encoders] self.silence_typeerror = silence_typeerror self.primitives = primitives super(TricksEncoder, self).__init__(**json_kwargs) @@ -72,17 +88,7 @@ """ prev_id = id(obj) for encoder in self.obj_encoders: - if hasattr(encoder, 'default'): - #todo: write test for this scenario (maybe ClassInstanceEncoder?) - try: - obj = call_with_optional_kwargs(encoder.default, obj, primitives=self.primitives, is_changed=id(obj) != prev_id) - except TypeError as err: - if not self.silence_typeerror: - raise - elif hasattr(encoder, '__call__'): - obj = call_with_optional_kwargs(encoder, obj, primitives=self.primitives, is_changed=id(obj) != prev_id) - else: - raise TypeError('`obj_encoder` {0:} does not have `default` method and is not callable'.format(encoder)) + obj = encoder(obj, primitives=self.primitives, is_changed=id(obj) != prev_id) if id(obj) == prev_id: raise TypeError(('Object of type {0:} could not be encoded by {1:} using encoders [{2:s}]. ' 'You can add an encoders for this type using `extra_obj_encoders`. If you want to \'skip\' this ' @@ -228,7 +234,7 @@ def numeric_types_encode(obj, primitives=False): """ Encode Decimal and Fraction. - + :param primitives: Encode decimals and fractions as standard floats. You may lose precision. If you do this, you may need to enable `allow_nan` (decimals always allow NaNs but floats do not). """ if isinstance(obj, Decimal): @@ -250,6 +256,17 @@ return obj +def pathlib_encode(obj, primitives=False): + from pathlib import Path + if not isinstance(obj, Path): + return obj + + if primitives: + return str(obj) + + return {'__pathlib__': str(obj)} + + class ClassInstanceEncoder(JSONEncoder): """ See `class_instance_encoder`. @@ -325,11 +342,11 @@ def numpy_encode(obj, primitives=False): """ Encodes numpy `ndarray`s as lists with meta data. - + Encodes numpy scalar types as Python equivalents. Special encoding is not possible, because int64 (in py2) and float64 (in py2 and py3) are subclasses of primitives, which never reach the encoder. - + :param primitives: If True, arrays are serialized as (nested) lists without meta info. """ from numpy import ndarray, generic @@ -357,8 +374,8 @@ """ JSON encoder for numpy arrays. """ - SHOW_SCALAR_WARNING = True # show a warning that numpy scalar serialization is experimental - + SHOW_SCALAR_WARNING = True # show a warning that numpy scalar serialization is experimental + def default(self, obj, *args, **kwargs): """ If input object is a ndarray it will be converted into a dict holding @@ -387,5 +404,3 @@ warning('`NoNumpyEncoder` is deprecated, use `nonumpy_encode`') #todo obj = nonumpy_encode(obj) return super(NoNumpyEncoder, self).default(obj, *args, **kwargs) - - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/json_tricks/nonp.py new/json_tricks-3.13.1/json_tricks/nonp.py --- old/json_tricks-3.12.2/json_tricks/nonp.py 2018-05-17 20:55:27.000000000 +0200 +++ new/json_tricks-3.13.1/json_tricks/nonp.py 2019-03-02 23:59:31.000000000 +0100 @@ -11,13 +11,13 @@ from .encoders import TricksEncoder, json_date_time_encode, \ class_instance_encode, json_complex_encode, json_set_encode, numeric_types_encode, numpy_encode, \ nonumpy_encode, nopandas_encode, pandas_encode, noenum_instance_encode, \ - enum_instance_encode # keep 'unused' imports + enum_instance_encode, pathlib_encode # keep 'unused' imports from .decoders import TricksPairHook, \ json_date_time_hook, ClassInstanceHook, \ json_complex_hook, json_set_hook, numeric_types_hook, json_numpy_obj_hook, \ json_nonumpy_obj_hook, \ nopandas_hook, pandas_hook, EnumInstanceHook, \ - noenum_hook # keep 'unused' imports + noenum_hook, pathlib_hook, nopathlib_hook # keep 'unused' imports ENCODING = 'UTF-8' @@ -26,9 +26,9 @@ _cih_instance = ClassInstanceHook() _eih_instance = EnumInstanceHook() DEFAULT_ENCODERS = [json_date_time_encode, json_complex_encode, json_set_encode, - numeric_types_encode, class_instance_encode, ] + numeric_types_encode, class_instance_encode, ] DEFAULT_HOOKS = [json_date_time_hook, json_complex_hook, json_set_hook, - numeric_types_hook, _cih_instance, ] + numeric_types_hook, _cih_instance, ] try: @@ -59,9 +59,20 @@ DEFAULT_ENCODERS = [pandas_encode,] + DEFAULT_ENCODERS DEFAULT_HOOKS = [pandas_hook,] + DEFAULT_HOOKS +try: + import pathlib +except: + # No need to include a "nopathlib_encode" hook since we would not encounter + # the Path object if pathlib isn't available. However, we *could* encounter + # a serialized Path object (produced by a version of Python with pathlib). + DEFAULT_HOOKS = [nopathlib_hook,] + DEFAULT_HOOKS +else: + DEFAULT_ENCODERS = [pathlib_encode,] + DEFAULT_ENCODERS + DEFAULT_HOOKS = [pathlib_hook,] + DEFAULT_HOOKS -DEFAULT_NONP_ENCODERS = [nonumpy_encode,] + DEFAULT_ENCODERS # DEPRECATED -DEFAULT_NONP_HOOKS = [json_nonumpy_obj_hook,] + DEFAULT_HOOKS # DEPRECATED + +DEFAULT_NONP_ENCODERS = [nonumpy_encode,] + DEFAULT_ENCODERS # DEPRECATED +DEFAULT_NONP_HOOKS = [json_nonumpy_obj_hook,] + DEFAULT_HOOKS # DEPRECATED def dumps(obj, sort_keys=None, cls=TricksEncoder, obj_encoders=DEFAULT_ENCODERS, extra_obj_encoders=(), @@ -109,12 +120,12 @@ :param fp: File handle or path to write to. :param compression: The gzip compression level, or None for no compression. :param force_flush: If True, flush the file handle used, when possibly also in the operating system (default False). - + The other arguments are identical to `dumps`. """ txt = dumps(obj, sort_keys=sort_keys, cls=cls, obj_encoders=obj_encoders, extra_obj_encoders=extra_obj_encoders, primitives=primitives, compression=compression, allow_nan=allow_nan, conv_str_byte=conv_str_byte, - fallback_encoders=fallback_encoders, **jsonkwargs) + fallback_encoders=fallback_encoders, **jsonkwargs) if isinstance(fp, str_type): fh = open(fp, 'wb+') else: @@ -125,9 +136,9 @@ except TypeError: pass # if not isinstance(txt, str_type): - # # Cannot write bytes, so must be in text mode, but we didn't get a text - # if not compression: - # txt = txt.decode(ENCODING) + # # Cannot write bytes, so must be in text mode, but we didn't get a text + # if not compression: + # txt = txt.decode(ENCODING) else: try: fh.write(u'') @@ -136,7 +147,7 @@ txt = txt.encode(ENCODING) try: if 'b' not in getattr(fh, 'mode', 'b?') and not isinstance(txt, - str_type) and compression: + str_type) and compression: raise IOError('If compression is enabled, the file must be opened in binary mode.') try: fh.write(txt) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/json_tricks/utils.py new/json_tricks-3.13.1/json_tricks/utils.py --- old/json_tricks-3.12.2/json_tricks/utils.py 2018-05-17 20:52:14.000000000 +0200 +++ new/json_tricks-3.13.1/json_tricks/utils.py 2019-03-24 12:15:49.000000000 +0100 @@ -42,15 +42,6 @@ return set(sig.parameters.keys()) -def call_with_optional_kwargs(callable, *args, **optional_kwargs): - accepted_kwargs = get_arg_names(callable) - use_kwargs = {} - for key, val in optional_kwargs.items(): - if key in accepted_kwargs: - use_kwargs[key] = val - return callable(*args, **use_kwargs) - - class NoNumpyException(Exception): """ Trying to use numpy features, but numpy cannot be found. """ @@ -63,6 +54,10 @@ """ Trying to use enum features, but enum cannot be found. """ +class NoPathlibException(Exception): + """ Trying to use pathlib features, but pathlib cannot be found. """ + + class ClassInstanceHookBase(object): def __init__(self, cls_lookup_map=None): self.cls_lookup_map = cls_lookup_map or {} @@ -161,6 +156,12 @@ return mod +def nested_index(collection, indices): + for i in indices: + collection = collection[i] + return collection + + is_py3 = (version[:2] == '3.') str_type = str if is_py3 else (basestring, unicode,) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/json_tricks.egg-info/PKG-INFO new/json_tricks-3.13.1/json_tricks.egg-info/PKG-INFO --- old/json_tricks-3.12.2/json_tricks.egg-info/PKG-INFO 2018-07-12 21:24:34.000000000 +0200 +++ new/json_tricks-3.13.1/json_tricks.egg-info/PKG-INFO 2019-03-24 12:28:21.000000000 +0100 @@ -1,11 +1,12 @@ Metadata-Version: 1.1 Name: json-tricks -Version: 3.12.2 +Version: 3.13.1 Summary: Extra features for Python's JSON: comments, order, numpy, pandas, datetimes, and many more! Simple but customizable. Home-page: https://github.com/mverleg/pyjson_tricks Author: Mark V Author-email: [email protected] License: Revised BSD License (LICENSE.txt) +Description-Content-Type: UNKNOWN Description: JSON tricks (python) --------------------------------------- @@ -17,7 +18,7 @@ 3. **Store and load date/times** as a dictionary (including timezone). 4. **Preserve map order** ``{}`` using ``OrderedDict``. 5. **Allow for comments** in json files by starting lines with ``#``. - 6. Sets, complex numbers, Decimal, Fraction, enums, compression, duplicate keys, ... + 6. Sets, complex numbers, Decimal, Fraction, enums, compression, duplicate keys, pathlib Paths ... As well as compression and disallowing duplicate keys. @@ -352,6 +353,7 @@ * Save and load ``Enum`` (thanks to ``Jenselme``), either built-in in python3.4+, or with the enum34_ package in earlier versions. ``IntEnum`` needs encode_intenums_inplace_. * ``json_tricks`` allows for gzip compression using the ``compression=True`` argument (off by default). * ``json_tricks`` can check for duplicate keys in maps by setting ``allow_duplicates`` to False. These are `kind of allowed`_, but are handled inconsistently between json implementations. In Python, for ``dict`` and ``OrderedDict``, duplicate keys are silently overwritten. + * Save and load ``pathlib.Path`` objects (e.g., the current path, `Path('.')`, serializes as ``{"__pathlib__": "."}``) (thanks to ``bburan``). Usage & contributions --------------------------------------- @@ -360,6 +362,8 @@ Contributions are very welcome! Bug reports, feature suggestions and code contributions help this project become more useful for everyone! There is a short `contribution guide`_. + Contributors not yet mentioned: ``janLo`` (performance boost). + Tests --------------------------------------- @@ -401,6 +405,7 @@ Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries :: Python Modules diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/json_tricks.egg-info/SOURCES.txt new/json_tricks-3.13.1/json_tricks.egg-info/SOURCES.txt --- old/json_tricks-3.12.2/json_tricks.egg-info/SOURCES.txt 2018-07-12 21:24:35.000000000 +0200 +++ new/json_tricks-3.13.1/json_tricks.egg-info/SOURCES.txt 2019-03-24 12:28:21.000000000 +0100 @@ -24,5 +24,6 @@ tests/test_enum.py tests/test_np.py tests/test_pandas.py +tests/test_pathlib.py tests/test_tz.py tests/test_utils.py \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/setup.py new/json_tricks-3.13.1/setup.py --- old/json_tricks-3.12.2/setup.py 2018-07-12 21:23:12.000000000 +0200 +++ new/json_tricks-3.13.1/setup.py 2019-03-24 12:18:30.000000000 +0100 @@ -32,7 +32,7 @@ license='Revised BSD License (LICENSE.txt)', keywords=['json', 'numpy', 'OrderedDict', 'comments', 'pandas', 'pytz', 'enum', 'encode', 'decode', 'serialize', 'deserialize'], - version='3.12.2', + version='3.13.1', packages=['json_tricks'], include_package_data=True, zip_safe=True, @@ -50,6 +50,7 @@ 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Software Development :: Libraries :: Python Modules', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/tests/test_bare.py new/json_tricks-3.13.1/tests/test_bare.py --- old/json_tricks-3.12.2/tests/test_bare.py 2018-07-12 20:16:13.000000000 +0200 +++ new/json_tricks-3.13.1/tests/test_bare.py 2019-03-03 00:24:37.000000000 +0100 @@ -11,7 +11,7 @@ from math import pi, exp from os.path import join from tempfile import mkdtemp -from pytest import raises +from pytest import raises, fail from json_tricks import fallback_ignore_unknown, DuplicateJsonKeyException from json_tricks.nonp import strip_comments, dump, dumps, load, loads, \ @@ -447,9 +447,12 @@ def test_hooks_not_too_eager(): from threading import RLock - with raises(TypeError, message='There is no hook to serialize RLock, so ' - 'this should fail, otherwise some hook is too eager.'): + with raises(TypeError): dumps([RLock()]) + # TypeError did not get raised, so show a message + # (https://github.com/pytest-dev/pytest/issues/3974) + fail('There is no hook to serialize RLock, so this should fail, ' + 'otherwise some hook is too eager.') def test_fallback_hooks(): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/tests/test_np.py new/json_tricks-3.13.1/tests/test_np.py --- old/json_tricks-3.12.2/tests/test_np.py 2018-05-17 20:54:47.000000000 +0200 +++ new/json_tricks-3.13.1/tests/test_np.py 2019-01-30 21:13:11.000000000 +0100 @@ -11,7 +11,7 @@ from .test_class import MyTestCls from .test_bare import cls_instance from numpy import int8, int16, int32, int64, uint8, uint16, uint32, uint64, \ - float16, float32, float64, complex64, complex128 + float16, float32, float64, complex64, complex128, zeros, ndindex DTYPES = (int8, int16, int32, int64, uint8, uint16, uint32, uint64, @@ -166,3 +166,23 @@ assert data[2] == tuple(rec[2]) +def test_ndarray_object_nesting(): + # Based on issue 53 + # With nested ndarrays + before = zeros((2, 2,), dtype=object) + for i in ndindex(before.shape): + before[i] = array([1, 2, 3]) + after = loads(dumps(before)) + assert before.shape == after.shape, \ + 'shape of array changed for nested ndarrays:\n{}'.format(dumps(before, indent=2)) + assert before.dtype == before.dtype + assert array_equal(before[0, 0], after[0, 0]) + # With nested lists + before = zeros((2, 2,), dtype=object) + for i in ndindex(before.shape): + before[i] = [1, 2, 3] + after = loads(dumps(before)) + assert before.shape == after.shape, \ + 'shape of array changed for nested ndarrays:\n{}'.format(dumps(before, indent=2)) + assert before.dtype == before.dtype + assert array_equal(before[0, 0], after[0, 0]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/tests/test_pathlib.py new/json_tricks-3.13.1/tests/test_pathlib.py --- old/json_tricks-3.12.2/tests/test_pathlib.py 1970-01-01 01:00:00.000000000 +0100 +++ new/json_tricks-3.13.1/tests/test_pathlib.py 2019-03-03 00:26:42.000000000 +0100 @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +This tests Paths, which need pathlib. +""" + +from pathlib import Path + +from json_tricks import dumps, loads + + +# These paths are not necessarily actual paths that exist, but are sufficient +# for testing to ensure that we can properly serialize/deserialize them. +PATHS = [ + Path(), + Path('c:/users/pyjson_tricks'), + Path('/home/users/pyjson_tricks'), + Path('../'), + Path('..'), + Path('./'), + Path('.'), + Path('test_pathlib.py'), + Path('/home/users/pyjson_tricks/test_pathlib.py'), +] + + +def test_path(): + json = dumps(PATHS) + back = loads(json) + assert PATHS == back + + for orig, bck in zip(PATHS, back): + assert orig == bck + + txt = '{"__pathlib__": "."}' + obj = loads(txt) + assert obj == Path() + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/tests/test_utils.py new/json_tricks-3.13.1/tests/test_utils.py --- old/json_tricks-3.12.2/tests/test_utils.py 2017-12-01 20:22:08.000000000 +0100 +++ new/json_tricks-3.13.1/tests/test_utils.py 2019-01-30 21:01:12.000000000 +0100 @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from json_tricks.utils import hashodict, get_arg_names +from json_tricks.utils import hashodict, get_arg_names, nested_index def test_hashodict(): @@ -17,3 +17,17 @@ assert argnames == set(('hello', 'world')) +def test_nested_index(): + arr = [[[1, 2], [1, 2]], [[1, 2], [3, 3]]] + assert 1 == nested_index(arr, (0, 0, 0,)) + assert 2 == nested_index(arr, (1, 0, 1,)) + assert [1, 2] == nested_index(arr, (1, 0,)) + assert [3, 3] == nested_index(arr, (1, 1,)) + assert [[1, 2], [1, 2]] == nested_index(arr, (0,)) + assert [[[1, 2], [1, 2]], [[1, 2], [3, 3]]] == nested_index(arr, ()) + try: + nested_index(arr, (0, 0, 0, 0,)) + except TypeError: + pass + else: + raise AssertionError('indexing more than nesting level should yield IndexError') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/json_tricks-3.12.2/tox.ini new/json_tricks-3.13.1/tox.ini --- old/json_tricks-3.12.2/tox.ini 2018-01-05 19:47:36.000000000 +0100 +++ new/json_tricks-3.13.1/tox.ini 2019-03-03 00:02:55.000000000 +0100 @@ -4,8 +4,8 @@ [tox] envlist = ; py26 not tested - {py27,py34,py35,py36}-{bare,pnp,tz,enum} - {py27,py35,py36}-panda + {py27,py34,py35,py36,py37}-{bare,pnp,tz,enum,path} + {py27,py35,py36,py37}-panda pypy-{bare,tz,enum} [testenv] @@ -18,6 +18,7 @@ snp: git+https://bitbucket.org/pypy/numpy.git tz: pytz panda: pandas!=0.20.* + path: pathlib py26: ordereddict py27-enum: enum34 pypy-enum: enum34 @@ -32,6 +33,6 @@ tz: py.test --cov json_tricks --cov-report= --strict --exitfirst tests/test_bare.py tests/test_class.py tests/test_tz.py {posargs} panda: py.test --cov json_tricks --cov-report= --strict --exitfirst tests/test_bare.py tests/test_class.py tests/test_pandas.py {posargs} enum: py.test --cov json_tricks --cov-report= --strict --exitfirst tests/test_bare.py tests/test_class.py tests/test_enum.py {posargs} + path: py.test --cov json_tricks --cov-report= --strict --exitfirst tests/test_bare.py tests/test_class.py tests/test_pathlib.py {posargs} ;{envsitepackagesdir}/json_tricks -
