mirror of
https://github.com/JonasunderscoreJones/epr_grader.git
synced 2025-10-28 17:49:18 +01:00
Ignoring a missing whitespace after : in a print command
This commit is contained in:
parent
995a0586be
commit
7333378967
1 changed files with 27 additions and 14 deletions
27
eprgrader.py
27
eprgrader.py
|
|
@ -129,6 +129,7 @@ PYCODESTYLE_SELECT = [
|
||||||
tmp_storage = {}
|
tmp_storage = {}
|
||||||
violations_checkers = {}
|
violations_checkers = {}
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def pylint_context(stdout, workdir):
|
def pylint_context(stdout, workdir):
|
||||||
"""Temporarily change stdout and working directory."""
|
"""Temporarily change stdout and working directory."""
|
||||||
|
|
@ -144,6 +145,7 @@ def pylint_context(stdout, workdir):
|
||||||
sys.path = tmp_storage['path']
|
sys.path = tmp_storage['path']
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = sys.__stdout__
|
||||||
|
|
||||||
|
|
||||||
def lint_files(folders, author_pairs, deduction: bool):
|
def lint_files(folders, author_pairs, deduction: bool):
|
||||||
"""Run pylint and pycodestyle on all Python files anywhere within `folders'."""
|
"""Run pylint and pycodestyle on all Python files anywhere within `folders'."""
|
||||||
count = 0
|
count = 0
|
||||||
|
|
@ -153,7 +155,8 @@ def lint_files(folders, author_pairs, deduction: bool):
|
||||||
for folder in folders:
|
for folder in folders:
|
||||||
count += 1
|
count += 1
|
||||||
print(f" ({str(count).rjust(len(str(total)))}/{total}) Checking {folder.name}")
|
print(f" ({str(count).rjust(len(str(total)))}/{total}) Checking {folder.name}")
|
||||||
pythons = list(map(pathlib.Path.resolve, filter(lambda p: "__MACOSX" not in p.parts, folder.glob('**/*.py'))))
|
pythons = list(map(pathlib.Path.resolve,
|
||||||
|
filter(lambda p: "__MACOSX" not in p.parts, folder.glob('**/*.py'))))
|
||||||
if not pythons:
|
if not pythons:
|
||||||
continue
|
continue
|
||||||
pycount = 0
|
pycount = 0
|
||||||
|
|
@ -161,7 +164,8 @@ def lint_files(folders, author_pairs, deduction: bool):
|
||||||
lintcache = io.StringIO()
|
lintcache = io.StringIO()
|
||||||
for file in pythons:
|
for file in pythons:
|
||||||
pycount += 1
|
pycount += 1
|
||||||
print(f" ({str(pycount).rjust(len(str(pytotal)))}/{pytotal}) Running pylint for {file.name}")
|
print(
|
||||||
|
f" ({str(pycount).rjust(len(str(pytotal)))}/{pytotal}) Running pylint for {file.name}")
|
||||||
with pylint_context(lintcache, folder):
|
with pylint_context(lintcache, folder):
|
||||||
try:
|
try:
|
||||||
RunPylint(PYLINT_ARGS + [str(file)])
|
RunPylint(PYLINT_ARGS + [str(file)])
|
||||||
|
|
@ -170,7 +174,8 @@ def lint_files(folders, author_pairs, deduction: bool):
|
||||||
print(f" [Pylint attempted to exit with code {e.code}]", file=sys.stderr)
|
print(f" [Pylint attempted to exit with code {e.code}]", file=sys.stderr)
|
||||||
raise RuntimeError from e
|
raise RuntimeError from e
|
||||||
pycount += 1
|
pycount += 1
|
||||||
print(f" ({str(pycount).rjust(len(str(pytotal)))}/{pytotal}) Running pycodestyle for {file.name}",
|
print(
|
||||||
|
f" ({str(pycount).rjust(len(str(pytotal)))}/{pytotal}) Running pycodestyle for {file.name}",
|
||||||
file=sys.__stdout__)
|
file=sys.__stdout__)
|
||||||
print('\n')
|
print('\n')
|
||||||
result = style.check_files([file])
|
result = style.check_files([file])
|
||||||
|
|
@ -231,6 +236,10 @@ def remove_unnecessary_violations(style_check: str):
|
||||||
# Allowing all module names
|
# Allowing all module names
|
||||||
elif "C0103" in line and "Module name" in line:
|
elif "C0103" in line and "Module name" in line:
|
||||||
continue
|
continue
|
||||||
|
# Ignoring a missing whitespace after : in a print command
|
||||||
|
elif "E231" in line and "after ':'" in line and "print(" in lines[i + 1]:
|
||||||
|
skip_count = 2
|
||||||
|
continue
|
||||||
filtered_lines.append(line)
|
filtered_lines.append(line)
|
||||||
return "\n".join(filtered_lines)
|
return "\n".join(filtered_lines)
|
||||||
|
|
||||||
|
|
@ -273,7 +282,8 @@ def begin_grading(folder: pathlib.Path, ratings_file: pathlib.Path, check_style:
|
||||||
with zipfile.ZipFile(file, 'r') as zip_obj:
|
with zipfile.ZipFile(file, 'r') as zip_obj:
|
||||||
# zip_obj.extractall(file.parent)
|
# zip_obj.extractall(file.parent)
|
||||||
safe_extract_zip(zip_obj, file.parent)
|
safe_extract_zip(zip_obj, file.parent)
|
||||||
target_folders = [f for f in itertools.chain.from_iterable((group.iterdir() for group in folder.glob('**/abgaben')))
|
target_folders = [f for f in itertools.chain.from_iterable(
|
||||||
|
(group.iterdir() for group in folder.glob('**/abgaben')))
|
||||||
if f.is_dir()]
|
if f.is_dir()]
|
||||||
if check_style:
|
if check_style:
|
||||||
print("Running style check...")
|
print("Running style check...")
|
||||||
|
|
@ -443,15 +453,18 @@ def update_rating(overall_rating_path: str, student_rating_path: str, student_na
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""The function main is where execution begins."""
|
"""The function main is where execution begins."""
|
||||||
print('EPRgrader v3/221031 running on ', datetime.now(), ' [', platform.platform(terse=True), ' ',
|
print('EPRgrader v3/221031 running on ', datetime.now(), ' [', platform.platform(terse=True),
|
||||||
|
' ',
|
||||||
platform.machine(), ']', sep='')
|
platform.machine(), ']', sep='')
|
||||||
parser = argparse.ArgumentParser(description="Assist in grading EPR assignments.")
|
parser = argparse.ArgumentParser(description="Assist in grading EPR assignments.")
|
||||||
# parser.add_argument('verb', type=str, choices=('begin', 'relint', 'finalise'))
|
# parser.add_argument('verb', type=str, choices=('begin', 'relint', 'finalise'))
|
||||||
parser.add_argument('-f', '--folder', type=str, help='the folder in which to operate (default: the current folder)',
|
parser.add_argument('-f', '--folder', type=str,
|
||||||
|
help='the folder in which to operate (default: the current folder)',
|
||||||
default='.')
|
default='.')
|
||||||
subparsers = parser.add_subparsers(metavar='verb', dest='verb', required=True)
|
subparsers = parser.add_subparsers(metavar='verb', dest='verb', required=True)
|
||||||
begin_parser = subparsers.add_parser('begin', help='begin a new grading process')
|
begin_parser = subparsers.add_parser('begin', help='begin a new grading process')
|
||||||
begin_parser.add_argument('--table', metavar='file', help='Ratings table file to copy to each folder',
|
begin_parser.add_argument('--table', metavar='file',
|
||||||
|
help='Ratings table file to copy to each folder',
|
||||||
required=True)
|
required=True)
|
||||||
begin_parser.add_argument('--stylecheck', action=argparse.BooleanOptionalAction, default=True,
|
begin_parser.add_argument('--stylecheck', action=argparse.BooleanOptionalAction, default=True,
|
||||||
help='whether or not to run style checks')
|
help='whether or not to run style checks')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue