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

Commit

Permalink
Add sanity checks rules
Browse files Browse the repository at this point in the history
  • Loading branch information
yillkid committed Aug 22, 2018
1 parent 0b1bbf8 commit 91f89af
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions mk/python.mk
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
# check Python version
PY_FAVORED_VER = 3.5
PYTHON := $(shell which "python")
PYTHON_COMPATIBLE_VERSION = 3.5
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$(PYTHON_COMPATIBLE_VERSION) package.")
install python$(PY_FAVORED_VER) package.")
endif # $(shell which "python")

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

PYTHON_COMPATIBLE_PATH := $(shell which "python"$(PYTHON_COMPATIBLE_VERSION))
PY_CHECK_VERSION := $(shell $(PYTHON) -V)

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.")
ifeq "$(filter $(PY_FAVORED_VER).%, $(PY_CHECK_VERSION))" ""

This comment has been minimized.

Copy link
@jserv

jserv Aug 22, 2018

Collaborator

It looks ugly. Can you improve the condition?

This comment has been minimized.

Copy link
@jserv

jserv Aug 22, 2018

Collaborator

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

PYTHON := $(shell which "python"$(PY_FAVORED_VER))

This comment has been minimized.

Copy link
@jserv

jserv Aug 22, 2018

Collaborator

Use macros in GNU macro to simplify detection flow.

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$(PYTHON_COMPATIBLE_VERSION).")
$(error "$(shell python -V):Unsupported python version, only available for Python$(PY_FAVORED_VER).")
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")
$(error "Dependency error $@ because PyOTA is not installed, to install the latest version: pip install pyota")

This comment has been minimized.

Copy link
@jserv

jserv Aug 22, 2018

Collaborator

Sometimes, it has to be pip3. You have to detect and probe.

This comment has been minimized.

Copy link
@jserv

jserv Aug 22, 2018

Collaborator

It is not "Dependency error". Instead, it lacks of pre-configured PyOTA package.

endif

0 comments on commit 91f89af

Please sign in to comment.