-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile
executable file
·109 lines (88 loc) · 2.47 KB
/
Taskfile
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# Stop on failure
set -e
REPO_ROOT="$(git rev-parse --show-toplevel)"
function initrepo {
ln -s ${REPO_ROOT}/Taskfile ${REPO_ROOT}/.git/hooks/pre-commit
}
function check {
echo "Run Taskfile help to see other task you can run"
echo "Running the default precommit checks"
mypy --strict ${REPO_ROOT}/python/src/*.py
ruff check python/src/
pytest ${REPO_ROOT}/python/src
pushd ${REPO_ROOT}/rust
cargo test
popd
}
function newday {
if [ -z "$1" ]; then
echo "Specify a day"
return 2
fi
RAW_DAY=$1
NEW_DAY=$(printf d%02d $RAW_DAY)
echo "Get day $RAW_DAY (pretty version $NEW_DAY)"
# Do NOT commit the real puzzle input - it shouldn't be shared!
# Grab the input first so that it fails early if network access is an issue
aoc download -I --input-file input/real/${NEW_DAY} --year 2022 --day $RAW_DAY
touch ${REPO_ROOT}/input/examples/${NEW_DAY}
git add ${REPO_ROOT}/input/examples/${NEW_DAY}
# Python
cp ${REPO_ROOT}/python/src/template.py ${REPO_ROOT}/python/src/${NEW_DAY}.py
sed -i '' "s/XXX/${RAW_DAY}/" ${REPO_ROOT}/python/src/${NEW_DAY}.py
git add ${REPO_ROOT}/python/src/${NEW_DAY}.py
code ${REPO_ROOT}/python/src/${NEW_DAY}.py
# Rust
cp ${REPO_ROOT}/rust/src/template.rs ${REPO_ROOT}/rust/src/${NEW_DAY}.rs
git add ${REPO_ROOT}/rust/src/${NEW_DAY}.rs
code ${REPO_ROOT}/rust/src/${NEW_DAY}.rs
# Last so that this is the file that has focus
code ${REPO_ROOT}/input/examples/${NEW_DAY}
}
function fmt {
black python/src
pushd rust
cargo fmt
popd
}
function timeday {
if [ -z "$1" ]; then
echo "Specify a day"
return 2
fi
DAY=$1
pushd ${REPO_ROOT}/python/src
python3 -m timeit "import ${DAY}; ${DAY}.p1p2(${DAY}.utils.real_input('${DAY}'))"
popd
}
function qtimeday {
if [ -z "$1" ]; then
echo "Specify a day"
return 2
fi
DAY=$1
pushd ${REPO_ROOT}/python/src
time python3 -c "import ${DAY}; print(${DAY}.p1p2(${DAY}.utils.real_input('${DAY}')))"
popd
}
function timedays {
pushd ${REPO_ROOT}/python/src
python3 -m utils
popd
}
function testdays {
pytest --durations=0 -k test_puzzles ${REPO_ROOT}/python/src
}
function help {
echo "$0 <task> <args>"
echo "Tasks:"
compgen -A function | cat -n
}
function t2 {
DAY=$1
pp_day=$(printf %02d $DAY)
echo "$DAY becomes $pp_day"
}
TIMEFORMAT="Task completed in %3lR"
time "${@:-check}"