diff --git a/README.md b/README.md index b087eb7..c7e291a 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ $ pipx install copier $ python -m pip install advent-of-code-data ``` -Once you have Copier on your system, you can create Advent of Code solution templates as follows: +Note that `advent-of-code-data` requires a small bit of [setup](https://github.com/wimglenn/advent-of-code-wim/issues/1) where you find and specify your personal Advent of Code session ID. Once you have Copier on your system, you can create Advent of Code solution templates as follows: ```console $ copier gh:gahjelle/template-aoc-python advent_of_code/ @@ -29,14 +29,30 @@ You can also use Copier as part of a script. The [documentation](https://copier. On the command line, you can use `-d` to provide answers to questions instead of answering them interactively. On Bash (and possibly other shells), the following will set up all directories for the 2021 event inside of your `aoc/` directory: ```console -$ for day in {1..25}; do -> copier gh:gahjelle/template-aoc-python -d year=2021 -d day=$day -d puzzle_name="" aoc/ +$ for day in {01..25}; do +> copier gh:gahjelle/template-aoc-python -d year=2021 -d day=$day -d puzzle_name="" -d puzzle_dir=$day aoc/ > done ``` +If you're using Powershell on Windows, you can use something like this instead: + +``` +for ($day = 1; $day -le 25; $day++) { + $day_str = "{0:00}" -f $day + copier gh:gahjelle/template-aoc-python -d year=2021 -d day=$day_str -d puzzle_name="" -d puzzle_dir=$day_str aoc/ +} +``` + After running this, you'll have 25 subdirectories within `aoc/2021/` with templates for solving each day of Advent of Code with Python. ## Examples -See https://github.com/gahjelle/advent_of_code/tree/main/python for examples using the template. +See https://github.com/gahjelle/advent_of_code/tree/main/python for examples using the template. My tutorial, [Advent of Code: Solving Your Puzzles With Python](https://realpython.com/python-advent-of-code/), explains the reasoning behind the template and shows a few examples of using it to solve puzzles. + + +## Credits + +Thanks to [Matt Gregory](https://github.com/grovduck) for helping to [debug](https://github.com/gahjelle/template-aoc-python/issues/1) this recipe for Windows and creating the Powershell script to create a full year of templates. + +And a huge thanks to [Eric Wastl](https://twitter.com/ericwastl/) for creating the wonderful [Advent of Code](https://adventofcode.com/). diff --git a/copier.yml b/copier.yml index 044a6f2..5b6c794 100644 --- a/copier.yml +++ b/copier.yml @@ -5,44 +5,44 @@ _tasks: # Questions year: - type: int + type: str choices: - - 2015 - - 2016 - - 2017 - - 2018 - - 2019 - - 2020 - - 2021 + - "2015" + - "2016" + - "2017" + - "2018" + - "2019" + - "2020" + - "2021" day: - type: int + type: str choices: - - 1 - - 2 - - 3 - - 4 - - 5 - - 6 - - 7 - - 8 - - 9 - - 10 - - 11 - - 12 - - 13 - - 14 - - 15 - - 16 - - 17 - - 18 - - 19 - - 20 - - 21 - - 22 - - 23 - - 24 - - 25 + - "01" + - "02" + - "03" + - "04" + - "05" + - "06" + - "07" + - "08" + - "09" + - "10" + - "11" + - "12" + - "13" + - "14" + - "15" + - "16" + - "17" + - "18" + - "19" + - "20" + - "21" + - "22" + - "23" + - "24" + - "25" puzzle_name: type: str @@ -50,4 +50,4 @@ puzzle_name: puzzle_dir: type: str - default: "[['%02d'|format(day)]][% if puzzle_name %]_[[puzzle_name|lower|replace(' ','_')]][% endif %]" + default: "[[day]][% if puzzle_name %]_[[puzzle_name|lower|replace(' ','_')]][% endif %]" diff --git a/src/[[year]]/[[puzzle_dir]]/aoc[[year]][['%02d'|format(day)]].py.tmpl b/src/[[year]]/[[puzzle_dir]]/aoc[[year]][[day]].py.tmpl similarity index 88% rename from src/[[year]]/[[puzzle_dir]]/aoc[[year]][['%02d'|format(day)]].py.tmpl rename to src/[[year]]/[[puzzle_dir]]/aoc[[year]][[day]].py.tmpl index 14bb994..f22206e 100644 --- a/src/[[year]]/[[puzzle_dir]]/aoc[[year]][['%02d'|format(day)]].py.tmpl +++ b/src/[[year]]/[[puzzle_dir]]/aoc[[year]][[day]].py.tmpl @@ -1,4 +1,4 @@ -"""AoC [[day]], [[year]][% if puzzle_name %]: [[puzzle_name]][% endif %]""" +"""AoC [[day|int]], [[year]][% if puzzle_name %]: [[puzzle_name]][% endif %]""" # Standard library imports import pathlib diff --git a/src/[[year]]/[[puzzle_dir]]/test_aoc[[year]][['%02d'|format(day)]].py.tmpl b/src/[[year]]/[[puzzle_dir]]/test_aoc[[year]][[day]].py.tmpl similarity index 64% rename from src/[[year]]/[[puzzle_dir]]/test_aoc[[year]][['%02d'|format(day)]].py.tmpl rename to src/[[year]]/[[puzzle_dir]]/test_aoc[[year]][[day]].py.tmpl index a2101c6..30a38ca 100644 --- a/src/[[year]]/[[puzzle_dir]]/test_aoc[[year]][['%02d'|format(day)]].py.tmpl +++ b/src/[[year]]/[[puzzle_dir]]/test_aoc[[year]][[day]].py.tmpl @@ -1,10 +1,10 @@ -"""Tests for AoC [[day]], [[year]][% if puzzle_name %]: [[puzzle_name]][% endif %]""" +"""Tests for AoC [[day|int]], [[year]][% if puzzle_name %]: [[puzzle_name]][% endif %]""" # Standard library imports import pathlib # Third party imports -import aoc[[year]][['%02d'|format(day)]] +import aoc[[year]][[day]] import pytest PUZZLE_DIR = pathlib.Path(__file__).parent @@ -13,13 +13,13 @@ PUZZLE_DIR = pathlib.Path(__file__).parent @pytest.fixture def example1(): puzzle_input = (PUZZLE_DIR / "example1.txt").read_text().strip() - return aoc[[year]][['%02d'|format(day)]].parse(puzzle_input) + return aoc[[year]][[day]].parse(puzzle_input) @pytest.fixture def example2(): puzzle_input = (PUZZLE_DIR / "example2.txt").read_text().strip() - return aoc[[year]][['%02d'|format(day)]].parse(puzzle_input) + return aoc[[year]][[day]].parse(puzzle_input) @pytest.mark.skip(reason="Not implemented") @@ -31,10 +31,10 @@ def test_parse_example1(example1): @pytest.mark.skip(reason="Not implemented") def test_part1_example1(example1): """Test part 1 on example input""" - assert aoc[[year]][['%02d'|format(day)]].part1(example1) == ... + assert aoc[[year]][[day]].part1(example1) == ... @pytest.mark.skip(reason="Not implemented") def test_part2_example2(example2): """Test part 2 on example input""" - assert aoc[[year]][['%02d'|format(day)]].part2(example2) == ... + assert aoc[[year]][[day]].part2(example2) == ...