Skip to content

Commit

Permalink
Merge pull request #116 from twm/relocate-importwarning-bpso-116108
Browse files Browse the repository at this point in the history
BPSO-116108 Warn about pyhash on use
  • Loading branch information
twm committed Oct 9, 2020
2 parents 1fd9c3c + 9f99460 commit bc820d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 20.10.0
===============

- **Feature:** The ``ImportWarning`` ``Import of pyhash failed, using pure python`` is no longer issued at import time.
Instead, an import warning with the text ``Using slow pure Python Murmur2 hash; install Afkak[FastMurmur2] for speedup`` is issued when the hash function is called by ``afkak.partitioner.HashedPartitioner``.
This prevents the warning from appearing when using Afkak as a consumer.

Version 20.9.0
===============

Expand Down
9 changes: 5 additions & 4 deletions afkak/partitioner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Cyan, Inc.
# Copyright 2017, 2018, 2019 Ciena Corporation
# Copyright 2017, 2018, 2019, 2020 Ciena Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,9 +22,6 @@
from pyhash import murmur2_32 as _murmur2_32
_c_murmur2 = _murmur2_32(0x9747b28c)
except ImportError: # pragma: no cover
warnings.warn(
"Import of pyhash failed, using pure python", ImportWarning,
)
_c_murmur2 = None


Expand Down Expand Up @@ -185,6 +182,10 @@ def _hash(self, key):
Coerce the input into a bytearray for the pure-Python MurmurHash2
implementation.
"""
warnings.warn(
"Using slow pure Python Murmur2 hash; install Afkak[FastMurmur2] for speedup",
ImportWarning,
)
if isinstance(key, type(u'')):
key = bytearray(key, 'UTF-8')
elif isinstance(key, bytes):
Expand Down

0 comments on commit bc820d7

Please sign in to comment.