remove pip-accel and make sure commands work if you're in a venv

remove pip-accel - it's not been updated in two years, and pins our
version of pip to a version that is several breaking changes old.

make sure commands work if you're already in a venv - mostly by
checking for presence of $VIRTUAL_ENV, and ensuring we use the correct
pip to install packages. Also clean up the commands a bit.
This commit is contained in:
Leo Hemsted
2018-10-04 15:52:51 +01:00
parent 640f00b0e8
commit bfc4343b0e
3 changed files with 18 additions and 22 deletions

View File

@@ -2,7 +2,6 @@
SHELL := /bin/bash SHELL := /bin/bash
DATE = $(shell date +%Y-%m-%d:%H:%M:%S) DATE = $(shell date +%Y-%m-%d:%H:%M:%S)
PIP_ACCEL_CACHE ?= ${CURDIR}/cache/pip-accel
APP_VERSION_FILE = app/version.py APP_VERSION_FILE = app/version.py
GIT_BRANCH ?= $(shell git symbolic-ref --short HEAD 2> /dev/null || echo "detached") GIT_BRANCH ?= $(shell git symbolic-ref --short HEAD 2> /dev/null || echo "detached")
@@ -34,11 +33,19 @@ help:
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: venv .PHONY: venv
# if there's a virtualenv already active, we don't want to do anything
ifeq ($(VIRTUAL_ENV),)
venv: venv/bin/activate ## Create virtualenv if it does not exist venv: venv/bin/activate ## Create virtualenv if it does not exist
venv/bin/activate: venv/bin/activate:
test -d venv || virtualenv venv -p python3 test -d venv || virtualenv venv -p python3
. venv/bin/activate && pip install pip-accel
VENV_BIN_DIR = $(shell . venv/bin/activate && echo $$VIRTUAL_ENV/bin)
else
venv:
VENV_BIN_DIR = $(VIRTUAL_ENV)/bin
endif
.PHONY: check-env-vars .PHONY: check-env-vars
check-env-vars: ## Check mandatory environment variables check-env-vars: ## Check mandatory environment variables
@@ -65,10 +72,9 @@ production: ## Set environment to production
@true @true
.PHONY: dependencies .PHONY: dependencies
dependencies: venv ## Install build dependencies dependencies: venv
mkdir -p ${PIP_ACCEL_CACHE} $(call install-pycurl, $(VENV_BIN_DIR)/pip)
. venv/bin/activate && make install-pycurl $(VENV_BIN_DIR)/pip install -r requirements_for_test.txt
. venv/bin/activate && PIP_ACCEL_CACHE=${PIP_ACCEL_CACHE} pip-accel install -r requirements_for_test.txt
.PHONY: generate-version-file .PHONY: generate-version-file
generate-version-file: ## Generates the app version file generate-version-file: ## Generates the app version file
@@ -76,7 +82,7 @@ generate-version-file: ## Generates the app version file
.PHONY: build .PHONY: build
build: dependencies generate-version-file ## Build project build: dependencies generate-version-file ## Build project
. venv/bin/activate && PIP_ACCEL_CACHE=${PIP_ACCEL_CACHE} pip-accel install -r requirements.txt
.PHONY: build-paas-artifact .PHONY: build-paas-artifact
build-paas-artifact: ## Build the deploy artifact for PaaS build-paas-artifact: ## Build the deploy artifact for PaaS
@@ -109,7 +115,7 @@ freeze-requirements:
define install-pycurl define install-pycurl
# install pycurl separately to avoid flags disabling wheels for other packages # install pycurl separately to avoid flags disabling wheels for other packages
PYCURL_SSL_LIBRARY=openssl ${1} install pycurl --global-option="build_ext" --global-option="-I/usr/local/opt/openssl/include" PYCURL_SSL_LIBRARY=openssl ${1} install pycurl==7.43.0.2 --global-option="build_ext" --global-option="-I/usr/local/opt/openssl/include"
endef endef
.PHONY: install-pycurl .PHONY: install-pycurl
@@ -125,11 +131,10 @@ test-requirements:
.PHONY: coverage .PHONY: coverage
coverage: venv ## Create coverage report coverage: venv ## Create coverage report
. venv/bin/activate && coveralls coveralls
.PHONY: prepare-docker-build-image .PHONY: prepare-docker-build-image
prepare-docker-build-image: ## Prepare the Docker builder image prepare-docker-build-image: ## Prepare the Docker builder image
mkdir -p ${PIP_ACCEL_CACHE}
make -C docker build make -C docker build
.PHONY: build-with-docker .PHONY: build-with-docker
@@ -137,7 +142,6 @@ build-with-docker: prepare-docker-build-image ## Build inside a Docker container
@docker run -i${DOCKER_TTY} --rm \ @docker run -i${DOCKER_TTY} --rm \
--name "${DOCKER_CONTAINER_PREFIX}-build" \ --name "${DOCKER_CONTAINER_PREFIX}-build" \
-v "`pwd`:/var/project" \ -v "`pwd`:/var/project" \
-v "${PIP_ACCEL_CACHE}:/var/project/cache/pip-accel" \
-e UID=$(shell id -u) \ -e UID=$(shell id -u) \
-e GID=$(shell id -g) \ -e GID=$(shell id -g) \
-e GIT_COMMIT=${GIT_COMMIT} \ -e GIT_COMMIT=${GIT_COMMIT} \

View File

@@ -28,3 +28,5 @@ awscli-cwlogs>=1.4,<1.5
botocore<1.11.0 botocore<1.11.0
git+https://github.com/alphagov/notifications-utils.git@30.4.0#egg=notifications-utils==30.4.0 git+https://github.com/alphagov/notifications-utils.git@30.4.0#egg=notifications-utils==30.4.0
# if you want to update pycurl please do so in makefile

View File

@@ -20,17 +20,7 @@ function display_result {
fi fi
} }
if [ ! $VIRTUAL_ENV ]; then make build
virtualenv -p python3 ./venv
. ./venv/bin/activate
fi
# we need the version file to exist otherwise the app will blow up
make generate-version-file
make install-pycurl
# Install Python development dependencies
pip3 install -r requirements_for_test.txt
# Create Postgres databases # Create Postgres databases
createdb notification_api createdb notification_api