forked from easybuilders/easybuild-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix_docs.py
More file actions
executable file
·71 lines (61 loc) · 2.28 KB
/
fix_docs.py
File metadata and controls
executable file
·71 lines (61 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
##
# Copyright 2016-2025 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en),
# the Hercules foundation (http://www.herculesstichting.be/in_English)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
# #
"""
Overhaul all @param and @author tags for rst API documentation
(@param x --> :param x: and @author --> :author:)
Authors:
* Caroline De Brouwer (Ghent University)
"""
import os
import re
import sys
from easybuild.tools.build_log import EasyBuildError
if not len(sys.argv) > 1:
raise EasyBuildError("Please include path to easybuild folder")
if not os.path.isdir(sys.argv[1]):
raise EasyBuildError("%s is not a directory" % sys.argv[1])
path = sys.argv[1]
py_files = []
for basename, _, filenames in os.walk(path):
for fn in filenames:
if os.path.splitext(fn)[1] == '.py':
py_files.append(os.path.join(basename, fn))
for tmp in py_files:
print("Processing %s" % tmp)
# exclude self
if os.path.basename(tmp) == os.path.basename(__file__):
continue
with open(tmp) as fh:
temp = "tmp_file.py"
with open(temp, 'w') as out:
for line in fh:
if "@author" in line:
out.write(re.sub(r"@author: (.*)", r":author: \1", line))
elif "@param" in line:
out.write(re.sub(r"@param ([^:]*):", r":param \1:", line))
else:
out.write(line)
os.rename(temp, tmp)