Skip to content

Commit

Permalink
improved language support
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-d committed Feb 3, 2024
1 parent c63bbe1 commit 1080e92
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ input.txt

/build/
build/

.venv/
40 changes: 40 additions & 0 deletions scripts/allpython.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -euo pipefail

script_dir=$(realpath $(dirname $0))

i()
{
local v=$1

local b=$(echo $v | cut -f1 -d'a') # major.minor.micro
local m=$(echo $v | cut -f1-2 -d'.') # major.minor
local url=https://www.python.org/ftp/python/$b/Python-$v.tar.xz

rm -rf /tmp/Python-$v /opt/python/Python-$v
curl -sL $url | tar -C /tmp -xJ
cd /tmp/Python-$v
./configure --prefix=/opt/python/Python-$v --enable-optimizations --disable-test-modules
make -j$(nproc --ignore=1)
make altinstall
# /opt/python/Python-$v/bin/python$m -mensurepip
cd /tmp
rm -rf /tmp/Python-$v

$script_dir/runall.py --venv /opt/python/Python-$v/bin/python$m
}

a()
{
i 3.10.13
i 3.11.6
i 3.12.1
# i 3.13.0a3
}

if [ ${1-} ]; then
i $1
else
a
fi
32 changes: 19 additions & 13 deletions scripts/runall.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import typing as t
from collections import defaultdict
from copy import deepcopy
from datetime import timedelta
from datetime import timedelta, datetime
from operator import itemgetter
from pathlib import Path
from zlib import crc32
Expand Down Expand Up @@ -41,11 +41,11 @@
INTERPRETERS = {
"Python": {
"Python": "python3",
"PyPy": ".pypy3.10/bin/python",
"Py3.10": ".py3.10/bin/python",
"Py3.11": ".py3.11/bin/python",
"Py3.12": ".py3.12/bin/python",
"Py3.13": ".py3.13/bin/python",
"PyPy": ".venv/pypy3.10/bin/python",
"Py3.10": ".venv/py3.10/bin/python",
"Py3.11": ".venv/py3.11/bin/python",
"Py3.12": ".venv/py3.12/bin/python",
"Py3.13": ".venv/py3.13/bin/python",
}
}

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

status = "unknown"
if solution:
solution = solution.read_text()
if answers == solution.strip():
solution = " ".join(solution.read_text().strip().split("\n"))
if answers == solution:
status = "ok"
else:
status = "error"
Expand All @@ -169,7 +169,13 @@ def run(
else:
status = "unknown"

return {"elapsed": elapsed, "status": status, "answers": answers}
result = {"elapsed": elapsed, "status": status, "answers": answers}

with Path("run.log").open("at") as f:
line = f"{datetime.now()} {lang} {cmd} {file.absolute()} {elapsed} {status} '{solution or ''}' '{answers}'"
print(line, file=f)

return result


def make(year: Path, source: Path, dest: Path, cmd: str):
Expand Down Expand Up @@ -314,7 +320,7 @@ def run_day(

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

answers = e["answers"].split("\n")
answers = e["answers"]

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

results.add(" ".join(answers))
results.add(answers)

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

Expand Down Expand Up @@ -389,7 +395,7 @@ def install_venv(interpreter: Path):

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

venv = "." + slug.lower()
venv = f".venv/{slug.lower()}"

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

0 comments on commit 1080e92

Please sign in to comment.