Break tools out into their own dirs

This commit is contained in:
Reid 'arrdem' McKenzie 2021-08-29 22:13:59 -06:00
commit 9211668d9e
15 changed files with 59 additions and 66 deletions

7
tools/autoflake/BUILD Normal file
View file

@ -0,0 +1,7 @@
py_binary(
name = "autoflake",
main = "__main__.py",
deps = [
py_requirement("autoflake"),
]
)

7
tools/isort/BUILD Normal file
View file

@ -0,0 +1,7 @@
py_binary(
name = "isort",
main = "__main__.py",
deps = [
py_requirement("isort"),
]
)

View file

@ -32,35 +32,6 @@ toolchain(
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
)
py_binary(
name = "autoflake",
main = "autoflake_shim.py",
deps = [
py_requirement("autoflake"),
]
)
py_binary(
name = "isort",
main = "isort_shim.py",
deps = [
py_requirement("isort"),
]
)
py_binary(
name = "sphinx",
main = "sphinx_shim.py",
deps = [
py_requirement("click"),
py_requirement("recommonmark"),
py_requirement("sphinx"),
py_requirement("sphinxcontrib-openapi"),
py_requirement("sphinxcontrib-programoutput"),
py_requirement("livereload"),
]
)
py_pytest(
name = "test_licenses",
srcs = [
@ -75,14 +46,6 @@ py_pytest(
]
)
py_binary(
name = "unify",
main = "unify_shim.py",
deps = [
py_requirement("unify"),
]
)
py_binary(
name = "openapi",
main = "openapi_shim.py",
@ -90,32 +53,3 @@ py_binary(
py_requirement("openapi-spec-validator"),
]
)
# WARNING: YAMLLINT is GLP3'd code. Do not extend, modify or depend on this as a lib.
py_binary(
name = "yamllint",
main = "yamllint_shim.py",
deps = [
py_requirement("yamllint"),
]
)
py_binary(
name = "templater",
main = "templater.py",
deps = [
py_requirement("click"),
py_requirement("jinja2"),
py_requirement("PyYAML"),
]
)
py_binary(
name = "xfmt",
main = "xfmt.py",
deps = [
py_requirement("beautifulsoup4"),
py_requirement("click"),
py_requirement("lxml"),
]
)

View file

@ -1,76 +0,0 @@
"""A tiny template(s) tool.
Processes Jekyll/Hyde/Hugo/... style 'fontmatter' headers, applying Jinja2/Liquid templating from an
optional templates and includes directory.
"""
import os
import re
import click
import jinja2
import yaml
FONTMATTER_PATTERN = re.compile(
r"^(---\n\r?(?P<fontmatter>.*?)\n\r?---\n\r?)?(?P<content>.+)$", re.DOTALL
)
@click.command()
@click.option("-i", "--include", "include_dir", multiple=True)
@click.option("-t", "--template", "template_dir", multiple=True)
@click.option("-c", "--config", "config_file")
@click.argument("infile")
@click.argument("outfile")
def main(include_dir, template_dir, config_file, infile, outfile):
"""Apply templating.
Consume infile, processing it with templating and write the results to outfile.
"""
loaders = []
for d in include_dir:
loaders.append(jinja2.FileSystemLoader(os.path.realpath(d)))
for d in template_dir:
loaders.append(jinja2.FileSystemLoader(os.path.realpath(d)))
# Build a j2 environment using the potentially various loaders..
environment = jinja2.Environment(loader=jinja2.ChoiceLoader(loaders))
# Load a site config
if config_file:
with open(config_file) as f:
site = yaml.safe_load(f.read())
else:
site = {}
# Figure out doing the fontmatter nonsense...
with open(infile, "r") as f:
buff = f.read()
match = re.match(FONTMATTER_PATTERN, buff)
if fontmatter := match.group("fontmatter"):
fontmatter = yaml.safe_load(fontmatter)
else:
fontmatter = {}
# Render the file contents
template = environment.from_string(match.group("content"))
content = template.render(site=site, page=fontmatter)
# If there's a configured `layout:` stick the content in the layout.
if "layout" in fontmatter:
template = environment.get_template(fontmatter.get("layout"))
content = template.render(content=content, site=site, page=fontmatter)
# And dump the results
with open(outfile, "w") as f:
f.write(content)
if __name__ == "__main__":
main()

12
tools/sphinx/BUILD Normal file
View file

@ -0,0 +1,12 @@
py_binary(
name = "sphinx",
main = "__main__.py",
deps = [
py_requirement("click"),
py_requirement("recommonmark"),
py_requirement("sphinx"),
py_requirement("sphinxcontrib-openapi"),
py_requirement("sphinxcontrib-programoutput"),
py_requirement("livereload"),
]
)

7
tools/unify/BUILD Normal file
View file

@ -0,0 +1,7 @@
py_binary(
name = "unify",
main = "__main__.py",
deps = [
py_requirement("unify"),
]
)

9
tools/xfmt/BUILD Normal file
View file

@ -0,0 +1,9 @@
py_binary(
name = "xfmt",
main = "__main__.py",
deps = [
py_requirement("beautifulsoup4"),
py_requirement("click"),
py_requirement("lxml"),
]
)

8
tools/yamllint/BUILD Normal file
View file

@ -0,0 +1,8 @@
# WARNING: YAMLLINT is GLP3'd code. Do not extend, modify or depend on this as a lib.
py_binary(
name = "yamllint",
main = "__main__.py",
deps = [
py_requirement("yamllint"),
]
)