From 57a7ee37e583ca4b6db3c361d85591a84f92c861 Mon Sep 17 00:00:00 2001 From: Guy Taylor Date: Sun, 28 Oct 2018 14:41:29 +0000 Subject: [PATCH] Always run Python in the Venv context --- .travis.yml | 1 - Makefile | 40 +++++++++++++++++++---------------- src/mako/deps.mako | 14 +++--------- src/mako/{cli => }/lib/cli.py | 0 4 files changed, 25 insertions(+), 30 deletions(-) rename src/mako/{cli => }/lib/cli.py (100%) diff --git a/.travis.yml b/.travis.yml index 82eac8c553..dd6ce651f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,6 @@ after_success: env: global: - - CODECOV_TOKEN: "7373de4d-4917-4634-99e4-1c535f232c30" - PYENV_VERSION: 2.7.14 - PYENV_ROOT: $HOME/.pyenv - secure: Plj5DqAQX/4+KPM+nOAZ2sCbGIsoSrHo1YggfesQnU7paR734XO/4IayWnsNO/3q6bDi4GIcn56RUZAD3xBJJBNLia2CYIickIIYORRqLWbLdbzQaxBbD670ahtzEuUSFJTRKURPwFteAnsWYgNMNzwXOVNwLS5IUBqWTcS+N0g= diff --git a/Makefile b/Makefile index 5d71cc4881..7796411c20 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,18 @@ -.PHONY: help deps regen-apis license test-gen test clean +.PHONY: help deps regen-apis license test-gen test codecov-upload clean .SUFFIXES: VIRTUALENV_VERSION = 16.0.0 -VENV = .virtualenv/virtualenv.py +VENV_BIN = .virtualenv/virtualenv.py + VENV_DIR := .pyenv-$(shell uname) -PYTHON := $(VENV_DIR)/bin/python -PIP := $(VENV_DIR)/bin/pip -MAKO_RENDER := etc/bin/mako-render +PYTHON_BIN := $(VENV_DIR)/bin/python + +PYTHON := . $(VENV_DIR)/bin/activate; python +PIP := $(PYTHON) -m pip PYTEST := $(PYTHON) -m pytest +CODECOV := $(PYTHON) -m codecov + +MAKO_RENDER := etc/bin/mako-render API_VERSION_GEN := etc/bin/api_version_to_yaml.py TPL := $(PYTHON) $(MAKO_RENDER) MKDOCS := $(shell pwd)/$(VENV_DIR)/bin/mkdocs @@ -30,12 +35,11 @@ endif API_JSON_FILES = $(shell find etc -type f -name '*-api.json') MAKO_LIB_DIR = $(MAKO_SRC)/lib MAKO_LIB_FILES = $(shell find $(MAKO_LIB_DIR) -type f -name '*.*') -MAKO = $(TPL) --template-dir '.' -PYPATH = PYTHONPATH=$(MAKO_LIB_DIR) +MAKO = export PYTHONPATH=$(MAKO_LIB_DIR):$(PYTHONPATH); $(TPL) --template-dir '.' MAKO_STANDARD_DEPENDENCIES = $(API_SHARED_INFO) $(MAKO_LIB_FILES) $(MAKO_RENDER) help: - $(info using template engine: '$(TPL)') + $(info using template engine: '$(MAKO_RENDER)') $(info ) $(info Targets) $(info help-api - show all api targets to build individually) @@ -53,24 +57,24 @@ help: $(info test - run all tests) $(info help - print this help) -$(VENV): +$(VENV_BIN): wget -nv https://pypi.python.org/packages/source/v/virtualenv/virtualenv-$(VIRTUALENV_VERSION).tar.gz -O virtualenv-$(VIRTUALENV_VERSION).tar.gz tar -xzf virtualenv-$(VIRTUALENV_VERSION).tar.gz && mv virtualenv-$(VIRTUALENV_VERSION) ./.virtualenv && rm -f virtualenv-$(VIRTUALENV_VERSION).tar.gz chmod +x $@ -$(PYTHON): $(VENV) requirements.txt - $(VENV) -p python2.7 $(VENV_DIR) +$(PYTHON_BIN): $(VENV_BIN) requirements.txt + $(VENV_BIN) -p python2.7 $(VENV_DIR) $(PIP) install -r requirements.txt -$(MAKO_RENDER): $(PYTHON) +$(MAKO_RENDER): $(PYTHON_BIN) $(wildcard $(MAKO_LIB_DIR)/*) # Explicitly NOT depending on $(MAKO_LIB_FILES), as it's quite stable and now takes 'too long' thanks # to a URL get call to the google discovery service $(API_DEPS): $(API_DEPS_TPL) $(API_SHARED_INFO) $(MAKO_RENDER) $(TYPE_API_INFO) $(API_LIST) - $(PYPATH) $(MAKO) -io $(API_DEPS_TPL)=$@ --data-files $(API_SHARED_INFO) $(TYPE_API_INFO) $(API_LIST) + $(MAKO) -io $(API_DEPS_TPL)=$@ --data-files $(API_SHARED_INFO) $(TYPE_API_INFO) $(API_LIST) $(CLI_DEPS): $(API_DEPS_TPL) $(API_SHARED_INFO) $(MAKO_RENDER) $(TYPE_CLI_INFO) $(API_LIST) - $(PYPATH) $(MAKO) -io $(API_DEPS_TPL)=$@ --data-files $(API_SHARED_INFO) $(TYPE_CLI_INFO) $(API_LIST) + $(MAKO) -io $(API_DEPS_TPL)=$@ --data-files $(API_SHARED_INFO) $(TYPE_CLI_INFO) $(API_LIST) deps: $(API_DEPS) $(CLI_DEPS) @@ -78,17 +82,17 @@ include $(API_DEPS) include $(CLI_DEPS) LICENSE.md: $(MAKO_SRC)/LICENSE.md.mako $(API_SHARED_INFO) $(MAKO_RENDER) - $(PYPATH) $(MAKO) -io $<=$@ --data-files $(API_SHARED_INFO) + $(MAKO) -io $<=$@ --data-files $(API_SHARED_INFO) license: LICENSE.md regen-apis: | clean-all-api clean-all-cli gen-all-api gen-all-cli license -test-gen: $(PYTHON) +test-gen: $(PYTHON_BIN) $(PYTEST) --cov=src src -codecov-upload: - $(VENV_DIR)/bin/codecov +codecov-upload: $(PYTHON_BIN) + $(CODECOV) test: test-gen diff --git a/src/mako/deps.mako b/src/mako/deps.mako index 8b09e7cd54..3de571cd72 100644 --- a/src/mako/deps.mako +++ b/src/mako/deps.mako @@ -39,14 +39,6 @@ post_processor_arg = '' if mako is not UNDEFINED: post_processor_arg = '--post-process-python-module=%s' % mako.post_processor_module - - python_path = 'PYTHONPATH=$(MAKO_LIB_DIR)' - try: - root = directories.mako_src + '/' + make.id + '/lib' - lib_files = [os.path.join(root, file_name) for file_name in os.listdir(root)] - python_path += ':%s' % root - except OSError: - lib_files = list() %>\ % for an, versions in api.list.iteritems(): % if an in api.get('blacklist', list()): @@ -104,9 +96,9 @@ ${api_common}: $(RUST_SRC)/${make.id}/cmn.rs $(lastword $(MAKEFILE_LIST)) ${gen_ @ echo "// DO NOT EDIT" >> $@ @cat $< >> $@ -${gen_root_stamp}: ${' '.join(i[0] for i in sds)} ${' '.join(lib_files)} ${api_json_inputs} $(MAKO_STANDARD_DEPENDENCIES) ${depends_on_target} +${gen_root_stamp}: $(MAKO_RENDER) ${' '.join(i[0] for i in sds)} ${api_json_inputs} $(MAKO_STANDARD_DEPENDENCIES) ${depends_on_target} @echo Generating ${api_target} - @${python_path} $(MAKO) -io ${' '.join("%s=%s" % (s, d) for s, d in sds)} ${post_processor_arg} --data-files ${api_json_inputs} + $(MAKO) -io ${' '.join("%s=%s" % (s, d) for s, d in sds)} ${post_processor_arg} --data-files ${api_json_inputs} @touch $@ ${api_target}: ${api_common} @@ -149,7 +141,7 @@ gen-all${agsuffix}: ${space_join(0)} % if global_targets: ${doc_index}: docs-cli ${gen_type_cfg_path('cli')} - $(PYPATH) $(MAKO) --var DOC_ROOT=${doc_root} -io $(MAKO_SRC)/index.html.mako=$@ --data-files $(API_SHARED_INFO) $(API_LIST) + $(MAKO) --var DOC_ROOT=${doc_root} -io $(MAKO_SRC)/index.html.mako=$@ --data-files $(API_SHARED_INFO) $(API_LIST) @echo Documentation index created at '$@' docs-all: ${doc_index} docs-all-clean: diff --git a/src/mako/cli/lib/cli.py b/src/mako/lib/cli.py similarity index 100% rename from src/mako/cli/lib/cli.py rename to src/mako/lib/cli.py