Skip to content

Commit 2117449

Browse files
committed
Formatting and linting
1 parent 637696a commit 2117449

File tree

8 files changed

+25
-17
lines changed

8 files changed

+25
-17
lines changed

.github/workflows/python-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: poetry run black . --check
4545

4646
- name: Lint with flake8
47-
run: poetry run flake8 . --max-line-length=100
47+
run: poetry run flake8 . --max-line-length=120 --exclude=.venv
4848

4949
test:
5050
name: Tests

aoc/models/file.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import json
22
import os
33
import sys
4-
import urllib.parse
54
from datetime import datetime
65
from pathlib import Path
76
from time import sleep
8-
from typing import Dict, Optional
7+
from typing import Dict
98
from urllib.request import Request, urlopen
109

1110
import requests
@@ -203,7 +202,8 @@ def add_day(day: int) -> None:
203202

204203
while now < available_to_download:
205204
logger.info(
206-
"\033[Fnow:", now.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3], "UTC"
205+
"\033[Fnow:", now.strftime(
206+
"%Y-%m-%d %H:%M:%S.%f")[:-3], "UTC"
207207
)
208208
sleep(1)
209209
now = datetime.now()
@@ -254,7 +254,8 @@ def add_test_input(day: int, part_num: int) -> None:
254254

255255
while now < available_to_download:
256256
logger.info(
257-
"\033[Fnow:", now.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3], "UTC"
257+
"\033[Fnow:", now.strftime(
258+
"%Y-%m-%d %H:%M:%S.%f")[:-3], "UTC"
258259
)
259260
sleep(1)
260261
now = datetime.now()
@@ -289,7 +290,8 @@ def add_test_file(day: int) -> None:
289290
if not test_path.exists():
290291
sample_file = f"{path}/templates/tests/sample.txt"
291292
if not os.path.exists(sample_file):
292-
raise FileNotFoundError(f"Template file not found: {sample_file}")
293+
raise FileNotFoundError(
294+
f"Template file not found: {sample_file}")
293295

294296
with open(sample_file, "r") as file:
295297
content = file.read()

aoc/models/reader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class Reader:
1515
the `aoc` package location.
1616
"""
1717

18-
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__).rsplit("aoc", 1)[0])
18+
PROJECT_ROOT = os.path.dirname(
19+
os.path.abspath(__file__).rsplit("aoc", 1)[0])
1920

2021
@staticmethod
2122
def get_path() -> str:

aoc/models/submission.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,15 @@ def submit(day: int, level: int, answer: int) -> None:
110110
values = {"level": level, "answer": answer}
111111
data = urllib.parse.urlencode(values).encode("utf-8")
112112

113-
req = urllib.request.Request(url, method=method, headers=headers, data=data)
113+
req = urllib.request.Request(
114+
url, method=method, headers=headers, data=data)
114115

115116
with urllib.request.urlopen(req) as response:
116117
content = response.read().decode("utf-8")
117118

118119
# Extract and format the response message
119-
article = re.findall(r"<article>(.*?)</article>", content, re.DOTALL)[0]
120+
article = re.findall(r"<article>(.*?)</article>",
121+
content, re.DOTALL)[0]
120122
article = "".join(article.split("</p>"))
121123
article = article.replace("\n", "")
122124
article = re.sub(r"<.*?>", "", article, re.DOTALL)

solutions/day02.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ def part2(self, data: List[str]) -> int:
117117
return sum(
118118
any(
119119
(
120-
self.is_increasing(ls[:i] + ls[i + 1 :])
121-
or self.is_decreasing(ls[:i] + ls[i + 1 :])
120+
self.is_increasing(ls[:i] + ls[i + 1:])
121+
or self.is_decreasing(ls[:i] + ls[i + 1:])
122122
)
123-
and self.between_range(ls[:i] + ls[i + 1 :])
123+
and self.between_range(ls[:i] + ls[i + 1:])
124124
for i in range(len(ls))
125125
)
126126
or (

solutions/day05.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ def parse_data(
4141
"3,1,2"
4242
Returns: ([(1,2), (2,3)], [[1,2,3], [3,1,2]])
4343
"""
44-
rules, ordering = [part.splitlines() for part in "\n".join(data).split("\n\n")]
45-
rules = [(int(a), int(b)) for a, b in (rule.split("|") for rule in rules)]
44+
rules, ordering = [part.splitlines()
45+
for part in "\n".join(data).split("\n\n")]
46+
rules = [(int(a), int(b))
47+
for a, b in (rule.split("|") for rule in rules)]
4648
ordering = [[int(x) for x in line.split(",")] for line in ordering]
4749

4850
return rules, ordering

solutions/day06.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class Solution(SolutionBase):
2121
guard movement and analyze possible paths.
2222
"""
2323

24-
moves = {"^": (-1, 0), ">": (0, 1), "v": (1, 0), "<": (0, -1)} # Direction vectors
24+
moves = {"^": (-1, 0), ">": (0, 1), "v": (1, 0),
25+
"<": (0, -1)} # Direction vectors
2526
turns = {"^": ">", ">": "v", "v": "<", "<": "^"} # Right turn mappings
2627

2728
def find_start(self, grid: List[List[str]]) -> Tuple[int, int, str]:

solutions/day08.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def part1(self, data: List[str]) -> int:
149149
for positions in antennas.values():
150150
# For each pair of same-frequency antennas
151151
for i, ant1 in enumerate(positions):
152-
for ant2 in positions[i + 1 :]:
152+
for ant2 in positions[i + 1:]:
153153
# Find antinodes for this pair
154154
antinodes = self.find_antinodes(ant1, ant2, data)
155155
all_antinodes.update(antinodes)
@@ -181,7 +181,7 @@ def part2(self, data: List[str]) -> int:
181181

182182
# For each pair of same-frequency antennas
183183
for i, ant1 in enumerate(positions):
184-
for j, ant2 in enumerate(positions[i + 1 :], start=i + 1):
184+
for j, ant2 in enumerate(positions[i + 1:], start=i + 1):
185185
# Add both antenna positions as they are collinear with at least two antennas
186186
all_antinodes.add(ant1)
187187
all_antinodes.add(ant2)

0 commit comments

Comments
 (0)