diff --git a/Utilities/Doxygen/CMakeLists.txt b/Utilities/Doxygen/CMakeLists.txt index 05d96781209..3f56ffbe320 100644 --- a/Utilities/Doxygen/CMakeLists.txt +++ b/Utilities/Doxygen/CMakeLists.txt @@ -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() diff --git a/Utilities/Doxygen/itkdoxygen.pl.in b/Utilities/Doxygen/itkdoxygen.pl.in deleted file mode 100644 index f5c6f2a870a..00000000000 --- a/Utilities/Doxygen/itkdoxygen.pl.in +++ /dev/null @@ -1,9 +0,0 @@ -# for vxl files run the vxl_doxy.pl script, and use itkgroup.pl for all other files -if ( $ARGV[0] =~ /(vxl|vcl|vnl)/) -{ - system ("perl @ITK_SOURCE_DIR@/Utilities/Doxygen/vxl_doxy.pl $ARGV[0]"); -} -else -{ - system ("perl @ITK_SOURCE_DIR@/Utilities/Doxygen/itkgroup.pl $ARGV[0]"); -} diff --git a/Utilities/Doxygen/itkgroup.pl b/Utilities/Doxygen/itkgroup.pl deleted file mode 100644 index 1e669538635..00000000000 --- a/Utilities/Doxygen/itkgroup.pl +++ /dev/null @@ -1,89 +0,0 @@ -# if regular doxycomment add a @{ -# at next empty line add a //@} - -$ingroup = 0; -$semicount =0; -$endbracecount = 0; -$endparencount = 0; -$leading_space = " "; -while(<>) -{ - chomp; - $line = $_; - # if the line is not an empty line - if( $line =~ /\S+/ ) - { - if ( /\/\*\*(.*)/ ) - { - # I guess it was not a group, dump savebuffer - if($ingroup) - { - print $leading_space . "/**" . $savebuffer . "\n"; - } - # if it is a class or brief then output the line but - # do not start a group - if ( /(\\class|\\brief)/ ) - { - print $line . "\n"; - } - # must be a group so start saving - else - { - - $savebuffer = "$1" . "\n"; - $ingroup = 1; - $semicount = 0; - $endbracecount = 0; - $endparencount = 0; - - $line =~ /(^\s*)/; - $leading_space = $1; - } - } - else - { - # add to save buffer if in group - if($ingroup) - { - $savebuffer = $savebuffer . $_ . "\n"; - } - else - { - # non empty line that is not the start of a doxy comment - print $_ . "\n"; - } - } - if($line =~ /;/ ) - { - $semicount = $semicount + 1; - } - if($line =~ /\}/ ) - { - $endbracecount = $endbracecount + 1; - } - if($line =~ /\)/ ) - { - $endparencount = $endparencount + 1; - } - } - else - { - if($ingroup) - { - if($endparencount > 1 && ($semicount > 1 || $endbracecount > 1)) - { - print $leading_space . "/**@\{" . $savebuffer . $leading_space . "/**@}*/\n\n"; - } - else - { - print $leading_space . "/**" . $savebuffer . "\n"; - } - $savebuffer = ""; - $ingroup = 0; - } - else - { - print $line . "\n"; - } - } -} diff --git a/Utilities/Doxygen/itkgroup.py b/Utilities/Doxygen/itkgroup.py new file mode 100755 index 00000000000..208142828d0 --- /dev/null +++ b/Utilities/Doxygen/itkgroup.py @@ -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 ") + sys.exit(1) + + filename = sys.argv[1] + with open(filename) as file: + for line in file: + process_line(line)