Skip to content

Commit

Permalink
ENH: Convert to python itkgroup script
Browse files Browse the repository at this point in the history
  • Loading branch information
blowekamp committed Jan 23, 2025
1 parent 327e31d commit b51939b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 103 deletions.
7 changes: 2 additions & 5 deletions Utilities/Doxygen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,9 @@ mark_as_advanced(
ITK_DOXYGEN_XML
ITK_DOXYGEN_SERVER_BASED_SEARCH)

find_package(Perl)
if(Python3_EXECUTABLE)
set(ITK_DOXYGEN_INPUT_FILTER "${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/itkgroup.py")

if(PERL_FOUND)
set(ITK_DOXYGEN_INPUT_FILTER "${PERL_EXECUTABLE} ${ITK_BINARY_DIR}/Utilities/Doxygen/itkdoxygen.pl")

configure_file(${ITK_SOURCE_DIR}/Utilities/Doxygen/itkdoxygen.pl.in ${ITK_BINARY_DIR}/Utilities/Doxygen/itkdoxygen.pl)
else()
set(ITK_DOXYGEN_INPUT_FILTER)
endif()
Expand Down
9 changes: 0 additions & 9 deletions Utilities/Doxygen/itkdoxygen.pl.in

This file was deleted.

89 changes: 0 additions & 89 deletions Utilities/Doxygen/itkgroup.pl

This file was deleted.

81 changes: 81 additions & 0 deletions Utilities/Doxygen/itkgroup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python
#
# Copyright NumFOCUS
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Add Doxygen grouping markers to a doxygen comment block, until an empty line is found. This groups multiple
# functions/variables not separated by a newline, into a single doxygen group with the same doxygen comment.


import re
import sys

ingroup = False
semicount = 0
endbracecount = 0
endparencount = 0
leading_space = " "
savebuffer = ""


def process_line(line: str):
global ingroup, semicount, endbracecount, endparencount, leading_space, savebuffer

line = line.rstrip()
if re.search(r"\S+", line):
match = re.search(r"/\*\*(.*)", line)
if match:
if ingroup:
print(f"{leading_space}/**{savebuffer}")
if re.search(r"(\\class|\\brief)", line):
print(line)
else:
savebuffer = f"{match.group(1)}\n"
ingroup = True
semicount = 0
endbracecount = 0
endparencount = 0
leading_space = re.match(r"(^\s*)", line).group(1)
else:
if ingroup:
savebuffer += f"{line}\n"
else:
print(line)
if re.search(r";", line):
semicount += 1
if re.search(r"\}", line):
endbracecount += 1
if re.search(r"\)", line):
endparencount += 1
else:
if ingroup:
if endparencount > 1 and (semicount > 1 or endbracecount > 1):
print(f"{leading_space}/**@{{{savebuffer}{leading_space}/**@}}*/\n")
else:
print(f"{leading_space}/**{savebuffer}")
savebuffer = ""
ingroup = False
else:
print(line)


if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python itkgroup.py <filename>")
sys.exit(1)

filename = sys.argv[1]
with open(filename) as file:
for line in file:
process_line(line)

0 comments on commit b51939b

Please sign in to comment.