Skip to content

Commit 0aae540

Browse files
committed
fix: Encode utf-8 for generator template
1 parent a46a50c commit 0aae540

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/telemetryflow/cli/generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def load_template(template_name: str, template_dir: Path | None = None) -> str:
128128
if not template_path.exists():
129129
raise FileNotFoundError(f"Template not found: {template_path}")
130130

131-
return template_path.read_text()
131+
return template_path.read_text(encoding="utf-8")
132132

133133

134134
def render_template(template_str: str, data: TemplateData) -> str:
@@ -177,7 +177,7 @@ def write_file(path: Path, content: str, force: bool = False) -> bool:
177177
return False
178178

179179
path.parent.mkdir(parents=True, exist_ok=True)
180-
path.write_text(content)
180+
path.write_text(content, encoding="utf-8")
181181
print(f"Generated: {path}")
182182
return True
183183

src/telemetryflow/cli/generator_restapi.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def load_template(
295295
if not template_path.exists():
296296
raise FileNotFoundError(f"Template not found: {template_path}")
297297

298-
return template_path.read_text()
298+
return template_path.read_text(encoding="utf-8")
299299

300300

301301
def render_template(template_str: str, data: TemplateData) -> str:
@@ -408,7 +408,7 @@ def write_file(path: Path, content: str, force: bool = False) -> bool:
408408
return False
409409

410410
path.parent.mkdir(parents=True, exist_ok=True)
411-
path.write_text(content)
411+
path.write_text(content, encoding="utf-8")
412412
print(f"Generated: {path}")
413413
return True
414414

@@ -452,7 +452,9 @@ def generate_project(
452452
# Create __init__.py files
453453
init_file = d / "__init__.py"
454454
if not init_file.exists():
455-
init_file.write_text('"""Auto-generated by telemetryflow-restapi."""\n')
455+
init_file.write_text(
456+
'"""Auto-generated by telemetryflow-restapi."""\n', encoding="utf-8"
457+
)
456458

457459
# Generate project files using templates
458460
project_tpl_dir = template_dir / "project" if template_dir else None
@@ -749,7 +751,7 @@ def cmd_entity(args: argparse.Namespace) -> int:
749751
pyproject_path = output_dir / "pyproject.toml"
750752
module_name = ""
751753
if pyproject_path.exists():
752-
content = pyproject_path.read_text()
754+
content = pyproject_path.read_text(encoding="utf-8")
753755
for line in content.split("\n"):
754756
if line.startswith("name = "):
755757
module_name = line.split("=")[1].strip().strip('"')

0 commit comments

Comments
 (0)