Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure repo, add templates and new day file generation #12

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/orchestrator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: aoc-2023-ci
name: advent-of-code-python-ci

on: [push, pull_request]

Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ test:

# Run specific solutions for Advent of Code 2023
solutions:
python3 src/aoc_2023/days/1.py --input_file inputs/1.txt --part 1
python3 src/aoc_2023/days/1.py --input_file inputs/1.txt --part 2
python3 src/aoc_2023/days/2.py --input_file inputs/2.txt
python3 src/aoc_2023/days/3.py --input_file inputs/3.txt
python3 src/aoc_2023/days/4.py --input_file inputs/4.txt
python3 src/aoc_2023/days/6.py --input_file inputs/6.txt
python3 src/advent_of_code/year_2023/days/1.py --input_file inputs/2023/1.txt --part 1
python3 src/advent_of_code/year_2023/days/1.py --input_file inputs/2023/1.txt --part 2
python3 src/advent_of_code/year_2023/days/2.py --input_file inputs/2023/2.txt
python3 src/advent_of_code/year_2023/days/3.py --input_file inputs/2023/3.txt
python3 src/advent_of_code/year_2023/days/4.py --input_file inputs/2023/4.txt
python3 src/advent_of_code/year_2023/days/6.py --input_file inputs/2023/6.txt
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# aoc-2023
# advent-of-code-python

Some overengineered Python solutions for Advent of Code 2023

```
docker build -t aoc-2023-app .
docker run aoc-2023-app
docker build -t advent-of-code-python-app .
docker run advent-of-code-python-app
```

### Progress
### 2023 Progress

| Day | Part 1 | Part 2 |
| :---: | :------: | :------: |
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "aoc-2023"
name = "advent-of-code-python"
version = "0.0.1"
authors = [
{ name="James Lawlor", email="[email protected]" },
Expand All @@ -14,7 +14,7 @@ classifiers = [
]

[project.urls]
Homepage = "https://github.com/jameslawlor/aoc-2023"
Homepage = "https://github.com/jameslawlor/advent-of-code-python"

[build-system]
requires = ["hatchling"]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from setuptools import setup

setup(name="aoc-2023", version="0.1", description="AOC 2023", packages=["src/aoc_2023"])
setup(name="advent-of-code-python", version="0.1", description="advent-of-code-python", packages=["src/advent_of_code"])
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
import argparse


TEMPLATES_PATH = os.path.join(".", "src", "advent_of_code", "scripts", "templates")


def parse_input_args():
parser = argparse.ArgumentParser()
parser.add_argument("--day", type=str, required=True)
parser.add_argument("--year", type=str, required=True)
args = parser.parse_args()
return args


def read_template(template_file_path) -> None:
with open(template_file_path, "r") as template_file:
return template_file.read()


def write_template(template: str, write_path: str) -> None:
# if os.path.exists(write_path):
# print(f"File {write_path} already exists! Not writing.")
# else:
with open(write_path, "w") as f:
f.write(template)


def generate_file(template_file_path, input_day, input_year, output_file_path):
try:
# Read the template content from the file
template_content = read_template(template_file_path)
except FileNotFoundError:
print(f"Template file '{template_file_path}' not found.")
exit(1)

# Replace placeholder with the provided integer input
modified_content = template_content.replace("{day}", str(input_day)).replace(
"{year}", str(input_year)
)
# Generate the Python file from the template
write_template(modified_content, output_file_path)
print(f"Python file '{output_file_path}' generated successfully.")


if __name__ == "__main__":
args = parse_input_args()
input_day = args.day
input_year = args.year

day_file_dest = os.path.join(
"src", "advent_of_code", f"year_{input_year}", f"days/{input_day}.py"
)
template_path = os.path.join(TEMPLATES_PATH, "days_template.txt")
generate_file(template_path, input_day, input_year, day_file_dest)

solvers_file_dest = os.path.join(
"src",
"advent_of_code",
f"year_{input_year}",
f"solvers/day_{input_day}_solvers.py",
)
template_path = os.path.join(TEMPLATES_PATH, "solvers_template.txt")
generate_file(template_path, input_day, input_year, solvers_file_dest)

tests_file_dest = os.path.join(
"tests", f"year_{input_year}", f"test_day_{input_day}_solvers.py"
)
template_path = os.path.join(TEMPLATES_PATH, "tests_template.txt")
generate_file(template_path, input_day, input_year, tests_file_dest)
19 changes: 19 additions & 0 deletions src/advent_of_code/scripts/templates/days_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from advent_of_code.year_{year}.solvers.day_{day}_solvers import (
solve_day_{day},
)
from advent_of_code.utils.input_handling import read_input, parse_args


def main():
args = parse_args()
input = read_input(args.input_file)
result_part_1, result_part_2 = solve_day_{day}(input)
print(
f"Day {day}: "
f" Result for part 1 is {result_part_1}. "
f" Result for part 2 is {result_part_2}. "
)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions src/advent_of_code/scripts/templates/solvers_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def solve_day_{day}(input):
part_1, part_2 = do_something(input)
return (part_1, part_2)
14 changes: 14 additions & 0 deletions src/advent_of_code/scripts/templates/tests_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
from advent_of_code.year_{year}.solvers.day_{day}_solvers import (
solve_day_{day},
)


@pytest.fixture
def day_{day}_test_input():
return []


@pytest.fixture
def day_{day}_expected_output():
return []
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from aoc_2023.solvers.day_1_solvers import (
from advent_of_code.year_2023.solvers.day_1_solvers import (
get_patterns,
solve_all_calibration_values,
)


from aoc_2023.utils.input_handling import (
from advent_of_code.utils.input_handling import (
read_input,
parse_args,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from aoc_2023.utils.input_handling import read_input, parse_args
from aoc_2023.solvers.day_2_solvers import solve_day_2
from advent_of_code.utils.input_handling import read_input, parse_args
from advent_of_code.year_2023.solvers.day_2_solvers import solve_day_2


def main():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from aoc_2023.solvers.day_3_solvers import (
from advent_of_code.year_2023.solvers.day_3_solvers import (
solve_day_3,
)
from aoc_2023.utils.input_handling import read_input, parse_args
from advent_of_code.utils.input_handling import read_input, parse_args


def main():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from aoc_2023.solvers.day_4_solvers import (
from advent_of_code.year_2023.solvers.day_4_solvers import (
solve_day_4,
)
from aoc_2023.utils.input_handling import read_input, parse_args
from advent_of_code.utils.input_handling import read_input, parse_args


def main():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from aoc_2023.solvers.day_6_solvers import (
from advent_of_code.year_2023.solvers.day_6_solvers import (
solve_day_6,
)
from aoc_2023.utils.input_handling import read_input, parse_args
from advent_of_code.utils.input_handling import read_input, parse_args


def main():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from aoc_2023.solvers.day_1_solvers import (
from advent_of_code.year_2023.solvers.day_1_solvers import (
convert_str_to_numerical,
get_patterns,
solve_all_calibration_values,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from aoc_2023.solvers.day_2_solvers import (
from advent_of_code.year_2023.solvers.day_2_solvers import (
solve_day_2,
check_game_is_possible,
parse_game_string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from aoc_2023.solvers.day_3_solvers import (
from advent_of_code.year_2023.solvers.day_3_solvers import (
Part,
Symbol,
check_char_is_number,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from aoc_2023.solvers.day_4_solvers import (
from advent_of_code.year_2023.solvers.day_4_solvers import (
solve_day_4,
compute_copies,
create_cards,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import math
from aoc_2023.solvers.day_6_solvers import (
from advent_of_code.year_2023.solvers.day_6_solvers import (
Race,
Races,
create_races,
Expand Down