Skip to content

Commit c8456c2

Browse files
authored
Merge pull request #133 from seperman/dev
DeepDiff 4.0.1
2 parents 885a5d5 + b3e2b10 commit c8456c2

File tree

12 files changed

+101
-21
lines changed

12 files changed

+101
-21
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include *.rst
2+
include *.txt
23
global-exclude __pycache__
34
global-exclude *.py[co]

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# DeepDiff v 4.0.0
1+
# DeepDiff v 4.0.1
22

33
<!-- ![Downloads](https://img.shields.io/pypi/dm/deepdiff.svg?style=flat) -->
44
![Python Versions](https://img.shields.io/pypi/pyversions/deepdiff.svg?style=flat)
@@ -13,7 +13,7 @@
1313

1414
Tested on Python 3.4, 3.5, 3.6, 3.7, Pypy3
1515

16-
**NOTE: Python 2 is not supported any more. DeepDiff v3.3.0 was the last version to supprt Python 2**
16+
**NOTE: Python 2 is not supported any more. DeepDiff v3.3.0 was the last version to support Python 2**
1717

1818

1919
- [Documentation](http://deepdiff.readthedocs.io/en/latest/)
@@ -23,7 +23,15 @@ Tested on Python 3.4, 3.5, 3.6, 3.7, Pypy3
2323

2424
### Install from PyPi:
2525

26-
pip install deepdiff
26+
`pip install deepdiff`
27+
28+
DeepDiff prefers to use Murmur3 for hashing. However you have to manually install Murmur3 by running:
29+
30+
`pip install mmh3`
31+
32+
Otherwise DeepDiff will be using SHA256 for hashing which is a cryptographic hash and is considerably slower.
33+
34+
If you are running into trouble installing Murmur3, please take a look at the [Troubleshoot](#troubleshoot) section.
2735

2836
### Importing
2937

@@ -388,8 +396,25 @@ And here is more info: <http://zepworks.com/blog/diff-it-to-digg-it/>
388396

389397
<http://deepdiff.readthedocs.io/en/latest/>
390398

399+
# Troubleshoot
400+
401+
## Murmur3
402+
403+
`Failed to build mmh3 when installing DeepDiff`
404+
405+
DeepDiff prefers to use Murmur3 for hashing. However you have to manually install murmur3 by running: `pip install mmh3`
406+
407+
On MacOS Mojave some user experience difficulty when installing Murmur3.
408+
409+
The problem can be solved by running:
410+
411+
`xcode-select --install`
412+
413+
And then running `pip install mmh3`
414+
391415
# ChangeLog
392416

417+
- v4-0-1: Fixing installation Tarball missing requirements.txt . DeepDiff v4+ should not show up as pip installable for Py2. Making Murmur3 installation optional.
393418
- v4-0-0: Ending Python 2 support, Adding more functionalities and documentation for DeepHash. Switching to Pytest for testing. Switching to Murmur3 128bit for hashing. Fixing classes which inherit from classes with slots didn't have all of their slots compared. Renaming ContentHash to DeepHash. Adding exclude by path and regex path to DeepHash. Adding ignore_type_in_groups. Adding match_string to DeepSearch. Adding Timedelta object diffing.
394419
- v3-5-0: Exclude regex path
395420
- v3-3-0: Searching for objects and class attributes

deepdiff/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""This module offers the DeepDiff, DeepSearch, grep and DeepHash classes."""
22
# flake8: noqa
3-
__version__ = '4.0.0'
3+
__version__ = '4.0.1'
44
import logging
55

66
if __name__ == '__main__':

deepdiff/deephash.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import os
4-
import mmh3
54
import logging
65
from collections import Iterable
76
from collections import MutableMapping
87
from collections import defaultdict
98
from decimal import Decimal
10-
from hashlib import sha1
9+
from hashlib import sha1, sha256
1110

1211
from deepdiff.helper import (strings, numbers, unprocessed, not_hashed, add_to_frozen_set,
1312
convert_item_or_items_into_set_else_none, current_dir,
1413
convert_item_or_items_into_compiled_regexes_else_none,
1514
get_id)
1615
from deepdiff.base import Base
17-
1816
logger = logging.getLogger(__name__)
1917

18+
try:
19+
import mmh3
20+
except ImportError:
21+
logger.warning('Can not find Murmur3 hashing installed. Switching to SHA256 as the default hash. Refer to https://github.com/seperman/deepdiff#murmur3 for more info.')
22+
mmh3 = False
23+
2024
UNPROCESSED = 'unprocessed'
2125
MURMUR_SEED = 1203
2226

@@ -77,8 +81,8 @@ def __init__(self,
7781
self.ignore_repetition = ignore_repetition
7882
self.exclude_paths = convert_item_or_items_into_set_else_none(exclude_paths)
7983
self.exclude_regex_paths = convert_item_or_items_into_compiled_regexes_else_none(exclude_regex_paths)
80-
81-
self.hasher = self.murmur3_128bit if hasher is None else hasher
84+
default_hasher = self.murmur3_128bit if mmh3 else self.sha256hex
85+
self.hasher = default_hasher if hasher is None else hasher
8286
hashes = hashes if hashes else {}
8387
self.update(hashes)
8488
self[UNPROCESSED] = []
@@ -101,6 +105,12 @@ def __init__(self,
101105
else:
102106
del self[UNPROCESSED]
103107

108+
@staticmethod
109+
def sha256hex(obj):
110+
"""Use Sha256 as a cryptographic hash."""
111+
obj = obj.encode('utf-8')
112+
return sha256(obj).hexdigest()
113+
104114
@staticmethod
105115
def sha1hex(obj):
106116
"""Use Sha1 as a cryptographic hash."""

deepdiff/deephash_doc.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ At the core of it, DeepHash is a deterministic serialization of your object into
1010
can be passed to a hash function. By default it uses Murmur 3 128 bit hash function which is a
1111
fast, non-cryptographic hashing function. You have the option to pass any another hashing function to be used instead.
1212

13+
If it can't find Murmur3 package (mmh3) installed, it uses Python's built-in SHA256 for hashing which is considerably slower than Murmur3. So it is advised that you install Murmur3 by running `pip install mmh3`
14+
1315
**Import**
1416
>>> from deepdiff import DeepHash
1517

@@ -89,13 +91,10 @@ By setting it to True, both the string and bytes of hello return the same hash.
8991
>>> DeepHash('hello', ignore_string_type_changes=True)
9092
{'hello': 221860156526691709602818861774599422448}
9193

92-
ignore_numeric_type_changes
93-
Default: False
94-
95-
ignore_numeric_type_changes: Boolean, default = True
94+
ignore_numeric_type_changes: Boolean, default = False
9695
numeric type conversions should not affect the hash output when this is set to True.
9796
For example 10, 10.0 and Decimal(10) should produce the same hash.
98-
However when ignore_numeric_type_changes is set to True, all numbers are converted
97+
When ignore_numeric_type_changes is set to True, all numbers are converted
9998
to decimals with the precision of significant_digits parameter.
10099
If no significant_digits is passed by the user, a default value of 55 is used.
101100

deepdiff/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self,
5757
ignore_numeric_type_changes=False,
5858
verbose_level=1,
5959
view=TEXT_VIEW,
60-
hasher=DeepHash.murmur3_128bit,
60+
hasher=None,
6161
**kwargs):
6262
if kwargs:
6363
raise ValueError((

deepdiff/diff_doc.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Example of using the text view.
9191
>>> print(ddiff)
9292
{'dictionary_item_added': [root[5], root[6]], 'dictionary_item_removed': [root[4]]}
9393

94-
So for example ddiff['dictionary_item_removed'] is a set if strings thus this is called the text view.
94+
So for example ddiff['dictionary_item_added'] is a set of strings thus this is called the text view.
9595

9696
.. seealso::
9797
The following examples are using the *default text view.*
@@ -328,7 +328,7 @@ The shortcuts are ignore_string_type_changes which by default is False and ignor
328328

329329
For example lets say you have specifically str and byte datatypes to be ignored for type changes. Then you have a couple of options:
330330

331-
1. Set ignore_string_type_changes=True which is the default.
331+
1. Set ignore_string_type_changes=True.
332332
2. Or set ignore_type_in_groups=[(str, bytes)]. Here you are saying if we detect one type to be str and the other one bytes, do not report them as type change. It is exactly as passing ignore_type_in_groups=[DeepDiff.strings] or ignore_type_in_groups=DeepDiff.strings .
333333

334334
Now what if you want also typeA and typeB to be ignored when comparing agains each other?

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
# built documents.
6161
#
6262
# The short X.Y version.
63-
version = '4.0.0'
63+
version = '4.0.1'
6464
# The full version, including alpha/beta/rc tags.
65-
release = '4.0.0'
65+
release = '4.0.1'
6666

6767
# The language for content autogenerated by Sphinx. Refer to documentation
6868
# for a list of supported languages.

docs/index.rst

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
contain the root `toctree` directive.
55
66
7-
DeepDiff 4.0.0 documentation!
7+
DeepDiff 4.0.1 documentation!
88
=============================
99

1010
**DeepDiff: Deep Difference of dictionaries, iterables, strings and other objects. It will recursively look for all the changes.**
@@ -25,6 +25,15 @@ Install from PyPi::
2525

2626
pip install deepdiff
2727

28+
DeepDiff prefers to use Murmur3 for hashing. However you have to manually install Murmur3 by running::
29+
30+
pip install mmh3
31+
32+
Otherwise DeepDiff will be using SHA256 for hashing which is a cryptographic hash and is considerably slower.
33+
34+
If you are running into trouble installing Murmur3, please take a look at the `Troubleshoot <#troubleshoot>`__ section.
35+
36+
2837
Importing
2938
~~~~~~~~~
3039

@@ -38,6 +47,12 @@ Importing
3847
DeepDiff
3948
********
4049

50+
Read The DeepDiff details in:
51+
52+
:doc:`/diff`
53+
54+
Short introduction::
55+
4156
Supported data types
4257
~~~~~~~~~~~~~~~~~~~~
4358

@@ -174,6 +189,12 @@ The core of DeepHash is a deterministic serialization of your object into a stri
174189
can be passed to a hash function. By default it uses Murmur 3 128 bit hash function.
175190
but you can pass another hash function to it if you want.
176191

192+
Read the details at:
193+
194+
:doc:`/deephash`
195+
196+
Examples:
197+
177198
Let's say you have a dictionary object.
178199

179200
.. code:: python
@@ -216,6 +237,28 @@ Read more in the Deep Hash reference:
216237
:doc:`/deephash`
217238

218239

240+
************
241+
Troubleshoot
242+
************
243+
244+
Murmur3
245+
~~~~~~~
246+
247+
`Failed to build mmh3 when installing DeepDiff`
248+
249+
DeepDiff prefers to use Murmur3 for hashing. However you have to manually install murmur3 by running: `pip install mmh3`
250+
251+
On MacOS Mojave some user experience difficulty when installing Murmur3.
252+
253+
The problem can be solved by running:
254+
255+
`xcode-select --install`
256+
257+
And then running
258+
259+
`pip install mmh3`
260+
261+
219262
References
220263
==========
221264

@@ -238,6 +281,7 @@ Indices and tables
238281
Changelog
239282
=========
240283

284+
- v4-0-1: Fixing installation Tarball missing requirements.txt . DeepDiff v4+ should not show up as pip installable for Py2. Making Murmur3 installation optional.
241285
- v4-0-0: Ending Python 2 support, Adding more functionalities and documentation for DeepHash. Switching to Pytest for testing. Switching to Murmur3 128bit for hashing. Fixing classes which inherit from classes with slots didn't have all of their slots compared. Renaming ContentHash to DeepHash. Adding exclude by path and regex path to DeepHash. Adding ignore_type_in_groups. Adding match_string to DeepSearch. Adding Timedelta object diffing.
242286
- v3-5-0: Exclude regex path
243287
- v3-3-0: Searching for objects and class attributes

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
pytest==4.0.1
33
pytest-cov==2.6.0
44
numpy==1.15.4
5+
mmh3==2.5.1

0 commit comments

Comments
 (0)