automatically generating file dependency information from python tools

Peter Hansen peter at engcorp.com
Fri Apr 9 22:42:27 EDT 2004


Moosebumps wrote:

> Say you have a group of 20 programmers, and they're all writing python
> scripts that are simple data crunchers -- i.e. command line tools that read
> from one or more files and output one or more files.

Shall we read into this the implication that there is no
coding standard of any kind being used for these tools?  So
no hope of saying something as simple as "use constants for
all filenames, using the following conventions..."?

> I want to set up some sort of system that would automatically generate
> makefile type information from the source code of these tools.  Can anyone
> think of a good way of doing it?  You could make everyone call a special
> function that wraps the file() and detects whether they are opening the file
> for read or write.  

I think you've mixed up your two ideas in the above.  You don't really
mean "source code" here, do you?  You mean catching the information
dynamically from the running program, I think.  That is something
that is probably quite easy to do with Python.  For example, just
have everyone import a particular magic module that you create for
this purpose at the top of their scripts.  That module installs a
replacement open() (or file()) function in the builtins module, and
then any file that is opened for reading or writing can be noticed
and relevant notes about it recorded in your repository.

> The other thing I could think of is statically analyzing the source code -- 
> but what if the filenames are generated dynamically?  

As you've guessed, much harder to do.  Especially with a language
that is not statically typed... (dare I say? ;-)

-Peter



More information about the Python-list mailing list