Skip to content

Commit 1080e92

Browse files
committed
improved language support
1 parent c63bbe1 commit 1080e92

File tree

3 files changed

+61
-13
lines changed

3 files changed

+61
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ input.txt
1919

2020
/build/
2121
build/
22+
23+
.venv/

scripts/allpython.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
script_dir=$(realpath $(dirname $0))
6+
7+
i()
8+
{
9+
local v=$1
10+
11+
local b=$(echo $v | cut -f1 -d'a') # major.minor.micro
12+
local m=$(echo $v | cut -f1-2 -d'.') # major.minor
13+
local url=https://www.python.org/ftp/python/$b/Python-$v.tar.xz
14+
15+
rm -rf /tmp/Python-$v /opt/python/Python-$v
16+
curl -sL $url | tar -C /tmp -xJ
17+
cd /tmp/Python-$v
18+
./configure --prefix=/opt/python/Python-$v --enable-optimizations --disable-test-modules
19+
make -j$(nproc --ignore=1)
20+
make altinstall
21+
# /opt/python/Python-$v/bin/python$m -mensurepip
22+
cd /tmp
23+
rm -rf /tmp/Python-$v
24+
25+
$script_dir/runall.py --venv /opt/python/Python-$v/bin/python$m
26+
}
27+
28+
a()
29+
{
30+
i 3.10.13
31+
i 3.11.6
32+
i 3.12.1
33+
# i 3.13.0a3
34+
}
35+
36+
if [ ${1-} ]; then
37+
i $1
38+
else
39+
a
40+
fi

scripts/runall.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import typing as t
99
from collections import defaultdict
1010
from copy import deepcopy
11-
from datetime import timedelta
11+
from datetime import timedelta, datetime
1212
from operator import itemgetter
1313
from pathlib import Path
1414
from zlib import crc32
@@ -41,11 +41,11 @@
4141
INTERPRETERS = {
4242
"Python": {
4343
"Python": "python3",
44-
"PyPy": ".pypy3.10/bin/python",
45-
"Py3.10": ".py3.10/bin/python",
46-
"Py3.11": ".py3.11/bin/python",
47-
"Py3.12": ".py3.12/bin/python",
48-
"Py3.13": ".py3.13/bin/python",
44+
"PyPy": ".venv/pypy3.10/bin/python",
45+
"Py3.10": ".venv/py3.10/bin/python",
46+
"Py3.11": ".venv/py3.11/bin/python",
47+
"Py3.12": ".venv/py3.12/bin/python",
48+
"Py3.13": ".venv/py3.13/bin/python",
4949
}
5050
}
5151

@@ -154,12 +154,12 @@ def run(
154154
start = time.time_ns()
155155
out = subprocess.run(cmd + [file.absolute()], stdout=subprocess.PIPE)
156156
elapsed = time.time_ns() - start
157-
answers = out.stdout.decode().strip()
157+
answers = " ".join(out.stdout.decode().strip().split("\n"))
158158

159159
status = "unknown"
160160
if solution:
161-
solution = solution.read_text()
162-
if answers == solution.strip():
161+
solution = " ".join(solution.read_text().strip().split("\n"))
162+
if answers == solution:
163163
status = "ok"
164164
else:
165165
status = "error"
@@ -169,7 +169,13 @@ def run(
169169
else:
170170
status = "unknown"
171171

172-
return {"elapsed": elapsed, "status": status, "answers": answers}
172+
result = {"elapsed": elapsed, "status": status, "answers": answers}
173+
174+
with Path("run.log").open("at") as f:
175+
line = f"{datetime.now()} {lang} {cmd} {file.absolute()} {elapsed} {status} '{solution or ''}' '{answers}'"
176+
print(line, file=f)
177+
178+
return result
173179

174180

175181
def make(year: Path, source: Path, dest: Path, cmd: str):
@@ -314,7 +320,7 @@ def run_day(
314320

315321
status_color = {"missing": MAGENTA, "unknown": GRAY, "error": RED, "ok": GREEN}[e["status"]]
316322

317-
answers = e["answers"].split("\n")
323+
answers = e["answers"]
318324

319325
line = (
320326
f"{CR}{RESET}{CLEAR_EOL}"
@@ -334,7 +340,7 @@ def run_day(
334340
if not in_cache and e["elapsed"] / 1e9 > 5:
335341
save_cache()
336342

337-
results.add(" ".join(answers))
343+
results.add(answers)
338344

339345
elapsed[lang].append(e["elapsed"] / 1e9)
340346

@@ -389,7 +395,7 @@ def install_venv(interpreter: Path):
389395

390396
slug = subprocess.check_output([interpreter, "-c", slug]).decode().strip()
391397

392-
venv = "." + slug.lower()
398+
venv = f".venv/{slug.lower()}"
393399

394400
# subprocess.check_call([interpreter, "-mensurepip"])
395401
subprocess.check_output([interpreter, "-mvenv", venv])

0 commit comments

Comments
 (0)