Use Pipenv to manage Python environments (#1553)

* Use Pipenv to manage Python environments

* Rename PIPENV_ARGS to PIPENV_PYTHON_VERSION to avoid confusion. Also remove two unused variables
This commit is contained in:
Sean Gillespie 2018-06-21 18:01:23 -07:00 committed by GitHub
parent 78aaa29cee
commit 89b052fc6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 65 deletions

2
.gitignore vendored
View file

@ -3,6 +3,8 @@
**/.vscode/
coverage.cov
*.coverprofile
Pipfile.lock
**/dist
# Go tests run "in tree" and this folder will linger if they fail (the integration test framework cleans
# it up when they pass.)

View file

@ -109,42 +109,6 @@ 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

@ -2,10 +2,22 @@ PROJECT_NAME := Pulumi Python SDK
LANGHOST_PKG := github.com/pulumi/pulumi/sdk/python/cmd/pulumi-language-python
VERSION := $(shell ../../scripts/get-py-version)
PYENV := env
PYENVBIN := $(PYENV)/bin
ifeq ($(PYTHON),)
PYTHON := python
endif
ifeq ($(PIP),)
PIP := pip
endif
ifneq ($(PYTHON_3),)
PIPENV_PYTHON_VERSION := --three
else
PIPENV_PYTHON_VERSION := --two
endif
PYENV := ./env
PYENVSRC := $(PYENV)/src
PYENVLIB := $(PYENV)/lib
GOMETALINTERBIN := gometalinter
GOMETALINTER := ${GOMETALINTERBIN} --config=../../Gometalinter.json
@ -13,30 +25,18 @@ GOMETALINTER := ${GOMETALINTERBIN} --config=../../Gometalinter.json
include ../../build/common.mk
ensure::
$(PIP) install --user 'virtualenv>=15.2.0'
rm -rf $(PYENV) && virtualenv --python=$(PYTHON) $(PYENV)/
echo "export PYTHONPATH=$${PYTHONPATH}:$(shell pwd)/$(PYENVLIB)/python2.7/site-packages" >> $(PYENVBIN)/activate
( \
source $(PYENVBIN)/activate ; \
pip install --upgrade 'pip>=10.0.0' ; \
pip install -r requirements.txt ; \
)
$(PIP) install pipenv --user
pipenv $(PIPENV_PYTHON_VERSION) install --dev
mkdir -p $(PYENVSRC)
build::
rm -rf $(PYENVSRC) && cp -R ./lib/. $(PYENVSRC)/
sed -i.bak "s/\$${VERSION}/$(VERSION)/g" $(PYENVSRC)/setup.py && rm $(PYENVSRC)/setup.py.bak
( \
source $(PYENVBIN)/activate ; \
cd $(PYENVSRC) && python setup.py build bdist_wheel --universal ; \
)
cd $(PYENVSRC) && pipenv run python setup.py build bdist_wheel --universal
go install -ldflags "-X github.com/pulumi/pulumi/sdk/python/pkg/version.Version=${VERSION}" ${LANGHOST_PKG}
lint::
( \
source $(PYENVBIN)/activate ; \
cd $(PYENVSRC) && pylint -E ./pulumi --ignore-patterns '.*_pb2_.*.py' ; \
)
pipenv run pylint -E ./lib/pulumi --ignore-patterns '.*_pb2_.*.py'
$(GOMETALINTER) ./cmd/pulumi-language-python/... | sort ; exit $${PIPESTATUS[0]}
$(GOMETALINTER) ./pkg/... | sort ; exit $${PIPESTATUS[0]}
@ -47,4 +47,5 @@ install::
-ldflags "-X github.com/pulumi/pulumi/sdk/python/pkg/version.Version=${VERSION}" ${LANGHOST_PKG}
test_fast::
$(PYTHON) -m unittest discover -s lib/test
pipenv run pip install ./env/src
pipenv run python -m unittest discover -s lib/test

12
sdk/python/Pipfile Normal file
View file

@ -0,0 +1,12 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
protobuf = ">=3.6.0"
grpcio = ">=1.9.1"
six = ">=1.11.0"
[dev-packages]
pylint = ">=1.8.2"

View file

@ -23,8 +23,8 @@ setup(name='pulumi',
license='Apache 2.0',
packages=find_packages(),
install_requires=[
'google==2.0.1',
'grpcio==1.9.1',
'six==1.11.0'
'protobuf>=3.6.0',
'grpcio>=1.9.1',
'six>=1.11.0'
],
zip_safe=False)

View file

@ -1,5 +0,0 @@
google==2.0.1
grpcio==1.9.1
pylint==1.8.2
six==1.11.0
wheel==0.30.0