-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscaffold.py
More file actions
84 lines (52 loc) · 2.09 KB
/
scaffold.py
File metadata and controls
84 lines (52 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
from pathlib import Path
def scaffold_day(day: int):
base_path = Path("./puzzles") / f"day_{day:02d}"
if base_path.is_dir():
raise ValueError("Day has been set up already.")
os.makedirs(base_path / "tests")
(base_path / "solution_part_1.py").write_text(f"""
from puzzles.day_{day:02d}.load_inputs import input_reader, InputType
def calculate_solution(input_values: InputType) -> int:
raise NotImplemented
if __name__ == "__main__":
puzzle_input = input_reader.from_file("./input.txt")
print(calculate_solution(puzzle_input))
""".lstrip("\n"))
(base_path / "solution_part_2.py").write_text(f"""
from puzzles.day_{day:02d}.load_inputs import input_reader, InputType
def calculate_solution(input_values: InputType) -> int:
raise NotImplemented
if __name__ == "__main__":
puzzle_input = input_reader.from_file("./input.txt")
print(calculate_solution(puzzle_input))
""".lstrip("\n"))
(base_path / "input.txt").touch()
(base_path / "load_inputs.py").write_text("""
from utils.input_deformatter import InputDeformatter
InputType = None
input_reader = InputDeformatter[InputType]()
""".lstrip("\n"))
(base_path / "tests" / "test_solution_part_1.py").write_text(f"""
from puzzles.day_{day:02d}.load_inputs import input_reader
from puzzles.day_{day:02d}.solution_part_1 import calculate_solution
def test_example():
raw_test_input = \"\"\"
\"\"\"
test_input = input_reader.load(raw_test_input)
solution = calculate_solution(test_input)
assert solution == NotImplemented
""".lstrip("\n"))
(base_path / "tests" / "test_solution_part_2.py").write_text(f"""
from puzzles.day_{day:02d}.load_inputs import input_reader
from puzzles.day_{day:02d}.solution_part_2 import calculate_solution
def test_example():
raw_test_input = \"\"\"
\"\"\"
test_input = input_reader.load(raw_test_input)
solution = calculate_solution(test_input)
assert solution == NotImplemented
""".lstrip("\n"))
if __name__ == '__main__':
days_already_made = os.listdir("./puzzles")
scaffold_day(len(days_already_made) + 1)