diff --git a/Makefile b/Makefile index e40c5ff..5d9607c 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +include mk/python.mk DCURL_DIR := deps/dcurl DCURL_LIB := $(DCURL_DIR)/build/libdcurl.so DEPS += $(DCURL_LIB) @@ -19,7 +20,7 @@ TESTS += $(wildcard tests/tangleid/*.sh) check: server.py $(DCURL_LIB) @ TMP_PID=`mktemp /tmp/server_pid.XXXXXX`; \ echo "Running test suite..." ; \ - ( python $^ & echo $$! > $${TMP_PID} ); \ + ( $(PYTHON) $^ & echo $$! > $${TMP_PID} ); \ sleep 3 ; \ for i in $(TESTS); do \ ( echo "\n\n==[ $$i ]==\n"; $$i || kill -9 `cat $${TMP_PID}` ) \ diff --git a/README.md b/README.md index 581325e..1501b71 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Most use cases for micropayments involve a single user or device interacting repeatedly with a few vendors. ## Prerequisites +This package depends on PyOTA, which is known to work with Python 3.5. However, before PyOTA issue [#203](https://github.com/iotaledger/iota.lib.py/issues/203) is resolved, Python 3.6/3.7 will be excluded for running this package. The build system would detect and validate the environment in advance. Install dependent packages: ```shell diff --git a/mk/python.mk b/mk/python.mk new file mode 100644 index 0000000..7f7fa83 --- /dev/null +++ b/mk/python.mk @@ -0,0 +1,47 @@ +# check Python version +PY_FAVORED_VER = 3.5 +PYTHON := $(shell which "python") +ifndef PYTHON +PYTHON := $(shell which "python3") +endif + +ifndef PYTHON +PYTHON := $(shell which "python$(PY_FAVORED_VER)") +endif + +ifndef PYTHON +$(error "Python is not executable, try to check the PATH environment variable or \ +install python$(PY_FAVORED_VER) package.") +endif # $(shell which "python") + +PY_CHECK_VERSION := $(shell $(PYTHON) -V) + +ifeq "$(filter $(PY_FAVORED_VER).%, $(PY_CHECK_VERSION))" "" +PYTHON := $(shell which "python"$(PY_FAVORED_VER)) +ifdef PYTHON +$(error "Found python$(PY_FAVORED_VER), but it should be set as \ +default interpreter, try to set $(PYTHON) in PATH environment variable.") +else +$(error "$(shell python -V):Unsupported python version, only available for Python$(PY_FAVORED_VER).") +endif # PYTHON +endif # "$(filter ... + +# check "iota" module in Python installation +PY_CHECK_MOD_IOTA := $(shell python -c "import iota" 2>/dev/null && \ + echo 1 || echo 0) +ifeq ("$(PY_CHECK_MOD_IOTA)","0") +PIP := $(shell pip -V && echo 1 || echo 0)) +PIP_CHECK_VERSION := $(findstring python 3, $(PIP) && echo $@ || echo 0) +endif + +ifneq ("$(PIP)", "1") +$(error "PIP package doesn't pre-configured, try to install it.") +endif + +ifeq ("$(PIP_CHECK_VERSION)", "0") +PIP_FAVORED_VER = 3 +endif + +ifeq ("$(PY_CHECK_MOD_IOTA)", "0") +$(error "PyOTA package doesn't pre-configured, install the latest version: pip$(PIP_FAVORED_VER) install pyota") +endif diff --git a/swarm_node.py b/swarm_node.py index 5c19b04..70368c1 100644 --- a/swarm_node.py +++ b/swarm_node.py @@ -145,8 +145,9 @@ def send_transfer(tag, messages, address, values, dict_tips, debug=0): time_end_pow = time.time() elapsed_pow = elapsed_pow + (time_end_pow - time_start_pow) - print("Prepare to broadcast ...") + print("Prepare to store and broadcast ...") try: + api.store_transactions([tx_tryte[0:2673]]) api.broadcast_transactions([tx_tryte[0:2673]]) except Exception as e: print("Error: %s" % (str(e.context)))