Add rule for missing placeholders in f-strings
This commit is contained in:
parent
81e0913656
commit
224ac76556
5
.flake8
Normal file
5
.flake8
Normal file
@ -0,0 +1,5 @@
|
||||
[flake8]
|
||||
ignore = E203, E266, E501, W503, F403, F401, F541
|
||||
max-line-length = 89
|
||||
max-complexity = 18
|
||||
select = B,C,E,F,W,T4,B9
|
@ -1,9 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from glob import glob
|
||||
from pathlib import Path
|
||||
from subprocess import PIPE, STDOUT, run
|
||||
from subprocess import run
|
||||
|
||||
from pytablewriter import MarkdownTableWriter
|
||||
from pytablewriter.style import Style
|
||||
@ -22,8 +19,13 @@ def write_md(results):
|
||||
"""
|
||||
Write to README.md
|
||||
"""
|
||||
with open("../README.md", "a") as f:
|
||||
# f.write(str(results))
|
||||
initial_message = (
|
||||
f"Having a bit of fun trying to solve the problems from "
|
||||
f"https://projecteuler.net/archives using different programming "
|
||||
f"languages for learning purposes.\n\n"
|
||||
)
|
||||
with open("../README.md", "w") as f:
|
||||
f.write(initial_message)
|
||||
results.stream = f
|
||||
results.write_table()
|
||||
|
||||
@ -49,7 +51,6 @@ def timing_Python(path=None, exec_only=1):
|
||||
os.chdir(Path(path))
|
||||
python_timings, python_results = [], []
|
||||
for script in scripts[:exec_only]:
|
||||
# print(f"Executing {script}")
|
||||
_res = run(
|
||||
["python3", f"{script}"], capture_output=True, text=True
|
||||
).stdout.split("\n")
|
||||
@ -66,7 +67,6 @@ def timing_Julia(path=None, exec_only=1):
|
||||
os.chdir(Path(path))
|
||||
julia_problem_numbers, julia_timings, julia_results = [], [], []
|
||||
for script in scripts[:exec_only]:
|
||||
# print(f"Executing {script}")
|
||||
_res = run(["julia", f"{script}"], capture_output=True, text=True).stdout.split(
|
||||
"\n"
|
||||
)
|
||||
@ -90,15 +90,11 @@ def execute(combine_columns=True, nproblems=-1):
|
||||
assert len(python_timings) == len(julia_timings)
|
||||
|
||||
not_equal = []
|
||||
for i, (pr, jr) in enumerate(zip(python_results, julia_results), start=1):
|
||||
# print(f"Results for problem {i} are equal? {int(pr[22:]) == int(jr[23:])}")
|
||||
if not int(pr[22:]) == int(jr[23:]):
|
||||
not_equal.append(i)
|
||||
# try:
|
||||
# int(pr[22:]) == int(jr[23:])
|
||||
# except ValueError:
|
||||
# print(f"Results for problem {i} are not identical!\n")
|
||||
# continue
|
||||
for nproblem, (python_res, julia_res) in enumerate(
|
||||
zip(python_results, julia_results), start=1
|
||||
):
|
||||
if not int(python_res[22:]) == int(julia_res[23:]):
|
||||
not_equal.append([nproblem, int(python_res[22:]), int(julia_res[23:])])
|
||||
|
||||
if combine_columns:
|
||||
headers = [
|
||||
@ -113,8 +109,13 @@ def execute(combine_columns=True, nproblems=-1):
|
||||
python_timings, python_results, julia_timings
|
||||
)
|
||||
]
|
||||
discrepancies = [
|
||||
f"\nDiscrepancies in problem {npb}. "
|
||||
f"Python result is {py_r} and in Julia is {jl_r}."
|
||||
for npb, py_r, jl_r in not_equal
|
||||
]
|
||||
writer_comb = MarkdownTableWriter(
|
||||
table_name=f"Results for problems {not_equal} are not correct",
|
||||
table_name="\n".join(discrepancies),
|
||||
headers=headers,
|
||||
value_matrix=value_matrix,
|
||||
column_styles=[
|
||||
@ -126,8 +127,6 @@ def execute(combine_columns=True, nproblems=-1):
|
||||
margin=1, # add a whitespace for both sides of each cell
|
||||
)
|
||||
writer_comb.set_indent_level(3)
|
||||
writer_comb.write_table()
|
||||
writer_comb.write_null_line()
|
||||
|
||||
return writer_comb
|
||||
|
||||
@ -161,15 +160,13 @@ def execute(combine_columns=True, nproblems=-1):
|
||||
], # specify styles for each column
|
||||
margin=1, # add a whitespace for both sides of each cell
|
||||
)
|
||||
writer.write_table()
|
||||
writer.write_null_line()
|
||||
|
||||
return writer
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
md = read_md()
|
||||
# md = read_md()
|
||||
# print(md)
|
||||
res = execute(combine_columns=True, nproblems=-1)
|
||||
# print(res)
|
||||
# write_md(res)
|
||||
write_md(res)
|
||||
|
Loading…
Reference in New Issue
Block a user