python - How can I identify the methods touched in HG changset? -


i way list of python methods touched between 2 mercurial changesets. there tool available this?

clarification based on comment:

i not looking 100% comprehensive. if tool identify each line changed in diff, method/class falls within, great.

i'm not aware of tools should doable custom solution depends on how complex solution you'd go for.

here's 2 possible solutions without detail: solution 1: diff between changesets , make sure hg diff command has lots of context in (the -u option), have simple script searches changes lines nearest function definition (a simple regex should do)

solution 2: parse diff above change line numbers (for example @@ -7,6 +7,10 @@ ) , write introspection tool tells function line comes from. can quite complex here's simple approximation:

    import sys      if __name__ == '__main__':         import foo         f_list = []         in_line = int(sys.argv[1])         k,v in sys.modules['foo'].__dict__.iteritems():             if k.startswith('__'):                 continue             if hasattr(v, '__call__'): #we have function                 f_list.append((v.__name__, v.__code__.co_firstlineno))         #sort our function list according starting line of each function (if needed)         last_fn = none         f_name, f_line in f_list:             if f_line >= in_line:                 break;             else:                 last_fn = f_name          if last_fn:                 print 'line {} in function {}'.format(in_line, last_fn) 

here i'm looking in module foo can changed whatever module need. i'm not going paste contents of module, you'll have trust me works :)

    ./intro.py 7      line 7 in function do_foo      ./intro.py 13     line 13 in function do_blah 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -