bite-check 0.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bite.py +817 -0
- bite_check-0.4.1.dist-info/METADATA +194 -0
- bite_check-0.4.1.dist-info/RECORD +9 -0
- bite_check-0.4.1.dist-info/WHEEL +5 -0
- bite_check-0.4.1.dist-info/entry_points.txt +2 -0
- bite_check-0.4.1.dist-info/licenses/LICENSE +21 -0
- bite_check-0.4.1.dist-info/top_level.txt +3 -0
- recent.py +1060 -0
- repo.py +104 -0
repo.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Shared helpers for recent.py: git, finding the repo, and reading the settings file (.bite.ini)."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import re
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
11
|
+
import bite # noqa: E402
|
|
12
|
+
|
|
13
|
+
CODE_SUFFIXES = {".py", ".pyw", ".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx", ".mts", ".cts", ".go", ".rs", ".rb",
|
|
14
|
+
".java", ".kt", ".kts", ".scala", ".c", ".h", ".cc", ".cpp", ".cxx", ".hpp", ".hh", ".cs", ".fs",
|
|
15
|
+
".php", ".swift", ".m", ".mm", ".gd", ".lua", ".ex", ".exs", ".erl", ".clj", ".dart", ".vue",
|
|
16
|
+
".svelte", ".r", ".jl", ".zig", ".nim", ".ml", ".hs", ".pl", ".pm"}
|
|
17
|
+
# What each kind of test runner can exercise. A runner only notices changes in its own language: pytest can't
|
|
18
|
+
# notice a TypeScript change going, so taking one out and seeing pytest pass says nothing about it.
|
|
19
|
+
RUNNERS = [("Python", {"pytest", "py.test", "python", "python3", "py", "tox", "nox", "unittest", "hatch"},
|
|
20
|
+
{".py", ".pyw", ".pyx", ".pxd"}),
|
|
21
|
+
("JavaScript or TypeScript", {"npm", "npx", "yarn", "pnpm", "node", "bun", "deno", "jest", "vitest", "mocha"},
|
|
22
|
+
{".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx", ".mts", ".cts", ".vue", ".svelte"}),
|
|
23
|
+
("Rust", {"cargo"}, {".rs"}),
|
|
24
|
+
("Go", {"go"}, {".go"}),
|
|
25
|
+
(".NET", {"dotnet"}, {".cs", ".fs"})]
|
|
26
|
+
COPY_IGNORE = [".git", "__pycache__", "node_modules", ".venv", "venv", ".tox", ".nox", ".mypy_cache",
|
|
27
|
+
".pytest_cache", ".ruff_cache", ".hypothesis"]
|
|
28
|
+
class ConfigError(Exception):
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# ---- git -----------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
def git(root, *args, raw=False):
|
|
35
|
+
r = subprocess.run(["git", *args], cwd=root, capture_output=True)
|
|
36
|
+
if r.returncode != 0:
|
|
37
|
+
return None
|
|
38
|
+
return r.stdout if raw else r.stdout.decode("utf-8", "replace").strip()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def repo_root(start) -> Path | None:
|
|
42
|
+
top = git(start, "rev-parse", "--show-toplevel")
|
|
43
|
+
return Path(top).resolve() if top else None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def state_dir(root: Path) -> Path:
|
|
47
|
+
d = Path(git(root, "rev-parse", "--absolute-git-dir") or root / ".git") / "bite"
|
|
48
|
+
d.mkdir(parents=True, exist_ok=True)
|
|
49
|
+
return d
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def load_cfg(root: Path):
|
|
53
|
+
ini = Path(os.environ["BITE_CONFIG"]) if os.environ.get("BITE_CONFIG") else root / ".bite.ini"
|
|
54
|
+
if ini.is_file() and not re.search(r"(?m)^\s*\[kit\]\s*$", ini.read_text(encoding="utf-8", errors="replace")):
|
|
55
|
+
raise ConfigError(f"{ini.name} has no [kit] section, so none of its settings are read. "
|
|
56
|
+
"Put [kit] on the first line.")
|
|
57
|
+
if not ini.is_file():
|
|
58
|
+
ini = state_dir(root) / "auto.ini"
|
|
59
|
+
ini.write_text("[kit]\n"
|
|
60
|
+
f"project_folder = {root}\n"
|
|
61
|
+
f"test_command = {bite.guess_test_command(root)}\n"
|
|
62
|
+
f"bite_copy_ignore = {', '.join(COPY_IGNORE)}\n"
|
|
63
|
+
"planted_bugs = 4\nplanted_bugs_seconds = 120\ntest_timeout_seconds = 300\n", encoding="utf-8")
|
|
64
|
+
cfg = bite.Config(ini)
|
|
65
|
+
cfg.project = root
|
|
66
|
+
for name in COPY_IGNORE:
|
|
67
|
+
if name not in cfg.copy_ignore:
|
|
68
|
+
cfg.copy_ignore.append(name)
|
|
69
|
+
if (root / "node_modules").is_dir():
|
|
70
|
+
# Node looks for node_modules in the folders above a file: a copy made inside node_modules/ finds the
|
|
71
|
+
# project's packages without copying them (node_modules itself is left out of every copy).
|
|
72
|
+
tmp = root / "node_modules" / ".bite_tmp"
|
|
73
|
+
tmp.mkdir(exist_ok=True)
|
|
74
|
+
tempfile.tempdir = str(tmp)
|
|
75
|
+
return cfg
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def is_setup(rel: str, cfg) -> bool:
|
|
79
|
+
import fnmatch
|
|
80
|
+
name = rel.rsplit("/", 1)[-1]
|
|
81
|
+
return name in cfg.test_cmd or any(fnmatch.fnmatch(rel.lower(), g.lower()) or fnmatch.fnmatch(name.lower(), g.lower())
|
|
82
|
+
for g in cfg.test_setup)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def runs_language(cmd: str) -> tuple[str, set]:
|
|
86
|
+
"""The language a test command runs and its file endings, or ("", set()) when it isn't plainly one runner
|
|
87
|
+
(make, a script, Unity, or a mix): then Bite can't tell, and every code change is checked."""
|
|
88
|
+
words = {re.sub(r"(?i)(\.exe|[\d.]+)$", "", w.rsplit("/", 1)[-1].rsplit("\\", 1)[-1].lower())
|
|
89
|
+
for w in re.split(r"[\s\"'&|;()]+", cmd) if w}
|
|
90
|
+
hits = [(lang, sufs) for lang, names, sufs in RUNNERS if words & names]
|
|
91
|
+
return hits[0] if len(hits) == 1 else ("", set())
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# ---- the check -----------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
def failure_excerpt(out: str, n: int = 12) -> str:
|
|
97
|
+
"""The lines that say what failed (assertion, expected/actual, error), not the stack around them."""
|
|
98
|
+
import re
|
|
99
|
+
lines = out.splitlines()
|
|
100
|
+
hits = [i for i, ln in enumerate(lines) if re.search(r"not ok|FAIL|Error|[Ee]xpected|[Aa]ctual|assert|panicked|!=", ln)]
|
|
101
|
+
if not hits:
|
|
102
|
+
return "\n".join(lines[-n:])
|
|
103
|
+
keep = sorted({j for i in hits for j in (i, i + 1) if j < len(lines)})[:n]
|
|
104
|
+
return "\n".join(lines[j] for j in keep)
|