-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
56 lines (48 loc) · 1.79 KB
/
Makefile
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
SOLUTION_DIR = src/aoc/solutions
README_FILE = README.md
INTRO_FILE = misc/readme-intro.md
build:
@uv sync --all-extras --dev && uv build
fmt:
@uvx ruff format
clean:
@uv clean
run:
@latest_file=$$(ls -1v $(SOLUTION_DIR)/*.py | tail -n 1); \
if [ -n "$$latest_file" ]; then \
day=$$(basename $$latest_file .py); \
python $$latest_file; \
else \
echo "No solution files found in $(SOLUTION_DIR)"; \
exit 1; \
fi
runall:
@for file in $(SOLUTION_DIR)/*.py; do \
day=$$(basename $$file .py); \
python $$file; \
echo ""; \
done
readme:
@cat $(INTRO_FILE) > $(README_FILE)
@echo "| **Day** | **Link** | **Total Lines** | **Effective Lines**| **Runtime** | **Last Updated** |" >> $(README_FILE)
@echo "| -: | - | -: | -: | -: | -: |" >> $(README_FILE)
@for file in $(SOLUTION_DIR)/*.py; do \
day=$$(basename $$file .py); \
total_lines=$$(wc -l < $$file); \
effective_lines=$$(grep -cve '^\s*$$' -e '^\s*#' $$file); \
last_updated=$$(stat -f '%Sm' -t '%a, %b %d, %Y' $$file); \
echo "Running $$day"; \
run_time=$$( { time python $$file > /dev/null 2>&1; } 2>&1 | grep real | awk '{print $$(NF)}'); \
echo "| $$day | [Link](./$$file) | $$total_lines | $$effective_lines | $$run_time | $$last_updated |" >> $(README_FILE); \
done
@echo "README.md generated successfully"
update: build fmt readme
@git add . && git commit -m "Update"
new:
@echo "Creating a new solution file..."
@last_day=$$(ls -1v $(SOLUTION_DIR)/*.py 2>/dev/null | tail -n 1 | xargs -n 1 basename | sed 's/\.py//'); \
next_day=$$((10#$${last_day:-0} + 1)); \
new_file="$(SOLUTION_DIR)/$$(printf '%02d.py' $$next_day)"; \
echo "Creating $$new_file"; \
echo 'from aoc.utilities.fetch import get_input\n\ndata = get_input('$$next_day')' > $$new_file; \
echo "New solution file $$new_file created successfully!"