[WIP] Programmatically update README with results
This commit is contained in:
parent
012480f7a3
commit
5a03b3b133
@ -1,7 +1,14 @@
|
|||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import PIPE, run
|
from subprocess import PIPE, STDOUT, run
|
||||||
|
|
||||||
|
from pytablewriter import MarkdownTableWriter
|
||||||
|
from pytablewriter.style import Style
|
||||||
|
|
||||||
|
|
||||||
def read_md():
|
def read_md():
|
||||||
"""
|
"""
|
||||||
@ -11,49 +18,43 @@ def read_md():
|
|||||||
md = [line.strip() for line in f.readlines() if line.strip() != ""][1:]
|
md = [line.strip() for line in f.readlines() if line.strip() != ""][1:]
|
||||||
return md
|
return md
|
||||||
|
|
||||||
def write_md():
|
def write_md(results):
|
||||||
"""
|
"""
|
||||||
Write to README.md
|
Write to README.md
|
||||||
"""
|
"""
|
||||||
pass
|
with open("../dummy.md", "w") as f:
|
||||||
|
f.write(results)
|
||||||
|
|
||||||
def execute(num):
|
def execute():
|
||||||
"""
|
"""
|
||||||
Execute script and return output
|
Execute script and return output
|
||||||
"""
|
"""
|
||||||
# import sys
|
os.chdir(Path("Python/"))
|
||||||
# sys.path.insert(0, "./Python/")
|
scripts = sorted(glob("*[0-9].py"))
|
||||||
|
|
||||||
# from Python import Problem001
|
timings, results = [], []
|
||||||
|
|
||||||
# res = eval(f"Problem{num:0>3}.compute()")
|
|
||||||
# print(res)
|
|
||||||
# time = str(res).split(sep=" ")
|
|
||||||
# print(time)
|
|
||||||
scripts = sorted(Path("Python/").glob("*[0-9].py"))
|
|
||||||
# print(scripts[0].name)
|
|
||||||
for script in scripts:
|
for script in scripts:
|
||||||
run(["python3", f"{script}"])
|
_res = run(["python3", f"{script}"], capture_output=True, text=True).stdout.split("\n")
|
||||||
time.sleep(5)
|
timings.append(_res[0])
|
||||||
|
results.append(_res[2])
|
||||||
|
|
||||||
|
writer = MarkdownTableWriter(
|
||||||
|
table_name="Project Euler Solutions",
|
||||||
|
headers=["Problem #", "Result", "Execution time (Python)"],
|
||||||
|
value_matrix=[[int(t[25:27]), int(r[23:]), t[29:]] for t,r in zip(timings, results)],
|
||||||
|
column_styles=[
|
||||||
|
Style(align="center"),
|
||||||
|
Style(align="right", thousand_separator="_"),
|
||||||
|
Style(align="right"),
|
||||||
|
], # specify styles for each column
|
||||||
|
margin=1 # add a whitespace for both sides of each cell
|
||||||
|
)
|
||||||
|
writer.write_table()
|
||||||
|
return writer.dumps()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
md = read_md()
|
md = read_md()
|
||||||
execute(1)
|
# print(md)
|
||||||
|
res = execute()
|
||||||
|
write_md(res)
|
||||||
# for c in chunks:
|
|
||||||
# res = run(
|
|
||||||
# [
|
|
||||||
# "sbatch",
|
|
||||||
# "--parsable",
|
|
||||||
# "--dependency=afterok:" + ":".join(str(j) for j in images_nbs),
|
|
||||||
# "run2.sh",
|
|
||||||
# str(f"{c:02}"),
|
|
||||||
# your_path_for_notebooks.as_posix(),
|
|
||||||
# ],
|
|
||||||
# stdout=PIPE,
|
|
||||||
# check=True,
|
|
||||||
# cwd=Path("."),
|
|
||||||
# )
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user