diff --git a/.travis.yml b/.travis.yml index bc44c7785c..323c1b988e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ jobs: - python3-sphinx - python3-pip - python3-setuptools + - python3-cairocffi - graphviz-dev - xmlstarlet - jq diff --git a/.travis/build.sh b/.travis/build.sh index 3ba558f91b..93997c6278 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -75,6 +75,7 @@ if [ "$TRAVIS_BUILD_STAGE_NAME" == "Test" ]; then unset SMING_PROJECTS_DIR make docs V=1 else + make -C "$SMING_PROJECTS_DIR/samples/HttpServer_FirmwareUpload" python-requirements PIP_ARGS=--user $MAKE_PARALLEL samples make clean samples-clean $MAKE_PARALLEL Basic_Blink ENABLE_CUSTOM_HEAP=1 DEBUG_VERBOSE_LEVEL=3 diff --git a/.travis/install.sh b/.travis/install.sh index 7c29b49a24..9f6972d4f1 100755 --- a/.travis/install.sh +++ b/.travis/install.sh @@ -1,11 +1,10 @@ #!/bin/bash set -ex # exit with nonzero exit code if anything fails -pip install --user -r $TRAVIS_BUILD_DIR/samples/HttpServer_FirmwareUpload/requirements.txt - if [ "$TRAVIS_BUILD_STAGE_NAME" == "Test" ]; then sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-6.0 100 - pip3 install -r $TRAVIS_BUILD_DIR/docs/requirements.txt + python3 -m pip install --upgrade pip + python3 -m pip install -r $TRAVIS_BUILD_DIR/docs/requirements.txt fi if [ "$SMING_ARCH" == "Esp8266" ]; then diff --git a/Sming/Components/terminal/README.rst b/Sming/Components/terminal/README.rst index a32459320a..a8d7e94235 100644 --- a/Sming/Components/terminal/README.rst +++ b/Sming/Components/terminal/README.rst @@ -9,9 +9,9 @@ Introduction This Component provides make targets to support a serial terminal for communicating with devices. The default serial terminal is `miniterm `__. -If you don't have it installed already, do this:: +If you don't have it installed already, you can install it via pip using the following command:: - pip install pyserial + make python-requirements (You'll need `python `__, of course.) diff --git a/Sming/Components/terminal/requirements.txt b/Sming/Components/terminal/requirements.txt new file mode 100644 index 0000000000..f6c1a1f572 --- /dev/null +++ b/Sming/Components/terminal/requirements.txt @@ -0,0 +1 @@ +pyserial diff --git a/Sming/building.rst b/Sming/building.rst index 32e75d11a3..f9f98725c5 100644 --- a/Sming/building.rst +++ b/Sming/building.rst @@ -562,6 +562,22 @@ changed as required. Set to any additional flags to be used when linking. +.. envvar:: COMPONENT_PYTHON_REQUIREMENTS + + If the component requires uncommon Python modules (e. g. as part of a custom + build step), set this variable to one or more `requirements.txt `_ + files. This allows installation of all python requirements of the project by + invoking:: + + make python-requirements [PIP_ARGS=...] + + .. note:: + + A `requirements.txt` file in the root directory of the Component is + detected automatically without setting this variable. To prevent + autodetection (e.g. if the python requirements depend on another + configuration variable) you must set this variable to an empty value. + These values are global so must only be appended to (with ``+=``) , never overwritten. diff --git a/Sming/project.mk b/Sming/project.mk index 4fc8d06f45..b480ca9073 100644 --- a/Sming/project.mk +++ b/Sming/project.mk @@ -137,6 +137,9 @@ COMPONENTS_EXTRA_INCDIR := # Components may specify directories containing source code to be compiled with application APPCODE := +# Python requirements.txt collected from components +PYTHON_REQUIREMENTS := + # # This macro sets the default component variables before including the (optional) component.mk file. # @@ -160,6 +163,7 @@ COMPONENT_VARS := COMPONENT_RELINK_VARS := COMPONENT_TARGETS := COMPONENT_DEPENDS := +COMPONENT_PYTHON_REQUIREMENTS := $$(wildcard $2/requirements.txt) EXTRA_LIBS := EXTRA_LDFLAGS := # Process any component.mk file (optional) @@ -184,6 +188,7 @@ CMP_$1_LIBNAME := $$(COMPONENT_LIBNAME) CMP_$1_INCDIRS := $$(COMPONENT_INCDIRS) CMP_$1_DEPENDS := $$(COMPONENT_DEPENDS) CMP_$1_RELINK_VARS := $$(COMPONENT_RELINK_VARS) +PYTHON_REQUIREMENTS += $$(call AbsoluteSourcePath,$2,$$(COMPONENT_PYTHON_REQUIREMENTS)) APPCODE += $$(call AbsoluteSourcePath,$2,$$(CMP_$1_APPCODE)) COMPONENTS += $$(filter-out $$(COMPONENTS),$$(CMP_$1_DEPENDS)) ifneq (App,$1) @@ -450,6 +455,17 @@ decode-stacktrace: ##Open the stack trace decoder ready to paste dump text. Alte $(Q) $(PYTHON) $(ARCH_TOOLS)/decode-stacktrace.py $(TARGET_OUT_0) $(TRACE) +CACHE_VARS += PIP_ARGS +PIP_ARGS ?= +.PHONY: python-requirements +python-requirements: ##Install Python requirements of project via pip (use PIP_ARGS=... for additional options) +ifeq (,$(PYTHON_REQUIREMENTS)) + @echo No Python requirements to install for this project. +else + @echo Installing Python requirements... + $(Q) $(PYTHON) -m pip install $(PIP_ARGS) $(foreach reqfile,$(PYTHON_REQUIREMENTS),-r $(reqfile)) +endif + ##@Testing # OTA Server @@ -505,6 +521,21 @@ list-components: ##Print details of all Components for this project $(info Components:) $(foreach c,$(sort $(COMPONENTS)),$(eval $(call PrintComponentInfo,$c))) +# Dump content of requirements.txt file +# $1 -> absolute path to file +define DumpRequirementsTxt + @echo \# From $1: + @cat $1 + +endef +.PHONY: list-python-requirements +list-python-requirements: ##List Python requirements for this project +ifeq (,$(PYTHON_REQUIREMENTS)) + @echo \# No Python requirements for this project. +else + $(foreach reqfile,$(PYTHON_REQUIREMENTS),$(call DumpRequirementsTxt,$(reqfile))) +endif + # => Help .PHONY: help help: ##Show this help summary @@ -516,7 +547,7 @@ ifneq (,$V) @echo ' cmp-rebuild' endif - + # Update build type cache $(shell mkdir -p $(dir $(BUILD_TYPE_FILE)); \ echo '# Automatically generated file. Do not edit.' > $(BUILD_TYPE_FILE); \ diff --git a/samples/HttpServer_FirmwareUpload/component.mk b/samples/HttpServer_FirmwareUpload/component.mk index f6af56de90..747df3fc4b 100644 --- a/samples/HttpServer_FirmwareUpload/component.mk +++ b/samples/HttpServer_FirmwareUpload/component.mk @@ -9,10 +9,6 @@ web-pack: web-upload: web-pack spiffs-image-update $(call WriteFlash,$(RBOOT_SPIFFS_0)=$(SPIFF_BIN_OUT)) -.PHONY: python-requirements -python-requirements: - $(PYTHON) -m pip install --user -r requirements.txt - SIGNTOOL := $(PYTHON) $(COMPONENT_PATH)/signtool.py SIGNING_KEY := $(COMPONENT_PATH)/signing.key VERIFICATION_HEADER := $(COMPONENT_PATH)/app/FirmwareVerificationKey.h diff --git a/samples/HttpServer_FirmwareUpload/requirements.txt b/samples/HttpServer_FirmwareUpload/requirements.txt index 19d7d50eab..9ad05add23 100644 --- a/samples/HttpServer_FirmwareUpload/requirements.txt +++ b/samples/HttpServer_FirmwareUpload/requirements.txt @@ -1,3 +1 @@ -# Requirements file for pip -# list of Python packages used in documentation build PyNaCl