mirror of
https://github.com/thib8956/advent-of-code.git
synced 2026-07-06 15:48:16 +00:00
update aoc helper
This commit is contained in:
+3
-5
@@ -1,6 +1,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from adventofcode.helper import init, run, run_all
|
from adventofcode.helper import init, run, run_all, validate_year
|
||||||
|
|
||||||
|
|
||||||
def year_or_all(value):
|
def year_or_all(value):
|
||||||
@@ -9,12 +9,10 @@ def year_or_all(value):
|
|||||||
return value
|
return value
|
||||||
try:
|
try:
|
||||||
year = int(value)
|
year = int(value)
|
||||||
if 2015 <= year <= 2025:
|
if (err := validate_year(year)) is None:
|
||||||
return year
|
return year
|
||||||
else:
|
else:
|
||||||
raise argparse.ArgumentTypeError(
|
raise argparse.ArgumentTypeError(err)
|
||||||
f"Year must be between 2015 and 2025. Got: {year}"
|
|
||||||
)
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise argparse.ArgumentTypeError(
|
raise argparse.ArgumentTypeError(
|
||||||
f"Invalid value: {value}. Must be an integer or 'all'."
|
f"Invalid value: {value}. Must be an integer or 'all'."
|
||||||
|
|||||||
+10
-4
@@ -20,7 +20,7 @@ def main(inp):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
with fileinput.input() as f:
|
with fileinput.input() as f:
|
||||||
lines = [x.rstrip() for x in fileinput.input()]
|
lines = [x.rstrip() for x in f]
|
||||||
main(lines)
|
main(lines)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -169,16 +169,22 @@ def run(year, day):
|
|||||||
|
|
||||||
def run_day(script_path, input_path):
|
def run_day(script_path, input_path):
|
||||||
try:
|
try:
|
||||||
print(f"> running {script_path}")
|
print(f"> running {script_path}\n")
|
||||||
start = time.time()
|
start = time.time()
|
||||||
res = subprocess.run(
|
res = subprocess.run(
|
||||||
[sys.executable, script_path.absolute(), input_path.absolute()],
|
[sys.executable, script_path.absolute(), input_path.absolute()],
|
||||||
check=True,
|
check=False,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
timeout=30,
|
timeout=30,
|
||||||
)
|
)
|
||||||
elapsed = time.time() - start
|
elapsed = time.time() - start
|
||||||
|
if res.returncode != 0:
|
||||||
|
print(
|
||||||
|
f"> {script_path} failed with exit code {res.returncode}",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
else:
|
||||||
print(res.stdout.decode())
|
print(res.stdout.decode())
|
||||||
print(f"> ran {script_path} in {elapsed:.3f}s")
|
print(f"\n> ran {script_path} in {elapsed:.3f}s")
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
print(f"> timeout {script_path} after 30s", file=sys.stderr)
|
print(f"> timeout {script_path} after 30s", file=sys.stderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user