Skip to content

Commit 2435161

Browse files
authored
Merge pull request #34 from benedictbrown/develop
added nocomments and verbatim passes
2 parents 68b038e + 0a3a515 commit 2435161

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

compare50/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __init__(self, option_strings, dest=argparse.SUPPRESS, default=argparse.SUPP
137137
def __call__(self, parser, namespace, values, option_string=None):
138138
indentation = " " * 4
139139
for pass_ in _data.Pass._get_all():
140-
print(str(pass_.__name__))
140+
print(str(pass_.__name__), f"(default: {'ON' if pass_.default else 'OFF'})")
141141
for line in textwrap.wrap(pass_.__doc__ or "No description provided", 80 - len(indentation)):
142142
print("{}{}".format(indentation, line))
143143
parser.exit()
@@ -307,7 +307,8 @@ def main():
307307
parser.add_argument("-p", "--passes",
308308
dest="passes",
309309
nargs="+",
310-
default=[pass_.__name__ for pass_ in _data.Pass._get_all()],
310+
default=[pass_.__name__ for pass_ in _data.Pass._get_all()
311+
if pass_.default],
311312
help="Specify which passes to use. compare50 ranks only by the first pass, but will render views for every pass.")
312313
parser.add_argument("-i", "--include",
313314
callback=submission_factory.include,

compare50/_data.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Pass(metaclass=_PassRegistry):
4343
"""
4444
__register = False
4545

46+
# Whether or not the pass should be enabled by default
47+
default = False
48+
4649
@abc.abstractmethod
4750
def preprocessors(self):
4851
pass

compare50/passes.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class structure(Pass):
1010
"""Compares code structure by removing whitespace and comments; normalizing variable names, string literals, and numeric literals; and then running the winnowing algorithm."""
11-
11+
default = True
1212
preprocessors = [preprocessors.strip_whitespace,
1313
preprocessors.strip_comments,
1414
preprocessors.normalize_identifiers,
@@ -20,16 +20,27 @@ class structure(Pass):
2020

2121
class exact(Pass):
2222
"""Removes all whitespace, then uses the winnowing algorithm to compare submissions."""
23+
default = True
2324
preprocessors = [preprocessors.split_on_whitespace,
2425
preprocessors.strip_whitespace]
2526
comparator = comparators.Winnowing(k=25, t=35)
2627

2728

2829
class misspellings(Pass):
2930
"""Compares comments for identically misspelled English words."""
30-
31+
default = True
3132
preprocessors = [preprocessors.comments,
3233
preprocessors.normalize_case,
3334
preprocessors.words]
3435
comparator = comparators.Misspellings(resource_filename("compare50.comparators",
3536
"english_dictionary.txt"))
37+
38+
class nocomments(Pass):
39+
"""Removes comments, but keeps whitespace, then uses the winnowing algorithm to compare submissions"""
40+
preprocessors = [preprocessors.strip_comments, preprocessors.split_on_whitespace]
41+
comparator = comparators.Winnowing(k=25, t=35)
42+
43+
class verbatim(Pass):
44+
"""Removes nothing, not even whitespace, then uses the winnowing algorithm to compare submissions"""
45+
preprocessors = []
46+
comparator = comparators.Winnowing(k=25, t=35)

0 commit comments

Comments
 (0)