-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_fun_name.py
46 lines (41 loc) · 1.74 KB
/
check_fun_name.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
# | Copyright 2017 Karlsruhe Institute of Technology
# |
# | 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
# |
# | http://www.apache.org/licenses/LICENSE-2.0
# |
# | 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.
import logging, get_file_list
from grid_control.utils.file_tools import SafeFile
from python_compat import any, imap
def main():
for (fn, fnrel) in get_file_list.get_file_list(show_type_list=['py'],
show_external=True, show_testsuite=False):
ident_map = {}
blacklist = ['python_compat.py', '/htcondor_wms/', 'xmpp']
if any(imap(lambda name: name in fn, blacklist)):
continue
for line in SafeFile(fn).iter_close():
ident = line.replace(line.lstrip(), '')
ident_level = ident.count('\t')
line = line.strip()
if line.startswith('def ') or line.startswith('class '):
ident_map[ident_level] = line.split(':')[0]
for other_ident_level in list(ident_map):
if other_ident_level > ident_level:
ident_map.pop(other_ident_level)
parent_ident = ident_level - 1
while (parent_ident not in ident_map) and (parent_ident > 0):
parent_ident = parent_ident - 1
parent = ident_map.get(parent_ident, '')
if line.startswith('def ') and parent.startswith('def '):
if not line.startswith('def _'):
logging.warning('nested function missing prefix: %r %r', fnrel, ident_map)
if __name__ == '__main__':
main()