Skip to content

Commit 98b99fc

Browse files
committed
update
1 parent 93f45e4 commit 98b99fc

29 files changed

+397
-170
lines changed

pyproject.toml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ authors = [
66
]
77
description = "Code for Advent of Code 2023"
88
readme = "README.md"
9-
requires-python = ">=3.8"
9+
requires-python = ">=3.12,<4"
1010
classifiers = [
1111
"Programming Language :: Python :: 3",
1212
"License :: OSI Approved :: MIT License",
1313
"Operating System :: OS Independent",
1414
]
15+
dependencies = [
16+
"numpy==1.26.2",
17+
"pytest==7.4.3",
18+
"ruff>=0.14.8",
19+
"setuptools==68.2.2",
20+
"uv>=0.9.16",
21+
]
1522

1623
[project.urls]
1724
Homepage = "https://github.com/jameslawlor/advent-of-code-python"
@@ -31,8 +38,14 @@ addopts = [
3138

3239
[tool.black]
3340
line-length = 88
34-
target-version = ['py39']
41+
target-version = ['py312']
42+
43+
[tool.ruff]
44+
line-length = 88
45+
target-version = "py312"
46+
exclude = ["__pycache__", ".venv", "build", "dist"]
47+
lint.select = ["E", "F", "W", "C", "B", "I"]
3548

3649
[project.scripts]
3750
# Console script for running day solutions: after `pip install -e .` you can run `aoc --year 2025 --day 1`
38-
aoc = "advent_of_code.cli:main"
51+
aoc = "advent_of_code.cli:main"

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
ruff==0.1.9
21
numpy==1.26.2
32
pytest==7.4.3
3+
ruff==0.14.8
44
setuptools==68.2.2
5+
uv==0.9.16
6+
black

scripts/generate_new_day_skeleton_files_from_templates.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import os
21
import argparse
3-
2+
import os
43

54
TEMPLATES_PATH = os.path.join("scripts", "templates")
65

scripts/run_all_solutions.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
RUN_DAY_SCRIPT = "scripts/run_day.py"
88
INPUTS_DIR = "inputs"
99

10+
1011
def discover_and_run_solutions():
1112
# Regex to match "day_<number>.py"
1213
day_pattern = re.compile(r"day_(\d{2})\.py")
13-
14+
1415
for year in sorted(os.listdir(BASE_DIR)):
1516
if year.startswith("year_"):
1617
year_path = os.path.join(BASE_DIR, year)
@@ -24,25 +25,33 @@ def discover_and_run_solutions():
2425
day_number = match.group(1)
2526

2627
# Build input file path
27-
input_file = os.path.join(INPUTS_DIR, f"year_{year_number}", f"{day_number}.dat")
28+
input_file = os.path.join(
29+
INPUTS_DIR, f"year_{year_number}", f"{day_number}.dat"
30+
)
2831
if not os.path.exists(input_file):
29-
print(f"Input file for {year_number} Day {day_number} not found, skipping.")
32+
print(f"Input for {year_number} {day_number} missing, skipping")
3033
continue
3134

3235
# Run the solution using run_day.py
3336
try:
3437
print(f"Running {year_number} Day {day_number}...")
3538
subprocess.run(
3639
[
37-
"python3", RUN_DAY_SCRIPT,
38-
"--year", year_number,
39-
"--day", str(int(day_number)), # Remove leading zero for argument
40+
"python3",
41+
RUN_DAY_SCRIPT,
42+
"--year",
43+
year_number,
44+
"--day",
45+
str(
46+
int(day_number)
47+
), # Remove leading zero for argument
4048
],
41-
check=True
49+
check=True,
4250
)
4351
print("\n")
4452
except subprocess.CalledProcessError as e:
4553
print(f"Error running {year_number} Day {day_number}: {e}")
4654

55+
4756
if __name__ == "__main__":
4857
discover_and_run_solutions()

scripts/run_day.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1+
import argparse
12
import importlib
23
import sys
3-
import argparse
4+
45

56
def main():
6-
parser = argparse.ArgumentParser(description="Run a specific Advent of Code solution.")
7+
parser = argparse.ArgumentParser(
8+
description="Run a specific Advent of Code solution."
9+
)
710
# parser.add_argument(
8-
# "--input_file",
9-
# required=True,
10-
# type=str,
11+
# "--input_file",
12+
# required=True,
13+
# type=str,
1114
# help="Path to the input file for the day's solution."
1215
# )
1316
parser.add_argument(
14-
"--year",
15-
required=True,
16-
type=int,
17+
"--year",
18+
required=True,
19+
type=int,
1720
)
1821
parser.add_argument(
19-
"--day",
20-
required=True,
21-
type=str,
22+
"--day",
23+
required=True,
24+
type=str,
2225
)
2326

2427
args = parser.parse_args()
@@ -35,10 +38,13 @@ def main():
3538
module.main(input_file)
3639
else:
3740
print("man")
38-
print(f"The module {day_module} does not have a 'main(input_file)' function.")
41+
print(
42+
f"The module {day_module} does not have a 'main(input_file)' function."
43+
)
3944
except ModuleNotFoundError:
4045
print(f"Could not find module: {day_module}")
4146
sys.exit(1)
4247

48+
4349
if __name__ == "__main__":
4450
main()

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
from setuptools import setup
22

3-
setup(name="advent-of-code-python", version="0.1", description="advent-of-code-python", packages=["src/advent_of_code"])
3+
setup(
4+
name="advent-of-code-python",
5+
version="0.1",
6+
description="advent-of-code-python",
7+
packages=["src/advent_of_code"],
8+
python_requires=">=3.12,<4",
9+
)

src/advent_of_code/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
66
This file delegates to `advent_of_code.cli:main`.
77
"""
8-
from .cli import main
98

9+
from .cli import main
1010

1111
if __name__ == "__main__":
1212
raise SystemExit(main())

src/advent_of_code/cli.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
88
This duplicates the behavior of `scripts/run_day.py` but lives inside the package.
99
"""
10+
1011
from __future__ import annotations
1112

1213
import argparse
1314
import importlib
14-
import sys
15-
from typing import Sequence, Optional
15+
from typing import Optional, Sequence
1616

1717

1818
def main(argv: Optional[Sequence[str]] = None) -> int:
@@ -24,8 +24,12 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
2424
Returns:
2525
exit code (0 on success).
2626
"""
27-
parser = argparse.ArgumentParser(prog="aoc", description="Run an Advent of Code solution module")
28-
parser.add_argument("--year", required=True, type=int, help="Year directory (e.g. 2025)")
27+
parser = argparse.ArgumentParser(
28+
prog="aoc", description="Run an Advent of Code solution module"
29+
)
30+
parser.add_argument(
31+
"--year", required=True, type=int, help="Year directory (e.g. 2025)"
32+
)
2933
parser.add_argument("--day", required=True, type=str, help="Day number (1 or 01)")
3034

3135
args = parser.parse_args(argv)
@@ -39,8 +43,12 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
3943
module = importlib.import_module(day_module)
4044
except ModuleNotFoundError as exc:
4145
print(f"Could not find module: {day_module}")
42-
# Helpful hint: if running from the repository root, make sure `src` is on PYTHONPATH or install the package editable
43-
print("Hint: run with `PYTHONPATH=src python -m advent_of_code ...` or `pip install -e .` to make the package importable")
46+
# Helpful hint: if running from the repository root,
47+
# make sure `src` is on PYTHONPATH or install the package editable.
48+
print(
49+
"Hint: run with `PYTHONPATH=src python -m advent_of_code ...` "
50+
"or `pip install -e .` to make the package importable"
51+
)
4452
if isinstance(exc, ModuleNotFoundError):
4553
# show original message
4654
print(str(exc))

src/advent_of_code/year_2023/day_01.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import re
2+
13
from advent_of_code.utils.input_handling import (
24
read_input,
35
)
46

5-
import re
6-
77
SPELLED_NUMBERS_MAPPING = {
88
"one": 1,
99
"two": 2,
@@ -95,26 +95,26 @@ def find_indices_of_patterns(line, patterns_to_find):
9595

9696
return patterns_and_indices
9797

98-
def run_part(input_data, accept_written_digits):
9998

99+
def run_part(input_data, accept_written_digits):
100100
patterns_to_find = get_patterns(accept_written_digits)
101101
calibration_value_sum = solve_all_calibration_values(input_data, patterns_to_find)
102102
return calibration_value_sum
103103

104+
104105
def main(input_file):
105106
# args = parse_args()
106107
# input = read_input(args.input_file)
107108
input_data = read_input(input_file)
108109

109-
calibration_value_sum = run_part(input_data, accept_written_digits = False)
110-
110+
calibration_value_sum = run_part(input_data, accept_written_digits=False)
111+
111112
print(f"Part 1: Solution is {calibration_value_sum}.")
112113

113-
calibration_value_sum = run_part(input_data, accept_written_digits = True)
114+
calibration_value_sum = run_part(input_data, accept_written_digits=True)
114115

115116
print(f"Part 2: Solution is {calibration_value_sum}.")
116117

117118

118-
119119
if __name__ == "__main__":
120120
main()

src/advent_of_code/year_2023/day_02.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from advent_of_code.utils.input_handling import read_input
2-
31
import re
42

3+
from advent_of_code.utils.input_handling import read_input
4+
55
BAG_CONSTRAINTS = {"red": 12, "green": 13, "blue": 14}
66

77

0 commit comments

Comments
 (0)