Skip to content

Commit

Permalink
Maintain a local version of pandoc to improve stability.
Browse files Browse the repository at this point in the history
Pinning Pandoc to 2.9.2.1 for now, and will upgrade to 2.11 once
it becomes a little more stable. The active developement in Pandoc
has led this framework to become too unstable.
  • Loading branch information
mpark committed Dec 18, 2020
1 parent 39463e0 commit 1284389
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
data/defaults.yaml
data/index.yaml
data/annex-f
deps/pandoc
deps/python
37 changes: 29 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,27 @@ OUTDIR ?= generated
DEFAULTS ?= $(wildcard $(SRCDIR)/defaults.yaml)
METADATA ?= $(wildcard $(SRCDIR)/metadata.yaml)

override DATADIR := $(dir $(lastword $(MAKEFILE_LIST)))data

override SRC := $(filter-out %/README.md, $(wildcard $(SRCDIR)/*.md))

override HTML := $(SRC:.md=.html)
override LATEX := $(SRC:.md=.latex)
override PDF := $(SRC:.md=.pdf)

override ROOTDIR := $(dir $(lastword $(MAKEFILE_LIST)))

override DEPSDIR := $(ROOTDIR)deps

override PANDOC_VER := $(shell cat $(DEPSDIR)/pandoc.ver)
override PANDOC_DIR := $(DEPSDIR)/pandoc/$(PANDOC_VER)
override PYTHON_DIR := $(DEPSDIR)/python

export SHELL := bash
export PATH := $(PANDOC_DIR):$(PYTHON_DIR)/bin:$(PATH)

override DEPS := $(PANDOC_DIR) $(PYTHON_DIR)

override DATADIR := $(ROOTDIR)data

override define PANDOC
$(eval override FILE := $(filter %.md, $^))
$(eval override CMD := pandoc $(FILE) -o $@ -d $(DATADIR)/defaults.yaml)
Expand All @@ -23,17 +36,17 @@ $(if $(filter %.html, $@),
$(CMD)
endef

override DEPS := $(addprefix $(DATADIR)/, defaults.yaml index.yaml annex-f)
$(eval $(and $(DEFAULTS), override DEPS += $(DEFAULTS)))
$(eval $(and $(METADATA), override DEPS += $(METADATA)))
override DATA := $(addprefix $(DATADIR)/, defaults.yaml index.yaml annex-f)
$(eval $(and $(DEFAULTS), override DATA += $(DEFAULTS)))
$(eval $(and $(METADATA), override DATA += $(METADATA)))

.PHONY: all
all: $(PDF)

ifneq ($(SRCDIR), $(OUTDIR))
.PHONY: clean
clean:
rm -rf $(OUTDIR)
rm -rf $(DEPSDIR)/pandoc $(DEPS) $(DATA) $(OUTDIR)

.PHONY: $(HTML) $(LATEX) $(PDF)
$(HTML) $(LATEX) $(PDF): $(SRCDIR)/%: $(OUTDIR)/%
Expand All @@ -46,14 +59,22 @@ update:
$(OUTDIR):
mkdir -p $@

$(PANDOC_DIR):
PANDOC_VER=$(PANDOC_VER) PANDOC_DIR=$@ $(DEPSDIR)/install-pandoc.sh

$(PYTHON_DIR): $(DEPSDIR)/requirements.txt
python3 -m venv $(PYTHON_DIR)
$@/bin/pip3 install --upgrade pip -r $<
touch $(PYTHON_DIR)

$(DATADIR)/defaults.yaml: $(DATADIR)/defaults.py
$< > $@
python3 $< > $@

$(DATADIR)/index.yaml:
curl -sSL https://wg21.link/index.yaml -o $@

$(DATADIR)/annex-f:
curl -sSL https://timsong-cpp.github.io/cppwp/annex-f -o $@

$(OUTDIR)/%.html $(OUTDIR)/%.latex $(OUTDIR)/%.pdf: $(DEPS) $(SRCDIR)/%.md | $(OUTDIR)
$(OUTDIR)/%.html $(OUTDIR)/%.latex $(OUTDIR)/%.pdf: $(SRCDIR)/%.md $(DEPS) $(DATA) | $(OUTDIR)
$(PANDOC) --bibliography $(DATADIR)/index.yaml
2 changes: 0 additions & 2 deletions data/defaults.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

import pathlib

print(
Expand Down
3 changes: 0 additions & 3 deletions data/filter/wg21.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env python3

"""
"""

import datetime
import html
import os.path
Expand Down
16 changes: 16 additions & 0 deletions deps/install-pandoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

: "${PANDOC_VER:?Set 'PANDOC_VER' to the desired version of Pandoc}"
: "${PANDOC_DIR:?Set 'PANDOC_DIR' to the directory to install Pandoc.}"

URL="https://github.com/jgm/pandoc/releases/download/${PANDOC_VER}/"
OS="$(uname -s)"
case "${OS}" in
Linux ) URL+="pandoc-${PANDOC_VER}-linux-amd64.tar.gz" ;;
Darwin) URL+="pandoc-${PANDOC_VER}-macOS.zip" ;;
* ) echo "Unspported OS: ${OS}."; exit 1 ;;
esac

mkdir -p "${PANDOC_DIR}"
curl -sSL "${URL}" | tar xz --strip-components 2 -C "${PANDOC_DIR}" -m - "pandoc-${PANDOC_VER}/bin"
chmod -R u+x "${PANDOC_DIR}"
1 change: 1 addition & 0 deletions deps/pandoc.ver
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.9.2.1
1 change: 1 addition & 0 deletions deps/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
panflute~=1.12

0 comments on commit 1284389

Please sign in to comment.