Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add make target python-requirements to install Python requirements of project #2019

Merged
merged 6 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- python3-sphinx
- python3-pip
- python3-setuptools
- python3-cairocffi
- graphviz-dev
- xmlstarlet
- jq
Expand Down
1 change: 1 addition & 0 deletions .travis/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions .travis/install.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions Sming/Components/terminal/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://pyserial.readthedocs.io/en/latest/tools.html#module-serial.tools.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 <https://www.python.org/>`__, of course.)

Expand Down
1 change: 1 addition & 0 deletions Sming/Components/terminal/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyserial
16 changes: 16 additions & 0 deletions Sming/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://pip.readthedocs.io/en/latest/reference/pip_install/#requirements-file-format>`_
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.

Expand Down
33 changes: 32 additions & 1 deletion Sming/project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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); \
Expand Down
4 changes: 0 additions & 4 deletions samples/HttpServer_FirmwareUpload/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions samples/HttpServer_FirmwareUpload/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# Requirements file for pip
# list of Python packages used in documentation build
PyNaCl