Skip to content

Commit 1acdf7e

Browse files
committed
ENH: Poison deprecated doxygen aliases and add a migration script
The deprecated \doxygen/\subdoxygen aliases now render an inline "error: deprecated ... alias" marker ahead of the still-working reference, steering remote modules and out-of-tree consumers to Utilities/ITKMigrationPreparation/update_doxygen_for_itkv6.py.
1 parent 982c273 commit 1acdf7e

2 files changed

Lines changed: 88 additions & 3 deletions

File tree

Utilities/Doxygen/DoxygenConfig.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ set(
2020
# Two names, not one overloaded alias: the Software Guide mirrors them as plain LaTeX \newcommands.
2121
"itkref{1}=\\ref \\1"
2222
"itksubref{2}=\\ref itk::\\1::\\2"
23-
# Deprecated spellings of \itkref / \itksubref, kept for external tools and out-of-tree code.
24-
"doxygen{1}=\\ref \\1"
25-
"subdoxygen{2}=\\ref itk::\\1::\\2"
23+
# Deprecated spellings of \itkref / \itksubref: the link still renders, prefixed by a visible error.
24+
"doxygen{1}=error: deprecated \\\\doxygen alias, run Utilities/ITKMigrationPreparation/update_doxygen_for_itkv6.py to update to \\\\itkref. \\ref \\1"
25+
"subdoxygen{2}=error: deprecated \\\\subdoxygen alias, run Utilities/ITKMigrationPreparation/update_doxygen_for_itkv6.py to update to \\\\itksubref. \\ref itk::\\1::\\2"
2626
"sphinx=\\par ITK Sphinx Examples: ^^ \\li <a href=\\\"https://itk.org/ITKExamples\\\">All ITK Sphinx Examples</a> ^^"
2727
"sphinxexample{2}=\\li <a href=\\\"https://itk.org/ITKExamples/src/\\1/Documentation.html\\\">\\2</a> ^^"
2828
"endsphinx=^^ ^^ ^^"
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
"""Rewrite deprecated Doxygen aliases to their ITKv6 spellings.
3+
4+
Replaces the deprecated ``doxygen``/``subdoxygen`` ITK Doxygen aliases with
5+
``itkref``/``itksubref`` across a source tree. Run from the root of any
6+
project whose documentation uses them:
7+
8+
python3 update_doxygen_for_itkv6.py [--dry-run] [paths ...]
9+
"""
10+
11+
import argparse
12+
import re
13+
import sys
14+
from pathlib import Path
15+
16+
REPLACEMENTS = (
17+
(re.compile(r"\\doxygen\{"), r"\\itkref{"),
18+
(re.compile(r"\\subdoxygen\{"), r"\\itksubref{"),
19+
)
20+
21+
SUFFIXES = {
22+
".h",
23+
".hxx",
24+
".txx",
25+
".cxx",
26+
".cpp",
27+
".dox",
28+
".md",
29+
".rst",
30+
".tex",
31+
".py",
32+
".wrap",
33+
}
34+
35+
36+
def rewrite(path: Path, dry_run: bool) -> int:
37+
try:
38+
original = path.read_text(encoding="utf-8")
39+
except (UnicodeDecodeError, OSError):
40+
return 0
41+
text = original
42+
count = 0
43+
for pattern, replacement in REPLACEMENTS:
44+
text, n = pattern.subn(replacement, text)
45+
count += n
46+
if count and not dry_run:
47+
path.write_text(text, encoding="utf-8")
48+
return count
49+
50+
51+
def main() -> int:
52+
parser = argparse.ArgumentParser(description=__doc__)
53+
parser.add_argument(
54+
"paths", nargs="*", default=["."], help="files or directories to rewrite"
55+
)
56+
parser.add_argument(
57+
"--dry-run", action="store_true", help="report changes without writing"
58+
)
59+
args = parser.parse_args()
60+
61+
total = 0
62+
changed_files = 0
63+
for root in args.paths:
64+
root_path = Path(root)
65+
candidates = (
66+
[root_path]
67+
if root_path.is_file()
68+
else (p for p in root_path.rglob("*") if p.is_file())
69+
)
70+
for path in candidates:
71+
if path.suffix not in SUFFIXES or ".git" in path.parts:
72+
continue
73+
count = rewrite(path, args.dry_run)
74+
if count:
75+
changed_files += 1
76+
total += count
77+
print(
78+
f"{path}: {count} replacement(s){' (dry run)' if args.dry_run else ''}"
79+
)
80+
print(f"{total} replacement(s) in {changed_files} file(s)")
81+
return 0
82+
83+
84+
if __name__ == "__main__":
85+
sys.exit(main())

0 commit comments

Comments
 (0)