feat(common): provide some useful paths for the mako templates

pull/3491/head
matejcik 4 months ago
parent f4ee8dcac9
commit c261dc27ba

@ -11,6 +11,7 @@ import re
import sys
from collections import defaultdict
from hashlib import sha256
from pathlib import Path
from typing import Any, Callable, Iterator, TextIO, cast
import click
@ -25,6 +26,9 @@ DEFINITIONS_LATEST_URL = (
"https://raw.githubusercontent.com/trezor/definitions/main/definitions-latest.json"
)
HERE = Path(__file__).parent.resolve()
ROOT = HERE.parent.parent
try:
import termcolor
except ImportError:
@ -148,10 +152,13 @@ def render_file(
eth_defs_date = datetime.datetime.fromisoformat(
DEFINITIONS_TIMESTAMP_PATH.read_text().strip()
)
this_file = Path(src)
result = template.render(
support_info=support_info,
supported_on=make_support_filter(support_info),
ethereum_defs_timestamp=int(eth_defs_date.timestamp()),
THIS_FILE=this_file,
ROOT=ROOT,
**coins,
**MAKO_FILTERS,
)

@ -1,4 +1,4 @@
// generated from librust_qstr.h.mako
// generated from ${THIS_FILE.name}
// (by running `make templates` in `core`)
// do not edit manually!
#pragma GCC diagnostic ignored "-Wunused-value"
@ -11,9 +11,7 @@ import sys
from pathlib import Path
from typing import Union, Set
THIS = Path(local.filename).resolve()
HERE = THIS.parent
RUST_SRC = HERE / "src"
RUST_SRC = THIS_FILE.parent / "src"
def find_unique_patterns_in_dir(directory: Union[str, Path], pattern: str) -> Set[str]:
command = f"grep -ro '{pattern}' {directory}"

@ -1,14 +1,10 @@
# generated from trezortranslate_keys.pyi.mako
# generated from ${THIS_FILE.name}
# (by running `make templates` in `core`)
# do not edit manually!
<%
import json
from pathlib import Path
THIS = Path(local.filename).resolve()
CORE_DIR = THIS.parent.parent
en_file = CORE_DIR / "embed" / "rust" / "src" / "translations" / "en.json"
en_file = ROOT / "core" / "translations" / "en.json"
en_data = json.loads(en_file.read_text())["translations"]
def get_en_strings(data: dict) -> dict[str, str]:

@ -1,15 +1,13 @@
# generated from all_modules.py.mako
# generated from ${THIS_FILE.name}
# (by running `make templates` in `core`)
# do not edit manually!
# flake8: noqa
# fmt: off
# isort:skip_file
<%
from pathlib import Path
from itertools import chain
THIS = Path(local.filename).resolve()
SRCDIR = THIS.parent
SRCDIR = THIS_FILE.parent
PATTERNS = (
"*.py",

Loading…
Cancel
Save