Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.
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: 4 additions & 1 deletion src/betterproto2_compiler/plugin/compiler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path
import subprocess
import sys
from importlib import metadata

from .module_validation import ModuleValidator

Expand All @@ -24,6 +25,8 @@
def outputfile_compiler(output_file: OutputTemplate) -> str:
templates_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "templates"))

version = metadata.version("betterproto2_compiler")

env = jinja2.Environment(
trim_blocks=True,
lstrip_blocks=True,
Expand All @@ -35,7 +38,7 @@ def outputfile_compiler(output_file: OutputTemplate) -> str:
header_template = env.get_template("header.py.j2")

code = body_template.render(output_file=output_file)
code = header_template.render(output_file=output_file) + "\n" + code
code = header_template.render(output_file=output_file, version=version) + "\n" + code

# Sort imports, delete unused ones
code = subprocess.check_output(
Expand Down
2 changes: 2 additions & 0 deletions src/betterproto2_compiler/templates/header.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ if TYPE_CHECKING:
import grpclib.server
from betterproto2.grpc.grpclib_client import MetadataLike
from grpclib.metadata import Deadline

betterproto2.check_compiler_version("{{ version }}")
Loading