Skip to content

Commit c7a0a38

Browse files
authored
Update main.py
1 parent 1602635 commit c7a0a38

File tree

1 file changed

+7
-3
lines changed
  • examples/custom_output_files

1 file changed

+7
-3
lines changed

examples/custom_output_files/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from datetime import timedelta
22
import os
33
import dataclasses
4+
from typing import Optional, Dict, Tuple, Any
45

56
import cocoindex
67
from markdown_it import MarkdownIt
78

89
_markdown_it = MarkdownIt("gfm-like")
910

1011

12+
@dataclasses.dataclass
1113
class LocalFileTarget(cocoindex.op.TargetSpec):
1214
"""Represents the custom target spec."""
1315

@@ -36,7 +38,9 @@ def describe(key: str) -> str:
3638

3739
@staticmethod
3840
def apply_setup_change(
39-
key: str, previous: LocalFileTarget | None, current: LocalFileTarget | None
41+
key: str,
42+
previous: Optional[LocalFileTarget],
43+
current: Optional[LocalFileTarget]
4044
) -> None:
4145
"""
4246
Apply setup changes to the target.
@@ -68,7 +72,7 @@ def prepare(spec: LocalFileTarget) -> LocalFileTarget:
6872

6973
@staticmethod
7074
def mutate(
71-
*all_mutations: tuple[LocalFileTarget, dict[str, LocalFileTargetValues | None]],
75+
*all_mutations: Tuple[LocalFileTarget, Dict[str, Optional[LocalFileTargetValues]]],
7276
) -> None:
7377
"""
7478
Mutate the target.
@@ -90,7 +94,7 @@ def mutate(
9094
except FileNotFoundError:
9195
pass
9296
else:
93-
with open(full_path, "w") as f:
97+
with open(full_path, "w", encoding="utf-8") as f:
9498
f.write(mutation.html)
9599

96100

0 commit comments

Comments
 (0)