From 89b052fc6d06902c907c751fbcd3603137a11155 Mon Sep 17 00:00:00 2001 From: Sean Gillespie Date: Thu, 21 Jun 2018 18:01:23 -0700 Subject: [PATCH] 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 --- .gitignore | 2 ++ build/common.mk | 36 ------------------------------- sdk/python/Makefile | 43 +++++++++++++++++++------------------ sdk/python/Pipfile | 12 +++++++++++ sdk/python/lib/setup.py | 6 +++--- sdk/python/requirements.txt | 5 ----- 6 files changed, 39 insertions(+), 65 deletions(-) create mode 100644 sdk/python/Pipfile delete mode 100644 sdk/python/requirements.txt diff --git a/.gitignore b/.gitignore index 5a90027d8..5aa238c17 100644 --- a/.gitignore +++ b/.gitignore @@ -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.) diff --git a/build/common.mk b/build/common.mk index 594afaa44..4a7b90dd1 100644 --- a/build/common.mk +++ b/build/common.mk @@ -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),) diff --git a/sdk/python/Makefile b/sdk/python/Makefile index 1bd02a76c..cd2db83be 100644 --- a/sdk/python/Makefile +++ b/sdk/python/Makefile @@ -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 diff --git a/sdk/python/Pipfile b/sdk/python/Pipfile new file mode 100644 index 000000000..40425bbd7 --- /dev/null +++ b/sdk/python/Pipfile @@ -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" diff --git a/sdk/python/lib/setup.py b/sdk/python/lib/setup.py index 730fdd0fe..4d4bed8a8 100644 --- a/sdk/python/lib/setup.py +++ b/sdk/python/lib/setup.py @@ -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) diff --git a/sdk/python/requirements.txt b/sdk/python/requirements.txt deleted file mode 100644 index 0b5f9c5fb..000000000 --- a/sdk/python/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -google==2.0.1 -grpcio==1.9.1 -pylint==1.8.2 -six==1.11.0 -wheel==0.30.0