Remove unused documents.traces_for_lesson, overlay.wrap_rule_body and HOUSE_WIDTH; a test fails on any new dead function. done / next: fix 4 (down --until time)
This commit is contained in:
1 parent
b114b29221
commit
e34dabfdb0
3 files changed
+35
-29
No files matched your search
@@ -22,10 +22,6 @@ def check_rule_text(text, rid=None):
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def traces_for_lesson(lesson_id):
|
|
||||||
return [] # the per-lesson trace regime is retired; provenance lives on the learning record
|
|
||||||
|
|
||||||
|
|
||||||
def trace_lines(kind, entry_id):
|
def trace_lines(kind, entry_id):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ from . import paths
|
|||||||
# games must not load more text. A learning round still may not grow the book without shortening.
|
# games must not load more text. A learning round still may not grow the book without shortening.
|
||||||
MAX_LINES = 200
|
MAX_LINES = 200
|
||||||
MAX_CHARS = 12000
|
MAX_CHARS = 12000
|
||||||
HOUSE_WIDTH = 100
|
|
||||||
KINDS = ("rule", "verifier", "recipe")
|
KINDS = ("rule", "verifier", "recipe")
|
||||||
ID_TAIL = re.compile(r"\s*\{#([A-Za-z0-9][A-Za-z0-9_-]*)\}\s*$")
|
ID_TAIL = re.compile(r"\s*\{#([A-Za-z0-9][A-Za-z0-9_-]*)\}\s*$")
|
||||||
NUM = re.compile(r"^\d+\.\s+")
|
NUM = re.compile(r"^\d+\.\s+")
|
||||||
@@ -98,30 +97,6 @@ def rule_text(r):
|
|||||||
return "## %s\n\n%s\n" % (r["title"], r["body"])
|
return "## %s\n\n%s\n" % (r["title"], r["body"])
|
||||||
|
|
||||||
|
|
||||||
def wrap_rule_body(body, width=HOUSE_WIDTH):
|
|
||||||
"""Re-wrap rule prose to the house width, preserving paragraphs, bullets and code fences."""
|
|
||||||
import textwrap
|
|
||||||
out, in_fence = [], False
|
|
||||||
for line in (body or "").split("\n"):
|
|
||||||
if line.strip().startswith("```"):
|
|
||||||
in_fence = not in_fence
|
|
||||||
out.append(line)
|
|
||||||
continue
|
|
||||||
if in_fence or not line.strip():
|
|
||||||
out.append(line)
|
|
||||||
continue
|
|
||||||
stripped = line.lstrip()
|
|
||||||
indent = ""
|
|
||||||
if stripped.startswith(("- ", "* ")):
|
|
||||||
indent = " "
|
|
||||||
elif re.match(r"^\d+\.\s", stripped):
|
|
||||||
indent = " "
|
|
||||||
wrapped = textwrap.wrap(line, width=width, subsequent_indent=indent,
|
|
||||||
break_long_words=False, break_on_hyphens=False)
|
|
||||||
out.extend(wrapped or [""])
|
|
||||||
return "\n".join(out).strip("\n")
|
|
||||||
|
|
||||||
|
|
||||||
def _read(p):
|
def _read(p):
|
||||||
with open(p, encoding="utf-8") as f:
|
with open(p, encoding="utf-8") as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
"""Nothing in sisi/ is defined and never called: a function or class whose name appears nowhere else in the
|
||||||
|
product (sisi/, bin/, tools/) is dead code, and a test of it only keeps it alive."""
|
||||||
|
import ast, collections, glob, os, re, unittest
|
||||||
|
|
||||||
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
# Seams that are documented and exercised by real-behaviour tests (docs/evaluation.md); keep them.
|
||||||
|
SEAMS = {"validate_check", "capture_case", "compare_for_candidate"}
|
||||||
|
|
||||||
|
|
||||||
|
def _files():
|
||||||
|
out = glob.glob(os.path.join(ROOT, "sisi", "*.py")) + glob.glob(os.path.join(ROOT, "bin", "*"))
|
||||||
|
out += [f for f in glob.glob(os.path.join(ROOT, "tools", "**", "*"), recursive=True) if os.path.isfile(f)]
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
class NoDeadCode(unittest.TestCase):
|
||||||
|
def test_every_function_and_class_in_sisi_is_referenced_somewhere(self):
|
||||||
|
text = ""
|
||||||
|
for f in _files():
|
||||||
|
try:
|
||||||
|
text += open(f, encoding="utf-8").read() + "\n"
|
||||||
|
except (OSError, UnicodeDecodeError):
|
||||||
|
pass
|
||||||
|
words = collections.Counter(re.findall(r"\w+", text))
|
||||||
|
dead = []
|
||||||
|
for f in sorted(glob.glob(os.path.join(ROOT, "sisi", "*.py"))):
|
||||||
|
for n in ast.walk(ast.parse(open(f, encoding="utf-8").read())):
|
||||||
|
if isinstance(n, (ast.FunctionDef, ast.ClassDef)) and not n.name.startswith("__") \
|
||||||
|
and n.name not in SEAMS and words[n.name] <= 1:
|
||||||
|
dead.append("%s:%s" % (os.path.basename(f), n.name))
|
||||||
|
self.assertEqual(dead, [])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user