Skip to content

Commit b2fa1f4

Browse files
committed
Update linting and formatting
1 parent 8873ca5 commit b2fa1f4

File tree

14 files changed

+63
-126
lines changed

14 files changed

+63
-126
lines changed

aoc/models/base.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ def benchmark(self, _print: bool = False) -> None:
7777
Args:
7878
_print (bool, optional): Whether to print the elapsed time. Defaults to `False`.
7979
"""
80-
if (
81-
_print
82-
and len(self.benchmark_times) > 0
83-
and len(self.benchmark_times) % 2 == 0
84-
):
80+
if _print and len(self.benchmark_times) > 0 and len(self.benchmark_times) % 2 == 0:
8581
t = self.benchmark_times[-1] - self.benchmark_times[-2]
8682
units = ["s", "ms", "µs", "ns"]
8783
unit_idx = 0

aoc/models/file.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ def get_path() -> str:
3030
str: Absolute path to either the directory containing the script or
3131
the script's directory if it is itself a directory.
3232
"""
33-
return (
34-
path
35-
if os.path.isdir(path := os.path.realpath(sys.argv[0]))
36-
else os.path.dirname(path)
37-
)
33+
return path if os.path.isdir(path := os.path.realpath(sys.argv[0])) else os.path.dirname(path)
3834

3935
@staticmethod
4036
def get_session() -> str:
@@ -137,11 +133,7 @@ def download_test_input(day: int, part_num: int) -> str | None:
137133
if response.status_code == 200:
138134
content = response.text
139135
soup = BeautifulSoup(content, "html.parser")
140-
code_elements = [
141-
element
142-
for element in soup.find_all("code")
143-
if element.text.count("\n") > 0
144-
]
136+
code_elements = [element for element in soup.find_all("code") if element.text.count("\n") > 0]
145137
return code_elements[part_num - 1].text
146138

147139
else:
@@ -189,9 +181,7 @@ def add_day(day: int) -> None:
189181

190182
if file_path.stat().st_size == 0:
191183
now = datetime.now()
192-
available_to_download = datetime(
193-
int(path.split(os.sep)[-1].split("-")[-1]), 12, day, 5, 0, 0
194-
)
184+
available_to_download = datetime(int(path.split(os.sep)[-1].split("-")[-1]), 12, day, 5, 0, 0)
195185

196186
if now < available_to_download:
197187
logger.info(
@@ -201,9 +191,7 @@ def add_day(day: int) -> None:
201191
)
202192

203193
while now < available_to_download:
204-
logger.info(
205-
"\033[Fnow:", now.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3], "UTC"
206-
)
194+
logger.info("\033[Fnow:", now.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3], "UTC")
207195
sleep(1)
208196
now = datetime.now()
209197

@@ -240,9 +228,7 @@ def add_test_input(day: int, part_num: int) -> None:
240228

241229
if file_path.stat().st_size == 0:
242230
now = datetime.now()
243-
available_to_download = datetime(
244-
int(path.split(os.sep)[-1].split("-")[-1]), 12, day, 5, 0, 0
245-
)
231+
available_to_download = datetime(int(path.split(os.sep)[-1].split("-")[-1]), 12, day, 5, 0, 0)
246232

247233
if now < available_to_download:
248234
logger.info(
@@ -252,9 +238,7 @@ def add_test_input(day: int, part_num: int) -> None:
252238
)
253239

254240
while now < available_to_download:
255-
logger.info(
256-
"\033[Fnow:", now.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3], "UTC"
257-
)
241+
logger.info("\033[Fnow:", now.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3], "UTC")
258242
sleep(1)
259243
now = datetime.now()
260244

aoc/models/reader.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ def get_path() -> str:
2626
str: Absolute path to either the directory containing the script or
2727
the script's directory if it is itself a directory.
2828
"""
29-
return (
30-
path
31-
if os.path.isdir(path := os.path.realpath(sys.argv[0]))
32-
else os.path.dirname(path)
33-
)
29+
return path if os.path.isdir(path := os.path.realpath(sys.argv[0])) else os.path.dirname(path)
3430

3531
@staticmethod
3632
def get_puzzle_input(day: int, is_raw: bool) -> List[str]:
@@ -48,14 +44,9 @@ def get_puzzle_input(day: int, is_raw: bool) -> List[str]:
4844
Expects input file at: `data/dayXX/puzzle_input.txt`
4945
where `XX` is the zero-padded day number.
5046
"""
51-
file_path = os.path.join(
52-
Reader.PROJECT_ROOT, f"data/day{day:02d}/puzzle_input.txt"
53-
)
47+
file_path = os.path.join(Reader.PROJECT_ROOT, f"data/day{day:02d}/puzzle_input.txt")
5448
with open(file_path, "r") as file:
55-
return [
56-
line.strip("\n") if is_raw else line.strip()
57-
for line in file.readlines()
58-
]
49+
return [line.strip("\n") if is_raw else line.strip() for line in file.readlines()]
5950

6051
@staticmethod
6152
def get_test_input(day: int, is_raw: bool, part_num: int) -> List[str]:
@@ -74,11 +65,6 @@ def get_test_input(day: int, is_raw: bool, part_num: int) -> List[str]:
7465
Expects input file at: `data/dayXX/test_YY_input.txt`
7566
where `XX` is the zero-padded day number and `YY` is the zero-padded part number.
7667
"""
77-
file_path = os.path.join(
78-
Reader.PROJECT_ROOT, f"data/day{day:02d}/test_{part_num:02d}_input.txt"
79-
)
68+
file_path = os.path.join(Reader.PROJECT_ROOT, f"data/day{day:02d}/test_{part_num:02d}_input.txt")
8069
with open(file_path, "r") as file:
81-
return [
82-
line.strip("\n") if is_raw else line.strip()
83-
for line in file.readlines()
84-
]
70+
return [line.strip("\n") if is_raw else line.strip() for line in file.readlines()]

aoc/models/submission.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ def get_path() -> str:
2626
str: Absolute path to either the directory containing the script or
2727
the script's directory if it is itself a directory.
2828
"""
29-
return (
30-
path
31-
if os.path.isdir(path := os.path.realpath(sys.argv[0]))
32-
else os.path.dirname(path)
33-
)
29+
return path if os.path.isdir(path := os.path.realpath(sys.argv[0])) else os.path.dirname(path)
3430

3531
@staticmethod
3632
def get_session() -> str:

aoc/models/tester.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,4 @@ def run_test(
5757
result = part_method(data=test_input)
5858

5959
# Assert the result
60-
assert (
61-
result == expected
62-
), f"Test failed for Day {day}, Part {part_num}: Expected {expected}, got {result}."
60+
assert result == expected, f"Test failed for Day {day}, Part {part_num}: Expected {expected}, got {result}."

main.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ def main():
8686
action="store_true",
8787
help="Optional, use raw input instead of stripped input.",
8888
)
89-
parser.add_argument(
90-
"--add", action="store_true", help="Optional, create daily file."
91-
)
89+
parser.add_argument("--add", action="store_true", help="Optional, create daily file.")
9290
parser.add_argument(
9391
"--add-test-input",
9492
action="store_true",
@@ -99,9 +97,7 @@ def main():
9997
action="store_true",
10098
help="Optional, create test files.",
10199
)
102-
parser.add_argument(
103-
"--skip-test", action="store_true", help="Optional, skipping tests."
104-
)
100+
parser.add_argument("--skip-test", action="store_true", help="Optional, skipping tests.")
105101
parser.add_argument(
106102
"--benchmark",
107103
action="store_true",
@@ -140,9 +136,7 @@ def main():
140136
args.day, args.part, args.raw, args.skip_test, args.benchmark
141137
)
142138
logger.info(
143-
f"The test answer is {answer}\n"
144-
if (answer := solution.solve(part_num=args.part)) is not None
145-
else ""
139+
f"The test answer is {answer}\n" if (answer := solution.solve(part_num=args.part)) is not None else ""
146140
)
147141
solution.benchmark(_print=True)
148142

@@ -151,11 +145,7 @@ def main():
151145
solution = import_module(f"solutions.day{args.day:02d}").Solution(
152146
args.day, args.part, args.raw, args.skip_test, args.benchmark
153147
)
154-
logger.info(
155-
f"The answer is {answer}\n"
156-
if (answer := solution.solve(part_num=args.part)) is not None
157-
else ""
158-
)
148+
logger.info(f"The answer is {answer}\n" if (answer := solution.solve(part_num=args.part)) is not None else "")
159149
solution.benchmark(_print=True)
160150

161151
if answer and args.submit is True:

poetry.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,23 @@ flake8 = "^7.1.1"
2020
autopep8 = "^2.3.1"
2121
mypy = "^1.13.0"
2222
pytest = "^8.3.4"
23+
flake8-pyproject = "^1.2.3"
24+
25+
[tool.black]
26+
line-length = 120
27+
target-version = ["py311"]
28+
include = '\.pyi?$'
2329

2430
[tool.isort]
2531
profile = "black"
32+
line_length = 120
2633
multi_line_output = 3
2734

35+
[tool.flake8]
36+
max-line-length = 120
37+
extend-ignore = ["E203", "W503"]
38+
exclude = [".venv", ".git", "__pycache__"]
39+
2840
[build-system]
2941
requires = ["poetry-core"]
3042
build-backend = "poetry.core.masonry.api"

solutions/day02.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ def part1(self, data: List[str]) -> int:
9595
[
9696
1
9797
for ls in [list(map(int, line.split())) for line in data]
98-
if (self.is_increasing(ls) or self.is_decreasing(ls))
99-
and self.between_range(ls)
98+
if (self.is_increasing(ls) or self.is_decreasing(ls)) and self.between_range(ls)
10099
]
101100
)
102101

@@ -116,16 +115,10 @@ def part2(self, data: List[str]) -> int:
116115
"""
117116
return sum(
118117
any(
119-
(
120-
self.is_increasing(ls[:i] + ls[i + 1 :])
121-
or self.is_decreasing(ls[:i] + ls[i + 1 :])
122-
)
118+
(self.is_increasing(ls[:i] + ls[i + 1 :]) or self.is_decreasing(ls[:i] + ls[i + 1 :]))
123119
and self.between_range(ls[:i] + ls[i + 1 :])
124120
for i in range(len(ls))
125121
)
126-
or (
127-
(self.is_increasing(ls) or self.is_decreasing(ls))
128-
and self.between_range(ls)
129-
)
122+
or ((self.is_increasing(ls) or self.is_decreasing(ls)) and self.between_range(ls))
130123
for ls in [list(map(int, line.split())) for line in data]
131124
)

solutions/day04.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def check_mas(self, data: List[str], row: int, col: int, dr: int, dc: int) -> bo
3434
rows, cols = len(data), len(data[0])
3535
pattern = "MAS"
3636
return all(
37-
0 <= row + i * dr < rows
38-
and 0 <= col + i * dc < cols
39-
and data[row + i * dr][col + i * dc] == pattern[i]
37+
0 <= row + i * dr < rows and 0 <= col + i * dc < cols and data[row + i * dr][col + i * dc] == pattern[i]
4038
for i in range(3)
4139
)
4240

@@ -71,9 +69,7 @@ def part1(self, data: List[str]) -> int:
7169
for c in range(cols):
7270
for dr, dc in directions:
7371
if all(
74-
0 <= r + i * dr < rows
75-
and 0 <= c + i * dc < cols
76-
and data[r + i * dr][c + i * dc] == "XMAS"[i]
72+
0 <= r + i * dr < rows and 0 <= c + i * dc < cols and data[r + i * dr][c + i * dc] == "XMAS"[i]
7773
for i in range(4)
7874
):
7975
count += 1

0 commit comments

Comments
 (0)