From c6c6deb71f34cb33ccae195444e2e02645ca5688 Mon Sep 17 00:00:00 2001 From: Nikita Chernyi Date: Mon, 1 Jul 2019 13:44:35 +0300 Subject: [PATCH] Init pypy support --- Dockerfile-dev | 4 ++-- bigchaindb/common/crypto.py | 8 ++++++-- bigchaindb/common/transaction.py | 5 ++++- setup.py | 2 +- tests/common/test_transaction.py | 5 ++++- tests/validation/test_transaction_structure.py | 5 ++++- tests/web/test_transactions.py | 5 ++++- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Dockerfile-dev b/Dockerfile-dev index f6535cab..a6c8fc05 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -1,5 +1,5 @@ ARG python_version=3.6 -FROM python:${python_version} +FROM pypy:${python_version} LABEL maintainer "devs@bigchaindb.com" RUN apt-get update \ @@ -33,4 +33,4 @@ RUN mkdir -p /usr/src/app COPY . /usr/src/app/ WORKDIR /usr/src/app RUN pip install -e .[dev] -RUN bigchaindb -y configure \ No newline at end of file +RUN bigchaindb -y configure diff --git a/bigchaindb/common/crypto.py b/bigchaindb/common/crypto.py index a8e42c52..66bdbf6c 100644 --- a/bigchaindb/common/crypto.py +++ b/bigchaindb/common/crypto.py @@ -5,7 +5,11 @@ # Separate all crypto code so that we can easily test several implementations from collections import namedtuple -import sha3 +try: + from hashlib import sha3_256 +except ImportError: + from sha3 import sha3_256 + from cryptoconditions import crypto @@ -14,7 +18,7 @@ CryptoKeypair = namedtuple('CryptoKeypair', ('private_key', 'public_key')) def hash_data(data): """Hash the provided data using SHA3-256""" - return sha3.sha3_256(data.encode()).hexdigest() + return sha3_256(data.encode()).hexdigest() def generate_key_pair(): diff --git a/bigchaindb/common/transaction.py b/bigchaindb/common/transaction.py index a1dfc626..701a01ae 100644 --- a/bigchaindb/common/transaction.py +++ b/bigchaindb/common/transaction.py @@ -19,7 +19,10 @@ import base58 from cryptoconditions import Fulfillment, ThresholdSha256, Ed25519Sha256 from cryptoconditions.exceptions import ( ParsingError, ASN1DecodeError, ASN1EncodeError, UnsupportedTypeError) -from sha3 import sha3_256 +try: + from hashlib import sha3_256 +except ImportError: + from sha3 import sha3_256 from bigchaindb.common.crypto import PrivateKey, hash_data from bigchaindb.common.exceptions import (KeypairMismatchException, diff --git a/setup.py b/setup.py index bb8e7c15..0c954692 100644 --- a/setup.py +++ b/setup.py @@ -74,7 +74,7 @@ tests_require = [ install_requires = [ # TODO Consider not installing the db drivers, or putting them in extras. 'pymongo~=3.6', - 'pysha3~=1.0.2', + # 'pysha3~=1.0.2', # @PYPY: not compability with PyPy, replaced with native hashlib 'cryptoconditions==0.8.0', 'python-rapidjson~=0.6.0', 'logstats~=0.2.1', diff --git a/tests/common/test_transaction.py b/tests/common/test_transaction.py index 8e5a2b6c..8df92209 100644 --- a/tests/common/test_transaction.py +++ b/tests/common/test_transaction.py @@ -11,7 +11,10 @@ from copy import deepcopy from base58 import b58encode, b58decode from cryptoconditions import Ed25519Sha256 from pytest import mark, raises -from sha3 import sha3_256 +try: + from hashlib import sha3_256 +except ImportError: + from sha3 import sha3_256 pytestmark = mark.bdb diff --git a/tests/validation/test_transaction_structure.py b/tests/validation/test_transaction_structure.py index 32622c87..804dd51b 100644 --- a/tests/validation/test_transaction_structure.py +++ b/tests/validation/test_transaction_structure.py @@ -9,7 +9,10 @@ structural / schematic issues are caught when reading a transaction import json import pytest -import sha3 +try: + import hashlib as sha3 +except ImportError: + import sha3 from unittest.mock import MagicMock from bigchaindb.common.exceptions import (AmountError, diff --git a/tests/web/test_transactions.py b/tests/web/test_transactions.py index ccf9d27c..d5b5cba4 100644 --- a/tests/web/test_transactions.py +++ b/tests/web/test_transactions.py @@ -8,7 +8,10 @@ from unittest.mock import Mock, patch import base58 import pytest from cryptoconditions import Ed25519Sha256 -from sha3 import sha3_256 +try: + from hashlib import sha3_256 +except ImportError: + from sha3 import sha3_256 from bigchaindb.common import crypto from bigchaindb.common.transaction_mode_types import (BROADCAST_TX_COMMIT,