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
Open

Perform sanity checks with Python3 #25

wants to merge 12 commits into from

Conversation

yillkid
Copy link
Owner

@yillkid yillkid commented Aug 18, 2018

Switch test suites invocation to Python3.

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.
Copy link
Collaborator

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
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.

mk/python.mk Outdated
PYTHON = python3
PYTHON := $(shell which $(PYTHON))
ifndef PYTHON
$(error "python3 is required.")
Copy link
Collaborator

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.")
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 or iota.lib.py.

Copy link
Collaborator

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.

@jserv jserv changed the title Perform sanity checks on Python3 Perform sanity checks with Python3 Aug 18, 2018
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.")
Copy link
Collaborator

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.

@jserv
Copy link
Collaborator

jserv commented Aug 18, 2018

TODO: Validate Python installation from the perspectives of the following:

  1. python3 package: Don't assume Debian/Ubuntu packages are available. Instead, you have to be aware of the case that somebody always build python3 from source (and you should try as well).
  2. The version of python3: only 3.5 or later are known to work.
  3. The availability of PyOTA: you have to mention and alert users if no package is installed.

Copy link
Collaborator

@jserv jserv left a 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")
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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).
Copy link
Collaborator

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".

Copy link
Collaborator

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.

Copy link
Collaborator

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" ?

Copy link
Collaborator

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")
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 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).
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.

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
Copy link
Collaborator

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)")
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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).")
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 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
Copy link
Collaborator

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))
Copy link
Collaborator

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).
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.

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 := $(shell which "python")
PYTHON_COMPATIBLE_VERSION = 3.5

ifndef 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.

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).")
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).

@yillkid
Copy link
Owner Author

yillkid commented Aug 23, 2018

Use macros in GNU macro to simplify detection flow.

Could you explain more about that?

@yillkid
Copy link
Owner Author

yillkid commented Aug 23, 2018

Can you handle the case that both python3.5 and python3.6 are available in $PATH?

The $(PYTHON) assign priority is python --> python3 --> python(favored version), if both python3.5, python3.6 are available in $PATH and symbolic link python is linked with python3.5, it will work. If not, an error message Found python$(PY_FAVORED_VER), but it should be set as default interpreter, try to set $(PYTHON) in PATH environment variable. will be trigged.

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).
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."

Copy link
Collaborator

@jserv jserv left a 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")
Copy link
Collaborator

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)")
Copy link
Collaborator

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 \
Copy link
Collaborator

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))
Copy link
Collaborator

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)
Copy link
Collaborator

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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto.

@jserv
Copy link
Collaborator

jserv commented Aug 24, 2018

Check dcurl for illustrating macro usage with GNU make: https://github.com/DLTcollab/dcurl/blob/dev/Makefile#L32

@jserv jserv closed this Aug 24, 2018
@jserv jserv reopened this Aug 24, 2018
@jserv
Copy link
Collaborator

jserv commented Aug 24, 2018

Once macros are appropriately facilitated, no more nested conditional syntax (such as ifdef and endif) will be taken, that implies compacted and dedicated script, thinking perspective of maintenance.

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.
Copy link
Collaborator

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 \
Copy link
Collaborator

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")
Copy link
Collaborator

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.")
Copy link
Collaborator

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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto. Fix grammar.

Copy link
Collaborator

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 \
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 ambiguous to say "Python is not executable". Use precise words.

ifndef PYTHON
PYTHON := $(shell which "python3")
endif

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
$(error "Python is not executable, try to check the PATH environment variable or \
install python$(PY_FAVORED_VER) 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".

$(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).")
Copy link
Collaborator

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.

Copy link
Collaborator

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 ...
Copy link
Collaborator

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.

@jserv
Copy link
Collaborator

jserv commented Oct 31, 2018

@yillkid, you should create a new branch as workspace for commit "Store transaction before broadcast
". Otherwise, this pull request would be polluted.

@@ -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.
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants