forked from ioannis-vm/OpenSees_Model_Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocstrings.py
66 lines (56 loc) · 1.87 KB
/
docstrings.py
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
"""
This script was used to remove all type-hints from the docstrings,
since the type hints exist in the code itself and Sphinx can pick them
up just fine. If something is enclosed in parenthesis inside a
docstring, immediately followed by a colon symbol, the code picks it
up.
"""
import os
import glob
import re
import numpy as np
def list_directories(root_dir):
res = []
for path, directories, _ in os.walk(root_dir):
for directory in directories:
res.append(os.path.join(path, directory))
return res
def list_python_files(dir):
res = []
for file in glob.glob(os.path.join(dir, '*.py')):
res.append(file)
return res
res = list_directories('src/osmg/')
not_backup = []
for thing in res:
if '.~' not in thing:
not_backup.append(thing)
not_backup.append('src/osmg')
# find all available filenames
files = {}
for thing in not_backup:
files[thing] = list_python_files(thing)
pattern = '\(*?\):' # type: ignore (this is so silly)
for module in files:
for path in files[module]:
with open(path, 'r', encoding='utf-8') as f:
contents = f.read()
if contents.startswith('"""'):
contents = '\n\n'+contents
contents_spl = np.array(contents.split('"""'))
contents_docstr = contents_spl[1::2]
for thing in contents_docstr:
lines = thing.split('\n')
for line in lines:
if '>>>' in line:
continue
if '...' in line:
continue
if '(most recent call last):' in line:
continue
match = re.search(pattern, line)
if match:
print('~~~')
print(line)
print('~~~')
print()