Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

Perform sanity checks with Python3 #25

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include mk/python.mk
DCURL_DIR := deps/dcurl
DCURL_LIB := $(DCURL_DIR)/build/libdcurl.so
DEPS += $(DCURL_LIB)
Expand All @@ -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}` ) \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Most use cases for micropayments involve a single user or device interacting
repeatedly with a few vendors.

## Prerequisites
`iota-swarm-node`, compatible with Python3+ as well as depending on [Pyota](https://github.com/iotaledger/iota.lib.py) is theoretically available for both Python 3.5 and 3.6; yet, our testing result indicates that the environment for Python 3.6 is invalid in this case. Details as [Pyota issue#203](https://github.com/iotaledger/iota.lib.py/issues/203).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is PyOTA instead of Pyota.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the wording: "invalid"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove "theoretically". Instead, it would be "expectedly" or something alike.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace Pyota issue#203 with PyOTA issue #203. Be aware of the spelling.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove "as well".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite the abobe wording to

"This package depends in PyOTA, which is known to work with Python 3.5. However, before PyOTA issue #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
Expand Down
30 changes: 30 additions & 0 deletions mk/python.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# check Python version
PYTHON := $(shell which "python")
PYTHON_COMPATIBLE_VERSION = 3.5

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blank line here.

ifndef PYTHON
Copy link
Collaborator

@jserv jserv Aug 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add extra condition if python indicated by $PATH is exactly of version 3. Think of the case that somebody built Python3 from source and the generated executable is python.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If python is not present, try python3. Then, if version is mismatching, try python3.5.

$(error "Python is not executable, try to check the PATH environment variable or \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

install python$(PYTHON_COMPATIBLE_VERSION) package.")
endif # $(shell which "python")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove non-effective "$(shell which "python")".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say, "no valid Python interpreter is found".


PY_CHECK_VERSION := $(shell python -c "print(str(__import__('sys').version_info.major) + \
str('.') + str(__import__('sys').version_info.minor) )")

ifneq ($(PY_CHECK_VERSION), $(PYTHON_COMPATIBLE_VERSION))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid this blank line.

PYTHON_COMPATIBLE_PATH := $(shell which "python"$(PYTHON_COMPATIBLE_VERSION))

ifdef PYTHON_COMPATIBLE_PATH
$(error "Found python$(PYTHON_COMPATIBLE_VERSION) in current environment, but it should be setting as \
default interpreter, try to set $(PYTHON_COMPATIBLE_PATH) in PATH environment variable.")
else
$(error "$(shell python -V):Unsupported python version, only available for Python$(PYTHON_COMPATIBLE_VERSION).")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace python with $(PYTHON).

endif
endif

# check "iota" module in Python installation
PY_CHECK_MOD_IOTA := $(shell python -c "import iota" 2>/dev/null && \
echo 1 || echo 0)
ifneq ("$(PY_CHECK_MOD_IOTA)","1")
$(error "Dependency error $@ because PyOTA is not installed, to install the latest version: pip3 install pyota")
endif