Skip to content

Commit

Permalink
Fix parameter names during docstring generation
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Jul 5, 2024
1 parent d4c6e98 commit b76a9b1
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 99 deletions.
37 changes: 37 additions & 0 deletions cmake/fix_docstrings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3

"""Fixes errors in Docstrings.hpp."""

import re
import sys


def main():
# sys.argv[1] should be the filepath of Docstrings.hpp
filename = sys.argv[1]

with open(filename) as f:
content = f.read()

# Convert parameter names from camel case to snake case
new_content = ""
extract_location = 0
for match in re.finditer(r"(?<=Parameter ``)(.*?)(?=``:)", content):
new_content += content[extract_location : match.start()]
param = match.group()
for i in range(len(param)):
# Replace uppercase letter preceded by lowercase letter with
# underscore and lowercase version of letter
if i > 0 and param[i - 1].islower() and param[i].isupper():
new_content += "_" + param[i].lower()
else:
new_content += param[i]
extract_location = match.end()
content = new_content + content[extract_location:]

with open(filename, mode="w") as f:
f.write(content)


if __name__ == "__main__":
main()
38 changes: 0 additions & 38 deletions cmake/fix_stubgen.py

This file was deleted.

4 changes: 4 additions & 0 deletions cmake/modules/Pybind11Mkdoc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ function(pybind11_mkdoc target headers)
${env_vars} ${Python3_EXECUTABLE} -m pybind11_mkdoc ${headers} -o
${CMAKE_CURRENT_SOURCE_DIR}/jormungandr/cpp/Docstrings.hpp
-I/usr/lib/clang/17/include ${target_dirs} ${eigen_dirs} -std=c++23
COMMAND
${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/fix_docstrings.py
${CMAKE_CURRENT_SOURCE_DIR}/jormungandr/cpp/Docstrings.hpp
DEPENDS ${headers}
USES_TERMINAL
)
Expand Down
4 changes: 0 additions & 4 deletions cmake/modules/Pybind11Stubgen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ function(pybind11_stubgen target)
'numpy.float64|numpy.ndarray|scipy.sparse.csc_matrix' --exit-code
$<TARGET_FILE_BASE_NAME:${target}> -o
$<TARGET_FILE_DIR:${target}>-stubs
COMMAND
${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/fix_stubgen.py
$<TARGET_FILE_DIR:${target}>-stubs
WORKING_DIRECTORY $<TARGET_FILE_DIR:${target}>
USES_TERMINAL
)
Expand Down
Loading

0 comments on commit b76a9b1

Please sign in to comment.