desperately in need of a tool

Y

yagyala

Hi.

I recently started working for a company that has just implemented its
first set of software standards. So far, so good. Here's the problem:
one of those standards is that the comments for each routine must
indicate every other routine that it calls. As I try to keep my
routines small, and factor out methods alot, this can lead to an
enormous ammount of extra typing. I really, really, really don't want
to do this by hand. Does anyone know of a tool that could do this for
me, or at least a tool that can tell what other routines a given
routine calls that I could program against? (Preferably something that
works under pydev, but I'm not going to be choosy.)

I'm sure some will wonder about the reasoning of this standard. The
company primarily has experience writing scientific alogorythms which
can get rather long. It makes a bit more sense to document all
routines called for a very long routine, but for short routines that
primarily call other routines, as most mine do, well....

Thanks.
 
C

Chris Mellon

Hi.

I recently started working for a company that has just implemented its
first set of software standards. So far, so good. Here's the problem:
one of those standards is that the comments for each routine must
indicate every other routine that it calls. As I try to keep my
routines small, and factor out methods alot, this can lead to an
enormous ammount of extra typing. I really, really, really don't want
to do this by hand. Does anyone know of a tool that could do this for
me, or at least a tool that can tell what other routines a given
routine calls that I could program against? (Preferably something that
works under pydev, but I'm not going to be choosy.)

I'm sure some will wonder about the reasoning of this standard. The
company primarily has experience writing scientific alogorythms which
can get rather long. It makes a bit more sense to document all
routines called for a very long routine, but for short routines that
primarily call other routines, as most mine do, well....

Thanks.

To the extent that it's useful to do this at all in Python (dynamic
method invocation is impossible determine, and polymorphic method
invocations you can't pinpoint), pycallgraph
(http://pycallgraph.slowchop.com/) can do this.
 
A

A.T.Hofkamp

Hi.

one of those standards is that the comments for each routine must
indicate every other routine that it calls. As I try to keep my
to do this by hand. Does anyone know of a tool that could do this for
me, or at least a tool that can tell what other routines a given
routine calls that I could program against? (Preferably something that
works under pydev, but I'm not going to be choosy.)

Wouldn't a regular expression be enough here?

Something like

# x.py
import re, sys

fcallpat = re.compile(r'\w+\(')

data = sys.stdin.read()
for match in fcallpat.findall(data):
print match



$ python x.py < x.py
compile(
read(
findall(

You may want to have a wider matching criterium than \w+


Albert
 
B

Bruno Desthuilliers

yagyala a écrit :
Hi.

I recently started working for a company that has just implemented its
first set of software standards. So far, so good. Here's the problem:
one of those standards is that the comments for each routine must
indicate every other routine that it calls.

May I suggest that this is a totally *stupid* (and FWIW, totally
impossible to apply) "standard" ?

Consider the following code, which is totally dumb but quite close to
real-life code in it's design (use of polymorphic dispatch, HOFs and
anonymous functions...) :

def some_func(obj, callback):
return callback(obj.method())

class One(object):
def method(self):
return 42

class Two(object):
def __init__(self, val):
self.val = val
def method(self):
return self.val / 3


def cb_one(val):
return val + 2

def cb_two(val):
return val * 3 + 42


arg_pairs = [(One(), cb_one),
(One(), cb_two),
(Two(33), cb_one),
(Two(99), cb_two)
(One(), lambda x: x ** 2]

for obj, cb in arg_pairs:
print some_func(obj, cb)

How are you going to list the functions called by some_func ???

(snip)
I'm sure some will wonder about the reasoning of this standard.

Indeed !-)
The
company primarily has experience writing scientific alogorythms which
can get rather long. It makes a bit more sense to document all
routines called for a very long routine, but for short routines that
primarily call other routines, as most mine do, well....

Show the above code to your PHB and ask him to explain how you're going
to apply the "standard"...
 
J

John J. Lee

yagyala said:
I recently started working for a company that has just implemented its
first set of software standards. So far, so good. Here's the problem:
one of those standards is that the comments for each routine must
indicate every other routine that it calls. As I try to keep my

Oh dear.

I'm sure some will wonder about the reasoning of this standard. The
company primarily has experience writing scientific alogorythms which
can get rather long. It makes a bit more sense to document all
routines called for a very long routine, but for short routines that
primarily call other routines, as most mine do, well....

Perhaps you can reason with them. Perhaps suggest the possibility
that parts of the standard be waived or modified for the area of work
you're involved with (rather than asking them for special personal
dispensation, or asking them to throw away or rewrite their
standards).


John
 
J

John J. Lee

yagyala said:
I recently started working for a company that has just implemented its
first set of software standards. So far, so good. Here's the problem:
one of those standards is that the comments for each routine must
indicate every other routine that it calls. As I try to keep my
routines small, and factor out methods alot, this can lead to an
enormous ammount of extra typing. I really, really, really don't want
to do this by hand. Does anyone know of a tool that could do this for
me, or at least a tool that can tell what other routines a given
routine calls that I could program against? (Preferably something that
works under pydev, but I'm not going to be choosy.)

import tokenize

for token in tokenize.generate_tokens(open("foo.py")):
print token


Note module token, also. Module inspect may also be of use:

http://docs.python.org/lib/inspect-source.html


Also, Python 2.5 introduced a new AST, which I haven't had occasion to
use yet (not even certain whether it ended up getting exposed it to
Python, or just staying on the C level...)


Possibly you could even persuade some existing source code analysis
tool to do exactly the job you want for you -- but it's probably much
easier just to write what you need yourself.


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,270
Messages
2,571,347
Members
48,032
Latest member
SantoBotto

Latest Threads

Top