feat(mako): can now use custom libraries in pycode

Namespaces can exclusively be used during rendering, which is fine if
you remind yourself of the newline rules.
However, I also need some utiltiies that convert input data. These
are now within their own libraries, which can be used from python blocks
like the ordinary python functions they are.

Quite neat.
In future, most of the functionality will be in separate namespaces,
the top-level will just assemble the main library file, usnig the
provided %defs. That way, the main file is kept clean.
This commit is contained in:
Sebastian Thiel
2015-03-02 11:52:15 +01:00
parent be938255bd
commit 2298601165
7 changed files with 33 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
.PHONY: json-to-xml clean help api-deps
.SUFFIXES:
include Makefile.helpers
@@ -9,10 +10,13 @@ PIP := $(VENV_DIR)/bin/pip
MAKO_RENDER := ./etc/bin/mako-render
TPL := $(PYTHON) $(MAKO_RENDER)
API_DEPS_TPL = src/mako/deps.mako
MAKO_SRC = src/mako
API_DEPS_TPL = $(MAKO_SRC)/deps.mako
API_DEPS = .api.deps
API_SHARED_INFO = ./etc/api/shared.yaml
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' -or -name '*.py')
help:
$(info using template engine: '$(TPL)')
@@ -28,8 +32,8 @@ $(PYTHON):
$(MAKO_RENDER): $(PYTHON)
$(API_DEPS): $(API_SHARED_INFO) $(API_DEPS_TPL) $(MAKO_RENDER)
$(TPL) -io $(API_DEPS_TPL) --data-files $(API_SHARED_INFO) > $@
$(API_DEPS): $(API_SHARED_INFO) $(API_DEPS_TPL) $(MAKO_LIB_FILES) $(MAKO_RENDER)
PYTHONPATH=$(MAKO_LIB_DIR) $(TPL) --template-dir '.' -io $(API_DEPS_TPL) --data-files $(API_SHARED_INFO) > $@
api-deps: $(API_DEPS)