Skip to content

Commit 3801559

Browse files
committed
flake8 max-line-length 120 -> 100
1 parent 08cf700 commit 3801559

File tree

14 files changed

+85
-29
lines changed

14 files changed

+85
-29
lines changed

aoc/models/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ def __init__(
3838
day (int, optional): The day number of the puzzle (1-25). Defaults to -1.
3939
part_num (int, optional): Which part of the day's puzzle (1 or 2). Defaults to 1.
4040
is_raw (bool, optional): Whether to load input as raw text. Defaults to `False`.
41-
skip_test (bool, optional): Whether to use puzzle input instead of test input. Defaults to `True`.
42-
benchmark (bool, optional): Whether to measure solution execution time. Defaults to `False`.
41+
skip_test (bool, optional): Whether to use puzzle input instead of test input.
42+
Defaults to `True`.
43+
benchmark (bool, optional): Whether to measure solution execution time.
44+
Defaults to `False`.
4345
"""
4446
self.day = day
4547
self.part_num = part_num

aoc/models/file.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ 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 path if os.path.isdir(path := os.path.realpath(sys.argv[0])) else os.path.dirname(path)
33+
return (
34+
path if os.path.isdir(path := os.path.realpath(sys.argv[0])) else os.path.dirname(path)
35+
)
3436

3537
@staticmethod
3638
def get_session() -> str:
@@ -133,7 +135,9 @@ def download_test_input(day: int, part_num: int) -> str | None:
133135
if response.status_code == 200:
134136
content = response.text
135137
soup = BeautifulSoup(content, "html.parser")
136-
code_elements = [element for element in soup.find_all("code") if element.text.count("\n") > 0]
138+
code_elements = [
139+
element for element in soup.find_all("code") if element.text.count("\n") > 0
140+
]
137141
return code_elements[part_num - 1].text
138142

139143
else:
@@ -181,7 +185,9 @@ def add_day(day: int) -> None:
181185

182186
if file_path.stat().st_size == 0:
183187
now = datetime.now()
184-
available_to_download = datetime(int(path.split(os.sep)[-1].split("-")[-1]), 12, day, 5, 0, 0)
188+
available_to_download = datetime(
189+
int(path.split(os.sep)[-1].split("-")[-1]), 12, day, 5, 0, 0
190+
)
185191

186192
if now < available_to_download:
187193
logger.info(
@@ -228,7 +234,9 @@ def add_test_input(day: int, part_num: int) -> None:
228234

229235
if file_path.stat().st_size == 0:
230236
now = datetime.now()
231-
available_to_download = datetime(int(path.split(os.sep)[-1].split("-")[-1]), 12, day, 5, 0, 0)
237+
available_to_download = datetime(
238+
int(path.split(os.sep)[-1].split("-")[-1]), 12, day, 5, 0, 0
239+
)
232240

233241
if now < available_to_download:
234242
logger.info(
@@ -256,7 +264,8 @@ def add_test_file(day: int) -> None:
256264
day (int): The day number (1-25) to create test file for.
257265
258266
Note:
259-
Creates test file at: `tests/test_XX.py` using template from `templates/tests/sample.txt`
267+
Creates test file at:
268+
`tests/test_XX.py` using template from `templates/tests/sample.txt`
260269
Replaces placeholders in template with actual day number.
261270
262271
Raises:

aoc/models/reader.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ 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 path if os.path.isdir(path := os.path.realpath(sys.argv[0])) else os.path.dirname(path)
29+
return (
30+
path if os.path.isdir(path := os.path.realpath(sys.argv[0])) else os.path.dirname(path)
31+
)
3032

3133
@staticmethod
3234
def get_puzzle_input(day: int, is_raw: bool) -> List[str]:
@@ -65,6 +67,8 @@ def get_test_input(day: int, is_raw: bool, part_num: int) -> List[str]:
6567
Expects input file at: `tests/data/dayXX/test_YY_input.txt`
6668
where `XX` is the zero-padded day number and `YY` is the zero-padded part number.
6769
"""
68-
file_path = os.path.join(Reader.PROJECT_ROOT, f"tests/data/day{day:02d}/test_{part_num:02d}_input.txt")
70+
file_path = os.path.join(
71+
Reader.PROJECT_ROOT, f"tests/data/day{day:02d}/test_{part_num:02d}_input.txt"
72+
)
6973
with open(file_path, "r") as file:
7074
return [line.strip("\n") if is_raw else line.strip() for line in file.readlines()]

aoc/models/submission.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ 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 path if os.path.isdir(path := os.path.realpath(sys.argv[0])) else os.path.dirname(path)
29+
return (
30+
path if os.path.isdir(path := os.path.realpath(sys.argv[0])) else os.path.dirname(path)
31+
)
3032

3133
@staticmethod
3234
def get_session() -> str:

aoc/models/tester.py

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

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

main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ def main():
136136
args.day, args.part, args.raw, args.skip_test, args.benchmark
137137
)
138138
logger.info(
139-
f"The test answer is {answer}\n" if (answer := solution.solve(part_num=args.part)) is not None else ""
139+
f"The test answer is {answer}\n"
140+
if (answer := solution.solve(part_num=args.part)) is not None
141+
else ""
140142
)
141143
solution.benchmark(_print=True)
142144

@@ -145,7 +147,11 @@ def main():
145147
solution = import_module(f"solutions.day{args.day:02d}").Solution(
146148
args.day, args.part, args.raw, args.skip_test, args.benchmark
147149
)
148-
logger.info(f"The answer is {answer}\n" if (answer := solution.solve(part_num=args.part)) is not None else "")
150+
logger.info(
151+
f"The answer is {answer}\n"
152+
if (answer := solution.solve(part_num=args.part)) is not None
153+
else ""
154+
)
149155
solution.benchmark(_print=True)
150156

151157
if answer and args.submit is True:

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ pytest = "^8.3.4"
2323
flake8-pyproject = "^1.2.3"
2424

2525
[tool.black]
26-
line-length = 120
26+
line-length = 100
2727
target-version = ["py311"]
2828
include = '\.pyi?$'
2929

3030
[tool.isort]
3131
profile = "black"
32-
line_length = 120
32+
line_length = 100
3333
multi_line_output = 3
3434

3535
[tool.flake8]
36-
max-line-length = 120
36+
max-line-length = 100
3737
extend-ignore = ["E203", "W503"]
3838
exclude = [".venv", ".git", "__pycache__"]
3939

solutions/day02.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ def part2(self, data: List[str]) -> int:
115115
"""
116116
return sum(
117117
any(
118-
(self.is_increasing(ls[:i] + ls[i + 1 :]) or self.is_decreasing(ls[:i] + ls[i + 1 :]))
118+
(
119+
self.is_increasing(ls[:i] + ls[i + 1 :])
120+
or self.is_decreasing(ls[:i] + ls[i + 1 :])
121+
)
119122
and self.between_range(ls[:i] + ls[i + 1 :])
120123
for i in range(len(ls))
121124
)

solutions/day04.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ 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 and 0 <= col + i * dc < cols and data[row + i * dr][col + i * dc] == pattern[i]
37+
0 <= row + i * dr < rows
38+
and 0 <= col + i * dc < cols
39+
and data[row + i * dr][col + i * dc] == pattern[i]
3840
for i in range(3)
3941
)
4042

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

solutions/day05.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def is_valid_order(self, pages: List[int], rules: List[Tuple[int, int]]) -> bool
5050
5151
Args:
5252
pages (List[int]): List of page numbers in their print order
53-
rules (List[Tuple[int, int]]): List of (before, after) pairs specifying required ordering
53+
rules (List[Tuple[int, int]]): List of (before, after) pairs specifying
54+
required ordering
5455
5556
Returns:
5657
bool: `True` if all rules are satisfied (each 'before' page appears before its
@@ -60,7 +61,9 @@ def is_valid_order(self, pages: List[int], rules: List[Tuple[int, int]]) -> bool
6061
"""
6162
position = {num: i for i, num in enumerate(pages)}
6263
return all(
63-
position[before] < position[after] for before, after in rules if before in position and after in position
64+
position[before] < position[after]
65+
for before, after in rules
66+
if before in position and after in position
6467
)
6568

6669
def fix_order(self, pages: List[int], rules: List[tuple]) -> List[int]:
@@ -99,7 +102,9 @@ def part1(self, data: List[str]) -> int:
99102
(orders that already satisfy all rules).
100103
"""
101104
rules, ordering = self.parse_data(data)
102-
return sum(pages[len(pages) // 2] for pages in ordering if self.is_valid_order(pages, rules))
105+
return sum(
106+
pages[len(pages) // 2] for pages in ordering if self.is_valid_order(pages, rules)
107+
)
103108

104109
def part2(self, data: List[str]) -> int:
105110
"""Sum middle pages from fixed invalid print orders.
@@ -113,5 +118,7 @@ def part2(self, data: List[str]) -> int:
113118
"""
114119
rules, ordering = self.parse_data(data)
115120
return sum(
116-
self.fix_order(pages, rules)[len(pages) // 2] for pages in ordering if not self.is_valid_order(pages, rules)
121+
self.fix_order(pages, rules)[len(pages) // 2]
122+
for pages in ordering
123+
if not self.is_valid_order(pages, rules)
117124
)

0 commit comments

Comments
 (0)