-
Notifications
You must be signed in to change notification settings - Fork 9
Perform sanity checks with Python3 #25
base: master
Are you sure you want to change the base?
Conversation
README.md
Outdated
@@ -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` is compatible with Python 3.5. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording is misleading. Instead, python 3.5+ is required as PyOTA configures. You have to emphasize on the rationale in plain English descriptions, otherwise nobody can be aware of it.
@@ -0,0 +1,12 @@ | |||
PYTHON = python3 | |||
PYTHON := $(shell which $(PYTHON)) | |||
ifndef PYTHON |
There was a problem hiding this comment.
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
.
mk/python.mk
Outdated
PYTHON = python3 | ||
PYTHON := $(shell which $(PYTHON)) | ||
ifndef PYTHON | ||
$(error "python3 is required.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Python 3.5+ is required, you have to validate its version.
mk/python.mk
Outdated
PY_CHECK_MOD_IOTA := $(shell $(PYTHON) -c "import iota" 2>/dev/null && \ | ||
echo 1 || echo 0) | ||
ifneq ("$(PY_CHECK_MOD_IOTA)","1") | ||
$(error "skip $@ because PyIOTA is not installed.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is PyOTA
or iota.lib.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is wrong because it does not "skip". Instead, we would take actions if both Python3 and PyOTA are absent. You shall dump informative diagnosis messages.
mk/python.mk
Outdated
PY_CHECK_MOD_IOTA := $(shell $(PYTHON) -c "import iota" 2>/dev/null && \ | ||
echo 1 || echo 0) | ||
ifneq ("$(PY_CHECK_MOD_IOTA)","1") | ||
$(error "skip $@ because PyOTA is not installed.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inform users of the diagnosis and information about trouble shooting. Change the wording from "skip" to something really making sense.
TODO: Validate Python installation from the perspectives of the following:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve Python version validation.
mk/python.mk
Outdated
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: pip install pyota") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Display error messages in multiple lines.
mk/python.mk
Outdated
@@ -0,0 +1,12 @@ | |||
PYTHON = python3.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The detection is not correct. If python is built from source, only file python
is generated. You shall validate through the output of python --version
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The coverage about Python 3.7 is not addressed yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shall always try to build Python from source and check how its directory structure is.
README.md
Outdated
@@ -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`, writing with Python3+ compatible code as well as depending on [Pyota](https://github.com/iotaledger/iota.lib.py) is theoretically available for bot 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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the grammar again. It is not "writing with".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might have to consider virtualenv or pythonbrew.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"bot Python 3.5 and 3.6" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explanation should be enforced to validation logic.
mk/python.mk
Outdated
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Python executable is restricted, the validation of pip
would be considered.
README.md
Outdated
@@ -10,7 +10,7 @@ Most use cases for micropayments involve a single user or device interacting | |||
repeatedly with a few vendors. | |||
|
|||
## Prerequisites | |||
`iota-swarm-node`, writing with Python3+ compatible code as well as depending on [Pyota](https://github.com/iotaledger/iota.lib.py) is theoretically available for bot 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). | |||
`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). |
There was a problem hiding this comment.
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
.
mk/python.mk
Outdated
$(error "Python is not executable, try to check the PATH environment variable or install $(PYTHON_COMPATIBLE) package.") | ||
endif # PYTHON | ||
|
||
ifdef PYTHON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to check $(PYTHON)
since you already exclude its absence.
mk/python.mk
Outdated
|
||
ifdef PYTHON_COMPATIBLE_PATH | ||
$(error "Found $(PYTHON_COMPATIBLE) in current environment, but it should be setting as \ | ||
default interpreter, try to create a symbolic link for $(PYTHON_COMPATIBLE_PATH)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't suggest to make symbolic link. Instead, configure via environment variables.
endif | ||
endif # PYTHON | ||
|
||
ifndef PYTHON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. Focus on detailed items.
mk/python.mk
Outdated
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 | ||
endif # PYTHON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid nested ifdef
and endif
pair as possible as you can.
mk/python.mk
Outdated
$(error "Found $(PYTHON_COMPATIBLE) in current environment, but it should be setting as \ | ||
default interpreter, try to create a symbolic link for $(PYTHON_COMPATIBLE_PATH)") | ||
else | ||
$(error "$(shell python -V):Invalid Python version, only available for $(PYTHON_COMPATIBLE).") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is NOT Invalid Python version
. Instead, only Python 3.5 is known to work with PyOTA. You have to address.
mk/python.mk
Outdated
PYTHON := $(shell which $(PYTHON)) | ||
# check Python version | ||
PYTHON := $(shell which "python") | ||
PYTHON_COMPATIBLE = python3.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename it to PYTHON35
to reflect its functionality.
mk/python.mk
Outdated
PY_CHECK_VERSION := $(shell python -c "print(__import__('sys').version_info[0:2])") | ||
|
||
ifneq ($(PY_CHECK_VERSION), (3, 5)) | ||
PYTHON_COMPATIBLE_PATH := $(shell which $(PYTHON_COMPATIBLE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't rely on new var PYTHON_COMPATIBLE_PATH
. Instead, override PYTHON
since you always block the one which is not accepted by each qualification.
README.md
Outdated
@@ -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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct the wording: "invalid"
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
str('.') + str(__import__('sys').version_info.minor) )") | ||
|
||
ifneq ($(PY_CHECK_VERSION), $(PYTHON_COMPATIBLE_VERSION)) | ||
|
There was a problem hiding this comment.
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 := $(shell which "python") | ||
PYTHON_COMPATIBLE_VERSION = 3.5 | ||
|
||
ifndef PYTHON |
There was a problem hiding this comment.
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
.
mk/python.mk
Outdated
$(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).") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace python
with $(PYTHON)
.
Could you explain more about that? |
The $(PYTHON) assign priority is python --> python3 --> python(favored version), if both python3.5, python3.6 are available in $PATH and symbolic link |
README.md
Outdated
@@ -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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "as well".
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce the indentation. We shall always make detection script slight and elegant.
mk/python.mk
Outdated
PY_FAVORED_VER = 3.5 | ||
PYTHON := $(shell which "python") | ||
ifndef PYTHON | ||
PYTHON := $(shell which "python3") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't indent here.
mk/python.mk
Outdated
endif | ||
|
||
ifndef PYTHON | ||
PYTHON := $(shell which "python$(PY_FAVORED_VER)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
mk/python.mk
Outdated
endif | ||
|
||
ifndef PYTHON | ||
$(error "Python is not executable, try to check the PATH environment variable or \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
mk/python.mk
Outdated
PY_CHECK_VERSION := $(shell $(PYTHON) -V) | ||
|
||
ifeq "$(filter $(PY_FAVORED_VER).%, $(PY_CHECK_VERSION))" "" | ||
PYTHON := $(shell which "python"$(PY_FAVORED_VER)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce the indentation for pretty code snip.
mk/python.mk
Outdated
PY_CHECK_MOD_IOTA := $(shell python -c "import iota" 2>/dev/null && \ | ||
echo 1 || echo 0) | ||
ifneq ("$(PY_CHECK_MOD_IOTA)","1") | ||
PIP := $(shell pip -V) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
mk/python.mk
Outdated
ifndef PIP_CHECK_VERSION | ||
PIP_FAVORED_VER = 3 | ||
endif | ||
$(error "PyOTA package doesn't pre-configured, install the latest version: pip$(PIP_FAVORED_VER) install pyota") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
Check dcurl for illustrating macro usage with GNU make: https://github.com/DLTcollab/dcurl/blob/dev/Makefile#L32 |
Once macros are appropriately facilitated, no more nested conditional syntax (such as |
README.md
Outdated
@@ -10,7 +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). | |||
This package depends in 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depends "on", not "in".
endif | ||
PYTHON := $(shell which "python"$(PY_FAVORED_VER)) | ||
ifdef PYTHON | ||
$(error "Found python$(PY_FAVORED_VER), but it should be set as \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it is valid according to the error message?
PIP_CHECK_VERSION := $(findstring python 3, $(PIP) && echo $@ || echo 0) | ||
endif | ||
|
||
ifneq ("$(PIP)", "1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ifdef
rather than ifneq
or ifeq
for consistency.
endif | ||
|
||
ifneq ("$(PIP)", "1") | ||
$(error "PIP package doesn't pre-configured, try to install it.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix grammar error.
ifndef PIP_CHECK_VERSION | ||
PIP_FAVORED_VER = 3 | ||
ifeq ("$(PY_CHECK_MOD_IOTA)", "0") | ||
$(error "PyOTA package doesn't pre-configured, install the latest version: pip$(PIP_FAVORED_VER) install pyota") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. Fix grammar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using pip
is not the only way to install Python packages. Sometimes, package maintainer might prepare prebuilt one or recipes that describe how to install Python packages. You can leave the message: "please ask your administrator to install the package 'pyota' or build from source: https://github.com/iotaledger/iota.lib.py"
endif | ||
|
||
ifndef PYTHON | ||
$(error "Python is not executable, try to check the PATH environment variable or \ | ||
install python$(PY_FAVORED_VER) package.") | ||
$(error "Python is not executable, try to check the PATH environment variable or \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ambiguous to say "Python is not executable". Use precise words.
ifndef PYTHON | ||
PYTHON := $(shell which "python3") | ||
endif | ||
|
There was a problem hiding this comment.
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 | ||
$(error "Python is not executable, try to check the PATH environment variable or \ | ||
install python$(PY_FAVORED_VER) package.") | ||
endif # $(shell which "python") |
There was a problem hiding this comment.
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")".
There was a problem hiding this comment.
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".
$(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).") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain the exact reason and point unresolved issue(s) here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate ifdef-else statement. Logic error.
else | ||
$(error "$(shell python -V):Unsupported python version, only available for Python$(PY_FAVORED_VER).") | ||
endif # PYTHON | ||
endif # "$(filter ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. You don't have to mention "$(filter ..." once you remove nested conditions.
@yillkid, you should create a new branch as workspace for commit "Store transaction before broadcast |
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyOTA doesn't support Python 3.7 because it has package Filters
which doesn't either.
Switch test suites invocation to Python3.