From 9c72c7c99d6d5d4b194ceded4e25bf73479e8ae1 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 19 Jan 2024 12:39:34 +0100 Subject: [PATCH] feat(common): provide some useful paths for the mako templates --- common/tools/cointool.py | 6 ++++++ core/embed/rust/librust_qstr.h.mako | 6 ++---- core/mocks/trezortranslate_keys.pyi.mako | 8 ++------ core/src/all_modules.py.mako | 6 ++---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/common/tools/cointool.py b/common/tools/cointool.py index b184a57cb..41aaeb5e3 100755 --- a/common/tools/cointool.py +++ b/common/tools/cointool.py @@ -25,6 +25,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 +151,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, ) diff --git a/core/embed/rust/librust_qstr.h.mako b/core/embed/rust/librust_qstr.h.mako index af14239d5..859869eb7 100644 --- a/core/embed/rust/librust_qstr.h.mako +++ b/core/embed/rust/librust_qstr.h.mako @@ -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}" diff --git a/core/mocks/trezortranslate_keys.pyi.mako b/core/mocks/trezortranslate_keys.pyi.mako index 96e042b9e..722eb3bc5 100644 --- a/core/mocks/trezortranslate_keys.pyi.mako +++ b/core/mocks/trezortranslate_keys.pyi.mako @@ -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"] %>\ diff --git a/core/src/all_modules.py.mako b/core/src/all_modules.py.mako index c1ef0a14b..b37fcd9bb 100644 --- a/core/src/all_modules.py.mako +++ b/core/src/all_modules.py.mako @@ -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",