-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_year_structure.py
More file actions
127 lines (102 loc) · 3.21 KB
/
create_year_structure.py
File metadata and controls
127 lines (102 loc) · 3.21 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import os
import argparse
import json
def create_class(day: int) -> None:
with open(f'Day{day}.py', 'w') as day_file:
day_file.write(f"""
# add parent directory to path for imports
import sys
sys.path.insert(0,'..')
class Day{day}:
def __init__(self,file_name:str) -> None:
with open(file_name, 'r') as input_file:
pass
def part1(self) -> int:
return 0
def part2(self) -> int:
return 0
""")
def create_tests(day: int, year: int) -> None:
os.chdir('..')
os.makedirs(f'tests')
os.chdir('tests')
with open(f'__init__.py','w') as _:
pass
with open(f'test_day{day}.py','w') as test_file:
test_file.write(f"""
import pytest
from Day{day} import Day{day}
test_data1=[('{year}/Day{day}/tests/input.txt',0)]
#test_data2=[('{year}/Day{day}/tests/input.txt',0)]
@pytest.mark.parametrize('file_name,result',test_data1)
def test_part1(file_name,result):
d = Day{day}(file_name)
assert(d.part1() == result)
'''
@pytest.mark.parametrize('file_name,result',test_data2)
def test_part2(file_name,result):
d = Day{day}(file_name)
assert(d.part2() == result)
'''
""")
with open(f'input.txt','w') as _:
pass
def create_vscode(day: int) -> None:
# create .vscode launch.json file (for debugging)
configs: list[dict] = list()
config: dict = dict()
config['name'] = f'day{day}'
config['type'] = 'python'
config['request'] = 'launch'
config['program'] = f'day_{day}.py'
config['console'] = 'integratedTerminal'
config['justMyCode'] = True
configs.append(config)
launch_json: dict = dict()
launch_json['version'] = '0.2.0'
launch_json['configurations'] = configs
os.makedirs('.vscode')
os.chdir('.vscode')
with open('launch.json', 'w') as json_file:
json.dump(launch_json, json_file)
def create_main_file(day: int, year: int) -> None:
with open(f'day_{day}.py','w') as main_file:
main_file.write(f"""
from Day{day} import Day{day}
def main():
d = Day{day}('{year}/Day{day}/tests/input.txt')
print(f'Part 1: {{d.part1()}}')
#print(f'Part 2: {{d.part2()}}')
if __name__ == '__main__':
main()
""")
def main():
# process command line args
argParser = argparse.ArgumentParser()
argParser.add_argument("-y", type=int, dest="year", help="Year (e.g., 2023)")
argParser.add_argument( "-d", type=int, dest="days", help="Number of Days (e.g., 25)")
args = argParser.parse_args()
year = args.year
days = args.days
# build directory structure
os.makedirs(f'{year}')
os.chdir(f'{year}')
os.makedirs(f'Common')
for day in range(1,days+1):
# main Python file and input.txt file
os.makedirs(f'Day{day}')
os.chdir(f'Day{day}')
# input.txt file
with open(f'input.txt','w') as _:
pass
# create main file
create_main_file(day, year)
# create class
create_class(day)
# create .vscode
create_vscode(day)
# create tests
create_tests(day, year)
os.chdir('../..')
if __name__ == '__main__':
main()