Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

programatically grab version for docs and live mode #116

Merged
merged 1 commit into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ Teletype is a dynamic, musical event triggering platform.
— [PDF scene recall sheet](https://monome.org/docs/modular/teletype/TT_scene_RECALL_sheet.pdf)
— [Default scenes](http://monome.org/docs/modular/teletype/scenes-1.0/)

* Current version: 2.1.0
* Current version: _VERSION_
— [Firmware update procedure](https://monome.org/docs/modular/update/)



2 changes: 1 addition & 1 deletion module/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ include $(MAKEFILE_PATH)

# Add the git commit id to a file for use when printing out the version
../module/gitversion.c: ../.git/HEAD ../.git/index
echo "const char *git_version = \"$(shell git describe --always --dirty | tr '[a-z]' '[A-Z]')\";" > $@
echo "const char *git_version = \"$(shell cut -d '-' -f 1 <<< $(shell git describe --tags | cut -c 2-)) $(shell git describe --always --dirty | tr '[a-z]' '[A-Z]')\";" > $@
2 changes: 1 addition & 1 deletion module/live_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ uint8_t screen_refresh_live() {
output.has_value = false;
}
else if (show_welcome_message) {
strcpy(s, "TELETYPE: ");
strcpy(s, "TELETYPE ");
strncat(s, git_version, 35 - strlen(s));
show_welcome_message = false;
}
Expand Down
7 changes: 5 additions & 2 deletions utils/cheatsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pypandoc
import pytoml as toml

from common import validate_toml
from common import validate_toml, get_tt_version

if (sys.version_info.major, sys.version_info.minor) < (3, 6):
raise Exception("need Python 3.6 or later")
Expand All @@ -19,6 +19,9 @@
DOCS_DIR = ROOT_DIR / "docs"
OP_DOCS_DIR = DOCS_DIR / "ops"
FONTS_DIR = ROOT_DIR / "utils" / "fonts"
_VERSION_ = get_tt_version()
_VERSION_STR_ = "Teletype " + \
_VERSION_["tag"] + " " + _VERSION_["hash"] + " Cheatsheet"


# We want to run inject_latex in parallel as it's quite slow, and we must run
Expand Down Expand Up @@ -78,7 +81,7 @@ def cheatsheet_tex():
print(f"Using ops docs directory: {OP_DOCS_DIR}")
print()

output = ""
output = _VERSION_STR_ + "\n\n"
for (section, title, new_page) in OPS_SECTIONS:
toml_file = Path(OP_DOCS_DIR, section + ".toml")
if toml_file.exists() and toml_file.is_file():
Expand Down
10 changes: 10 additions & 0 deletions utils/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from os import path
import re
import subprocess

_THIS_FILE = path.realpath(__file__)
_THIS_DIR = path.dirname(_THIS_FILE)
Expand Down Expand Up @@ -105,3 +106,12 @@ def validate_toml(ops):
for k in keys - {"prototype", "prototype_set", "aliases",
"short", "description"}:
print(f" - WARNING: {name} - unknown entry - {k}")


def get_tt_version():
tag = subprocess.check_output(["git", "describe", "--tags"]) \
.decode("utf-8").split("-")[0]
hash = subprocess.check_output(["git", "describe",
"--always", "--dirty"]) \
.decode("utf-8")[:-1].upper()
return {'tag': tag, 'hash': hash}
12 changes: 9 additions & 3 deletions utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import jinja2
import pypandoc
import pytoml as toml
import subprocess

from common import list_ops, list_mods, validate_toml
from common import list_ops, list_mods, validate_toml, get_tt_version

if (sys.version_info.major, sys.version_info.minor) < (3, 6):
raise Exception("need Python 3.6 or later")
Expand All @@ -18,6 +19,8 @@
DOCS_DIR = ROOT_DIR / "docs"
OP_DOCS_DIR = DOCS_DIR / "ops"
FONTS_DIR = ROOT_DIR / "utils" / "fonts"
_VERSION_ = get_tt_version()
_VERSION_STR_ = "Teletype " + _VERSION_["tag"] + " " + _VERSION_["hash"] + " Documentation"

env = jinja2.Environment(
autoescape=False,
Expand Down Expand Up @@ -71,7 +74,8 @@ def common_md():
op_extended_template = env.get_template("op_extended.jinja2.md")

output = ""
output += Path(DOCS_DIR / "intro.md").read_text() + "\n\n"
output += Path(DOCS_DIR / "intro.md").read_text() \
.replace("VERSION", _VERSION_["tag"][1:]) + "\n\n"
output += Path(DOCS_DIR / "whats_new.md").read_text() + "\n\n"
output += Path(DOCS_DIR / "quickstart.md").read_text() + "\n\n"
output += Path(DOCS_DIR / "keys.md").read_text() + "\n\n"
Expand Down Expand Up @@ -149,6 +153,7 @@ def main():
if ext == ".md":
p.write_text(output)
elif ext == ".html":
output = "# " + _VERSION_STR_ + "\n\n" + output
pypandoc.convert_text(
output,
format=input_format,
Expand All @@ -162,7 +167,8 @@ def main():
"--template=" + str(TEMPLATE_DIR / "template.html5")])
elif ext == ".pdf" or ext == ".tex":
latex_preamble = env.get_template("latex_preamble.jinja2.md")
latex = latex_preamble.render(fonts_dir=FONTS_DIR) + "\n\n"
latex = latex_preamble \
.render(title=_VERSION_STR_, fonts_dir=FONTS_DIR) + "\n\n"
latex += output
pypandoc.convert_text(
latex,
Expand Down
2 changes: 1 addition & 1 deletion utils/templates/latex_preamble.jinja2.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Teletype Documentation
title: {{title}}
documentclass: report
geometry: margin=1in
links-as-notes: true
Expand Down