chore: Setup tox+appveyor, refomat python code, prepare rust code to add branch pruning to search
This commit is contained in:
parent
865889712e
commit
2636ecbdb9
35 changed files with 1245 additions and 926 deletions
2
docs/.vscode/settings.json
vendored
2
docs/.vscode/settings.json
vendored
|
@ -8,4 +8,4 @@
|
|||
"latex",
|
||||
"plaintext"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,4 +45,4 @@ watch:
|
|||
watchexec -w src -w data -w filters -w Makefile make all
|
||||
|
||||
clean:
|
||||
-rm $(PDFS) $(IMGS)
|
||||
-rm $(PDFS) $(IMGS)
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
from panflute import *
|
||||
import tempfile
|
||||
import sys
|
||||
from jinja2 import Template, Environment, PackageLoader, select_autoescape
|
||||
import contextlib
|
||||
import io
|
||||
import hashlib
|
||||
from dateutil.parser import parse as dateparse
|
||||
from functools import partial
|
||||
import subprocess as SP
|
||||
import panflute as pf
|
||||
import os
|
||||
import csv
|
||||
import datetime
|
||||
import hashlib
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import subprocess as SP
|
||||
import sys
|
||||
import tempfile
|
||||
from functools import partial
|
||||
|
||||
import panflute as pf
|
||||
from dateutil.parser import parse as dateparse
|
||||
from jinja2 import Environment, PackageLoader, Template, select_autoescape
|
||||
from panflute import *
|
||||
|
||||
|
||||
def remove_pound(elem, doc):
|
||||
|
@ -29,10 +30,10 @@ def fix_color(elem, doc):
|
|||
|
||||
def update_date(elem, doc):
|
||||
if type(elem) == MetaMap:
|
||||
datefmt = doc.get_metadata('datefmt', "%Y-%m-%d")
|
||||
datefmt = doc.get_metadata("datefmt", "%Y-%m-%d")
|
||||
today = datetime.date.today().strftime(datefmt)
|
||||
date = dateparse(doc.get_metadata('date', today)).date()
|
||||
elem['date'] = MetaInlines(Str(date.strftime(datefmt)))
|
||||
date = dateparse(doc.get_metadata("date", today)).date()
|
||||
elem["date"] = MetaInlines(Str(date.strftime(datefmt)))
|
||||
return elem
|
||||
|
||||
|
||||
|
@ -42,8 +43,7 @@ def csv_table(elem, doc):
|
|||
ext = os.path.splitext(elem.url)[1][1:]
|
||||
if ext == "csv":
|
||||
caption = elem.content
|
||||
has_header = elem.attributes.get(
|
||||
'has-header', "false").lower() == "true"
|
||||
has_header = elem.attributes.get("has-header", "false").lower() == "true"
|
||||
with open(elem.url) as f:
|
||||
reader = csv.reader(f)
|
||||
body = []
|
||||
|
@ -62,7 +62,12 @@ def code_refs(elem, doc):
|
|||
label = label.text
|
||||
filename = re.findall(r"^\[@lst:(.*)\]$", label) or [None]
|
||||
if filename[0] in doc.inc_files:
|
||||
return [RawInline("\\hyperref[{}]{{{}}}".format(filename[0], filename[0]), format="tex")]
|
||||
return [
|
||||
RawInline(
|
||||
"\\hyperref[{}]{{{}}}".format(filename[0], filename[0]),
|
||||
format="tex",
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def include_code(elem, doc):
|
||||
|
@ -71,9 +76,8 @@ def include_code(elem, doc):
|
|||
filepath = elem.attributes.pop("include")
|
||||
filename = os.path.split(filepath)[-1]
|
||||
try:
|
||||
elem.text += elem.text + \
|
||||
open(filepath, encoding="utf-8").read()
|
||||
elem.attributes['caption'] = filename
|
||||
elem.text += elem.text + open(filepath, encoding="utf-8").read()
|
||||
elem.attributes["caption"] = filename
|
||||
doc.inc_files.append(filename)
|
||||
except Exception as e:
|
||||
elem.text += "Error: {}".format(e)
|
||||
|
@ -92,28 +96,26 @@ def jinja_py_filt(doc, file):
|
|||
env = {}
|
||||
code = open(file, encoding="utf-8").read()
|
||||
exec(code, env)
|
||||
return env['main'](doc)
|
||||
return env["main"](doc)
|
||||
|
||||
|
||||
def prepare(doc):
|
||||
doc.inc_files = []
|
||||
doc.env = Environment()
|
||||
doc.pyenv = {}
|
||||
filters = {'py': partial(jinja_py_filt, doc)}
|
||||
filters = {"py": partial(jinja_py_filt, doc)}
|
||||
doc.env.filters.update(filters)
|
||||
|
||||
|
||||
def process_templates(elem, doc):
|
||||
if type(elem) == CodeBlock:
|
||||
if elem.classes == ["@"]:
|
||||
args = {'meta': doc.get_metadata()}
|
||||
args = {"meta": doc.get_metadata()}
|
||||
return convert_text(doc.env.from_string(elem.text).render(args))
|
||||
|
||||
|
||||
def yaml_filt(elem, doc):
|
||||
tags = {
|
||||
'eval': py_eval,
|
||||
}
|
||||
tags = {"eval": py_eval}
|
||||
return yaml_filter(elem, doc, tags=tags, strict_yaml=True)
|
||||
|
||||
|
||||
|
@ -138,8 +140,16 @@ def checkboxes(elem, doc):
|
|||
|
||||
|
||||
def main(doc=None):
|
||||
f = [process_templates, update_date, csv_table, include_code,
|
||||
fix_color, code_refs, yaml_filt, checkboxes]
|
||||
f = [
|
||||
process_templates,
|
||||
update_date,
|
||||
csv_table,
|
||||
include_code,
|
||||
fix_color,
|
||||
code_refs,
|
||||
yaml_filt,
|
||||
checkboxes,
|
||||
]
|
||||
return run_filters(f, prepare=prepare, doc=doc)
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import sys
|
||||
import pylab as PL
|
||||
import numpy as np
|
||||
from scipy.spatial.ckdtree import cKDTree
|
||||
import heapq
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
import pylab as PL
|
||||
from scipy.spatial.ckdtree import cKDTree
|
||||
|
||||
exit()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue