mirror of
https://github.com/openmm/openmm
synced 2026-06-03 06:39:48 +09:00
* Replace C++ code examples in Python API docs * Use newer Python for building docs * Remove sphinx version pin * Add Python versions of code examples * Minor edit * Add Python version of one more code example
29 lines
919 B
Python
29 lines
919 B
Python
import os
|
|
import re
|
|
import sys
|
|
|
|
def replace_code(match):
|
|
lines = match.group(1).split('\n')
|
|
for i, line in enumerate(list(lines)):
|
|
if line.startswith('*'):
|
|
lines[i] = line[1:]
|
|
return f"\n* .. code-block:: c++\n* {'\n* '.join(lines)}"
|
|
|
|
|
|
def process_file(file):
|
|
"""Edit docstrings in an XML file to remove the Python versions of code examples,
|
|
and put the correct Sphinx directives around the C++ versions."""
|
|
with open(file) as input:
|
|
content = input.read()
|
|
processed = re.sub(r'<c\+\+>((.|\n)*?)</c\+\+>', replace_code, content)
|
|
processed = re.sub(r'<python>((.|\n)*?)</python>', '', processed)
|
|
print(file, processed != content)
|
|
if processed != content:
|
|
with open(file, 'w') as output:
|
|
output.write(processed)
|
|
|
|
|
|
dir = sys.argv[1]
|
|
for file in os.listdir(dir):
|
|
process_file(os.path.join(dir, file))
|