doc-reference check
Browse files
scripts/test_doc_references.py
CHANGED
|
@@ -53,16 +53,30 @@ def main() -> int:
|
|
| 53 |
+ (f"; MISSING {missing[:4]}" if missing else ""))
|
| 54 |
|
| 55 |
# ...and the published scripts must not point at one person's disk
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
scripts = sorted(f for f in files if f.startswith("scripts/") and f.endswith(".py"))
|
| 57 |
-
hard = []
|
| 58 |
-
for
|
| 59 |
-
text = Path(hf_hub_download(REPO,
|
| 60 |
local_dir=d)).read_text(errors="ignore")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
for m in ABS_RE.findall(text):
|
| 62 |
-
hard.append(f"{
|
| 63 |
-
check(not hard
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# ...and the path module they share is published, since they import it
|
| 68 |
imports_paths = []
|
|
|
|
| 53 |
+ (f"; MISSING {missing[:4]}" if missing else ""))
|
| 54 |
|
| 55 |
# ...and the published scripts must not point at one person's disk
|
| 56 |
+
# react_paths.py is the ONE place a default may live, and only as the
|
| 57 |
+
# fallback of an environment lookup. Exempting it wholesale would let a
|
| 58 |
+
# literal creep back in beside the documented ones, so the exemption is
|
| 59 |
+
# narrowed: every absolute path in that file must sit on a line that reads
|
| 60 |
+
# the environment.
|
| 61 |
scripts = sorted(f for f in files if f.startswith("scripts/") and f.endswith(".py"))
|
| 62 |
+
hard, loose = [], []
|
| 63 |
+
for s_ in scripts:
|
| 64 |
+
text = Path(hf_hub_download(REPO, s_, repo_type="dataset",
|
| 65 |
local_dir=d)).read_text(errors="ignore")
|
| 66 |
+
if s_ == "scripts/react_paths.py":
|
| 67 |
+
for line in text.splitlines():
|
| 68 |
+
if ABS_RE.search(line) and "os.environ" not in line \
|
| 69 |
+
and not line.lstrip().startswith(("#", "_DEF_")):
|
| 70 |
+
loose.append(line.strip()[:70])
|
| 71 |
+
continue
|
| 72 |
for m in ABS_RE.findall(text):
|
| 73 |
+
hard.append(f"{s_}: {m}")
|
| 74 |
+
check(not hard and not loose,
|
| 75 |
+
"only react_paths.py holds a default path, behind the environment",
|
| 76 |
+
f"{len(scripts)} scripts: {len(scripts)-1} with no absolute path, and "
|
| 77 |
+
f"react_paths.py's defaults all sit behind os.environ.get"
|
| 78 |
+
+ (f"; hard-coded {hard[:3]}" if hard else "")
|
| 79 |
+
+ (f"; loose in react_paths {loose[:2]}" if loose else ""))
|
| 80 |
|
| 81 |
# ...and the path module they share is published, since they import it
|
| 82 |
imports_paths = []
|