Created
January 23, 2019 17:51
-
-
Save dustydecapod/29bc1af7c34eab9c507d94dadfa7bdea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import os, re, sys | |
func_regex = re.compile("((def)|(class)) (?P<funcname>[^\(]+)\([^\)]*") | |
for stdin_line in sys.stdin.read().splitlines(): | |
filename, _lineno, _ = stdin_line.split(":", 2) | |
lineno = int(_lineno) | |
fd = open(filename) | |
code = fd.read().splitlines() | |
line = code[lineno] | |
while not line.strip().startswith("def "): | |
lineno += 1 | |
line = code[lineno] | |
func_lineno = lineno | |
match = func_regex.match(line.strip()) | |
if not match: print(line) | |
path_parts = [match.groupdict()['funcname']] | |
if line.startswith(" "): | |
indent_level = len(line.split(" ")[:-1]) | |
while True: | |
lineno -= 1 | |
line = code[lineno] | |
line_indent_level = len(line.split(" ")[:-1]) | |
if line_indent_level >= indent_level: continue | |
match = func_regex.match(line.strip()) | |
if match: | |
path_parts = [match.groupdict()['funcname']] + path_parts | |
if not line.startswith(" "): break | |
module_path = filename.split("/")[1:-1] | |
path_parts = module_path + path_parts | |
print("%s:%s,%s" % (filename, func_lineno, '.'.join(path_parts))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment