Prefer Python2 tools; fail-fast when wrong

This change includes a few things:

1) Prefer python2 and pip2 when on the PATH, over the undecorated
   names python and pip.  This is the standard convention for package
   managers like Pip, etc., to support Python2 and Python3 side-by-side.

2) Fail-fast if neither can be found on the PATH.

3) Check the reported version number for python, pip, and pylint, and
   fail-fast if it doesn't report back 2.7, just to safeguard against
   undecorated binaries with unsupported versions.

Also, we had not listed wheel as a dependency in the requirements.txt
file.  This needs to be there to support building bdist_wheels.  Fixed.
This commit is contained in:
joeduffy 2018-03-06 15:29:52 -08:00
parent f59931d242
commit 440ffb27e5
4 changed files with 61 additions and 9 deletions

View file

@ -109,6 +109,42 @@ PULUMI_NODE_MODULES := $(PULUMI_ROOT)/node_modules
# ensure that `default` is the target that is run when no arguments are passed to make
default::
# Ensure the requisite tools are on the PATH.
# - Prefer Python2 over Python.
PYTHON := $(shell command -v python2 2>/dev/null)
ifeq ($(PYTHON),)
PYTHON = $(shell command -v python 2>/dev/null)
endif
ifeq ($(PYTHON),)
ensure::
$(error "missing python 2.7 (`python2` or `python`) from your $$PATH; \
please see https://github.com/pulumi/home/wiki/Package-Management-Prerequisites")
else
PYTHON_VERSION := $(shell command $(PYTHON) --version 2>&1)
ifeq (,$(findstring 2.7,$(PYTHON_VERSION)))
ensure::
$(error "$(PYTHON) did not report a 2.7 version number ($(PYTHON_VERSION)); \
please see https://github.com/pulumi/home/wiki/Package-Management-Prerequisites")
endif
endif
# - Prefer Pip2 over Pip.
PIP := $(shell command -v pip2 2>/dev/null)
ifeq ($(PIP),)
PIP = $(shell command -v pip 2>/dev/null)
endif
ifeq ($(PIP),)
ensure::
$(error "missing pip 2.7 (`pip2` or `pip`) from your $$PATH; \
please see https://github.com/pulumi/home/wiki/Package-Management-Prerequisites")
else
PIP_VERSION := $(shell command $(PIP) --version 2>&1)
ifeq (,$(findstring python 2.7,$(PIP_VERSION)))
ensure::
$(error "$(PIP) did not report a 2.7 version number ($(PIP_VERSION)); \
please see https://github.com/pulumi/home/wiki/Package-Management-Prerequisites")
endif
endif
# If there are sub projects, our default, all, and ensure targets will
# recurse into them.
ifneq ($(SUB_PROJECTS),)

View file

@ -5,7 +5,7 @@ nvm install v6.10.2
# they would be set in the outer shell as well, so do as much logic as
# we can in a subshell.
(
set -o nounset -o errexit -o pipefail
set -o nounset -o errexit -o pipefail -x
[ -e "$(go env GOPATH)/bin" ] || mkdir -p "$(go env GOPATH)/bin"
YARN_VERSION="1.3.2"
@ -58,9 +58,6 @@ nvm install v6.10.2
pip install --user "wheel==${WHEEL_VERSION}" "twine==${TWINE_VERSION}"
)
# If the sub shell failed, bail out now.
[ "$?" -eq 0 ] || exit 1
# By default some tools are not on the PATH, let's fix that
# On OSX, the user folder that `pip` installs tools to is not on the
@ -72,3 +69,6 @@ fi
# Add yarn to the $PATH
export PATH=$HOME/.yarn/bin:$PATH
# If the sub shell failed, bail out now.
[ "$?" -eq 0 ] || exit 1

View file

@ -8,22 +8,37 @@ GOMETALINTER := ${GOMETALINTERBIN} --config=../../Gometalinter.json
include ../../build/common.mk
ensure::
pip install --user -r requirements.txt
$(PIP) install --user --upgrade -r requirements.txt
# Ensure Pylint is present and has the right version.
PYLINT := $(shell command -v pylint 2>/dev/null)
ifeq ($(PYLINT),)
ensure::
$(error "missing pylint from your $$PATH; \
please see https://github.com/pulumi/home/wiki/Package-Management-Prerequisites")
else
PYLINT_VERSION := $(shell command $(PYLINT) --version 2>&1)
ifeq (,$(findstring Python 2.7,$(PYLINT_VERSION)))
ensure::
$(error "$(PYLINT) did not report a 2.7 version number ($(PYLINT_VERSION)); \
please see https://github.com/pulumi/home/wiki/Package-Management-Prerequisites")
endif
endif
lint::
pylint -E lib/pulumi/ --ignore-patterns '.*_pb2_.*.py'
$(PYLINT) -E lib/pulumi/ --ignore-patterns '.*_pb2_.*.py'
$(GOMETALINTER) ./cmd/pulumi-language-python/... | sort ; exit $${PIPESTATUS[0]}
$(GOMETALINTER) ./pkg/... | sort ; exit $${PIPESTATUS[0]}
build::
cd ./lib/ && python setup.py clean --all 2>/dev/null
cd ./lib/ && $(PYTHON) setup.py clean --all 2>/dev/null
rm -rf ./bin/ && cp -R ./lib/. ./bin/
sed -i.bak "s/\$${VERSION}/$(VERSION)/g" ./bin/setup.py && rm ./bin/setup.py.bak
cd ./bin/ && python setup.py build bdist_wheel --universal
cd ./bin/ && $(PYTHON) setup.py build bdist_wheel --universal
go install -ldflags "-X github.com/pulumi/pulumi/sdk/python/pkg/version.Version=${VERSION}" ${LANGHOST_PKG}
install::
cd ./bin/ && python setup.py install --user --force --prefix=
cd ./bin/ && $(PYTHON) setup.py install --user --force --prefix=
cp ./cmd/pulumi-language-python-exec "$(PULUMI_BIN)"
GOBIN=$(PULUMI_BIN) go install \
-ldflags "-X github.com/pulumi/pulumi/sdk/python/pkg/version.Version=${VERSION}" ${LANGHOST_PKG}

View file

@ -2,3 +2,4 @@ google==2.0.1
grpcio==1.9.1
pylint==1.8.2
six==1.11.0
wheel==0.30.0