diff --git a/common/tools/cointool.py b/common/tools/cointool.py index 2f4a770eb..b35bf9e59 100755 --- a/common/tools/cointool.py +++ b/common/tools/cointool.py @@ -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, ) 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 99c9680f4..d942d3a15 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"] def get_en_strings(data: dict) -> dict[str, str]: 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",