Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9386bf1
Refactor day_template.py: streamline input handling and simplify part…
cak Dec 2, 2026
24f81ed
Update CI workflow and tests: add puzzle execution step and refactor …
cak Dec 2, 2026
ab6b1bc
Refactor submit_answer and submit_to_aoc: improve error handling and …
cak Dec 2, 2026
a5d53d4
Refactor AOCClient HTTP methods: switch to build_request for improved…
cak Dec 2, 2026
a1d5869
Update cache and guesses handling: improve cache key naming, enhance …
cak Dec 2, 2026
9232265
Update cache command output: enhance cache directory display and coun…
cak Dec 2, 2026
c8db7c9
Update private leaderboard documentation and enhance test coverage fo…
cak Dec 2, 2026
eac7a11
Enhance input fetching logic: implement legacy cache handling, improv…
cak Dec 2, 2026
87ee901
Add MD5 hashing and integer extraction functions; implement tests for…
cak Dec 2, 2026
47746f5
Refactor leaderboard handling: streamline session token resolution, e…
cak Dec 2, 2026
0046757
Refactor guess value parsing and session token resolution: improve er…
cak Dec 2, 2026
fffa53c
Add rate limit handling test: verify subsequent submissions are block…
cak Dec 2, 2026
b8c1c86
Update version to 1.2.2 in pyproject.toml and enhance CHANGELOG with …
cak Dec 2, 2026
242fb28
Update getting started guide for puzzle creation: change example year…
cak Dec 2, 2026
acfc310
Add Python puzzle cookbook: comprehensive guide with examples and exp…
cak Dec 2, 2026
4f7b887
Add workflow_call trigger to Quality workflow
cak Dec 2, 2026
3c61a08
Enhance publish workflow: add quality job dependency, release tag che…
cak Dec 2, 2026
2158a94
Update GitHub Actions workflow: fix action versions for checkout, set…
cak Dec 2, 2026
66cfb1f
Update README.md: enhance interactive puzzle template instructions an…
cak Dec 2, 2026
c61fa2b
Update great-docs.yml: add puzzle-cookbook and additional helper func…
cak Dec 2, 2026
29ca48c
update deps
cak Dec 2, 2026
b2e30d9
Refactor GitHub Actions workflow: streamline test jobs, enhance cachi…
cak Dec 2, 2026
861ae58
Update README.md: clarify GitHub Actions test matrix and workflow limits
cak Dec 2, 2026
1ca65c2
Fix pytest command syntax for faulthandler timeout in quality workflow
cak Dec 2, 2026
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
18 changes: 9 additions & 9 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
name: "Build Docs"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
fetch-depth: 0 # Full history for accurate page timestamps
persist-credentials: false

- uses: actions/setup-python@v6
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: "3.11"

Expand All @@ -30,7 +30,7 @@ jobs:
uv sync --locked --no-default-groups --group docs

- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
uses: quarto-dev/quarto-actions/setup@8a96df13519ee81fd526f2dfca5962811136661b # v2
with:
version: "1.11.9"

Expand All @@ -41,7 +41,7 @@ jobs:
run: uv run --locked --no-default-groups --group docs great-docs build

- name: Save docs artifact
uses: actions/upload-artifact@v7
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: docs-html
path: great-docs/_site
Expand All @@ -52,7 +52,7 @@ jobs:
run: uv run --locked --no-default-groups --group docs great-docs ci notice --run ${{ github.run_id }} --pr ${{ github.event.number }}

- name: Upload build timings
uses: actions/upload-artifact@v7
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: build-timings
path: great-docs/_site/build-timings.json
Expand All @@ -69,20 +69,20 @@ jobs:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/download-artifact@v7
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
with:
name: docs-html
path: great-docs/_site

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v5
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5
with:
path: great-docs/_site
include-hidden-files: true

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5

preview-docs:
name: "Preview Docs"
Expand All @@ -99,6 +99,6 @@ jobs:
# token. continue-on-error so fork PRs (read-only token) don't fail the run.
- name: Post preview instructions to the PR
continue-on-error: true
run: pipx run great-docs ci pr-comment --run ${{ github.run_id }} --pr ${{ github.event.number }}
run: pipx run --spec great-docs==0.17.0 great-docs ci pr-comment --run ${{ github.run_id }} --pr ${{ github.event.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 10 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ permissions:
contents: read

jobs:
quality:
uses: ./.github/workflows/quality.yml

build:
needs: quality
runs-on: ubuntu-latest
steps:
- name: Check out repository
Expand All @@ -17,6 +21,11 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3

- name: Check release tag against package version
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: test "$RELEASE_TAG" = "v$(uv version --short --frozen)"

- name: Build distributions
run: uv build --no-sources

Expand Down Expand Up @@ -48,4 +57,4 @@ jobs:
path: dist/

- name: Publish to PyPI
run: uv publish
run: uv publish --trusted-publishing always
74 changes: 42 additions & 32 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,77 @@ name: Quality
on:
push:
pull_request:
workflow_call:

concurrency:
group: quality-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
tests:
name: Tests · Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python-version: "3.11"
- os: ubuntu-latest
python-version: "3.12"
- os: ubuntu-latest
python-version: "3.13"
- os: ubuntu-latest
python-version: "3.14"
- os: macos-latest
python-version: "3.14"
- os: windows-latest
python-version: "3.14"
python-version: ["3.11", "3.12", "3.13", "3.14"]

steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv and Python
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
python-version: ${{ matrix.python-version }}
enable-cache: true
cache-dependency-glob: uv.lock

- name: Install project
run: uv sync --locked --group dev

- name: Test
run: uv run pytest -q
run: uv run pytest -q -o faulthandler_timeout=30

- name: Smoke-test diagnostics
run: uv run elf doctor

- name: Run a puzzle generated by the installed wheel
if: matrix.python-version == '3.11'
run: |
uv build
uvx --from twine twine check dist/*
uvx check-wheel-contents dist/*.whl
uv pip install --reinstall --no-deps dist/*.whl
cd "$RUNNER_TEMP"
"$GITHUB_WORKSPACE/.venv/bin/elf" new 2016 15
"$GITHUB_WORKSPACE/.venv/bin/python" 2016/day15.py

static-checks:
name: Lint and type check
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install uv and Python
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
python-version: "3.11"
enable-cache: true
cache-dependency-glob: uv.lock

- name: Install project
run: uv sync --locked --group dev

- name: Lint
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
run: uv run ruff check elf tests

- name: Check formatting
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
run: uv run ruff format --check elf tests

- name: Type check
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
run: uv run mypy

- name: Build distributions
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
run: uv build

- name: Validate distributions
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
run: |
uvx --from twine twine check dist/*
uvx check-wheel-contents dist/*.whl
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

Notable user-facing changes to elf are documented here.

## 1.2.2

### Added

- Five optional functions in `elf.helpers` cover common puzzle operations: `ints`, `neighbors4`, `neighbors8`, `manhattan`, and `md5`.
- The Python puzzle cookbook includes runnable examples for parsing, grids, search, timing, and debugging.

### Changed

- `elf new` generates four interactive cells. Start offline with an inline example, set the expected answer for each part, and run only the selected part. Submission requires uncommenting the matching block. Rerun Setup and the selected part after changing the input, part, or account.
- Concurrent reads for the same input share one fetch. Cache hits preserve the original line endings. Reading a private leaderboard validates its model once.

### Fixed

- Incomplete input responses, explicit HTML error pages, and invalid UTF-8 are rejected before writing to the input cache.
- Submission POSTs stop on redirects and respect HTTP 429 retry deadlines. Guess history retains numeric-looking text answers and selects current account caches ahead of stale legacy copies.

### Security

- A leaderboard view key authorizes its request independently of the session cookie. View-key caches start fresh on upgrade, and HTTP status errors omit URLs carrying share keys.

### Upgrade

For a uv tool installation, run `uv tool upgrade elf`. For a pip installation, run `python -m pip install --upgrade elf`. Python 3.11+ remains supported. Existing solution files and session-scoped caches require no migration.

## 1.2.1

### Fixed
Expand Down
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ Supports:
- **json:** raw JSON
- **model:** structured Pydantic model

With a view key, elf sends the key alone, even when a session cookie is configured. The upstream API takes the key in the query string, so keep HTTP client request logs private.

Leaderboard JSON is cached for 15 minutes, matching Advent of Code's minimum request interval. Cache entries are isolated by event, leaderboard ID, and a one-way fingerprint of the session cookie or view key.

### `elf status`
Expand Down Expand Up @@ -346,7 +348,7 @@ do not fail the command; cache-access errors return exit code `1`.
- Guess history stored under: `<cache>/accounts/<fingerprint>/<year>/<day>/guesses.csv`
- Private leaderboard JSON is scoped by event, board ID, and account/view-key fingerprint and cached for at least 15 minutes
- New cache files use private permissions where supported and are replaced atomically to avoid partial files after interruption
- Operating-system locks serialize leaderboard refreshes and guess-history writes. A process exit releases its locks automatically. Finish any running elf 1.2.0 commands before using 1.2.1 against the same cache.
- Operating-system locks serialize input fetches, leaderboard refreshes, and guess-history writes for each cache entry. A process exit releases its locks automatically. Finish any running elf 1.2.0 commands before using 1.2.1 against the same cache.
- Duplicate/high/low guesses are short‑circuited locally when possible
- Cooldown responses retain AoC's server-provided retry deadline; historical entries without one use a 60-second fallback
- Guardrails rely on your local guess history only (new machines/cleared cache = fresh)
Expand Down Expand Up @@ -393,31 +395,35 @@ print(status)

### Interactive Puzzle Template

Create a solution file from elf's [interactive template](https://github.com/typeerror/elf/blob/main/elf/templates/day_template.py):
Generate a daily file in your puzzle project with elf installed in its Python environment.

```sh
elf new 2025 1
elf new 2025 2 --output solutions/2025/day02.py
elf new 2026 2
elf new 2026 2 --output solutions/2026/day02.py
```

By default, Elf creates `YEAR/dayDD.py`, creating parent directories as needed. It refuses to overwrite existing files.

We recommend [Positron](https://positron.posit.co/download.html) for working through puzzles interactively. Open your puzzle project, select the Python interpreter where you installed elf, and run individual `# %%` cells. Use the Variables pane to inspect `raw`, `lines`, `data`, and your answers as you work.

Set `PART` to `1` or `2` in **Setup**. To try an example, paste it into `sample` in **Load Input** and set `USE_SAMPLE = True`. Run **Setup** through the selected part.
The default path is `YEAR/dayNN.py`. Elf creates parent directories and refuses to overwrite existing files.

For a real submission, set `USE_SAMPLE = False`, rerun **Setup** through the selected part, and inspect the answer. Set `SUBMIT = True` in the console, then run **Submit**. The file also runs with `python 2025/day01.py` and defaults to submission off.
1. Open `2026/day02.py` in Positron or another cell-aware editor. In **Setup**, paste the example into `sample` and enter its expected answer in `SAMPLE_ANSWERS[1]`.
2. Run **Setup** and **Part 1**. Edit the solution and rerun the part until the sample assertion passes. Inspect `data`, intermediate variables, and the printed answer as you work.
3. Set `USE_SAMPLE = False`, rerun **Setup** and the selected part, and inspect the real answer. Uncomment the matching two-line block in **Submit**, execute it once, then comment it again.
4. Switch to `PART = 2` and `USE_SAMPLE = True`, set `SAMPLE_ANSWERS[2]`, and repeat. Replace the inline example if Part 2 uses a different one.

If your Advent of Code session changes, rerun from **Load Input** through the selected part before submitting. The template checks that the session used to load the input matches the session used to submit the answer. Each submission requires a fresh opt-in.
Rerun **Setup** and the selected part whenever you change the input, part, or authenticated account. You can also run the whole file with `python 2026/day02.py`. It prints only the selected part and works offline in sample mode.

### Puzzle Helpers

`elf.helpers` includes some small utilities you can use in your own AoC solutions:
Use `elf.helpers` when a puzzle mixes coordinates with text. For example, extract two positions and count the steps between them on an open grid.

```python
from elf.helpers import parse_input, read_input, timer
from elf.helpers import ints, manhattan

r1, c1, r2, c2 = ints("from (-2, 3) to (1, 5)")
assert manhattan((r1, c1), (r2, c2)) == 5
```

The [Python puzzle cookbook](https://typeerror.com/elf/user-guide/puzzle-cookbook.html) covers parsing, collections, grids, graph search, mathematics, timing, and debugging with runnable examples. It also shows when to reach for `neighbors4`, `neighbors8`, `parse_input`, `read_input`, `md5`, and `timer`.

### Leaderboard Example

```sh
Expand Down Expand Up @@ -520,7 +526,7 @@ uv run mypy
uv build
```

GitHub Actions runs the full Python 3.11–3.14 suite on Linux, plus Python 3.14 smoke jobs on macOS and Windows. Tests block external network access, mock every Advent of Code interaction, and never fetch inputs or submit answers.
GitHub Actions runs the full Python 3.11–3.14 test matrix on Ubuntu. Linting, formatting, and type checks run once per workflow. Tests block external network access, mock every Advent of Code interaction, and never fetch inputs or submit answers. Superseded runs are cancelled, and each test job has a five-minute limit.

Alternatively, you can still run:

Expand Down
Loading
Loading