::dependencies tool::

July 12th, 2011 by hamish download the zooToolBox

I finally managed to package up the dependency tracking tool I blogged about ages ago.  If you want to take a squiz you can find it here.  Its kinda neat actually.  As you can see from the link to the tool – its a zip file.  I made this zip file using one of the features of the tool; the /package flag.  Because the tool knows all the dependencies of all the scripts in your tree, you can ask it to make a zip file containing all the dependencies for a given list of scripts.

So to make the zip file in the link above I ran this command:

pydeps /package pydeps.cmd

And that was it.  Simple eh?  Packaging isn’t terribly useful, but I figured I’ll most likely use this tool to generate future zooToolBox distributions.  I should be able to maintain a list of tools I want to include and pipe them into this command.  And it seemed like a useful thing for anyone who wants to distribute a neat tool without having to manually figure out what they need to include.

You may be wondering about the .cmd extension in the example above.  Well take a look at the zip file.  Basically .cmd files in windows are similar to shell scripts in *nix.  The tool will peek into a .cmd file to see if its a python script and if so, will include them in the dependency database.

So what else can you do with it?  The main features are the /i and the /d flags.  The /i flag will report all import dependencies for the given scripts.  By default it will report only immediate import dependencies, but you can pass it an depth integer as well.  For example if you wanted to know every single import dependency for a script (ie what the imported scripts import etc), you’d simply run this command:

pydeps /i 0 someScript.py

The /d flag will report scripts that are dependent on the ones you specify.  So just say you find some code you want to re-factor.  You can run this command:

pydeps /d 1 someScript.py

This command will report deep dependents for someScript.py.  By this I mean it will report every script that may possibly be using some part of someScript.py.  So for example, just say you import someScript into scriptA and then import scriptA into scriptB.  ScriptB will have access to code in someScript via its scriptA import right?  So now the pyDeps tool will report scriptA as an immediate dependent and scriptB as a deep dependent when run on someScript.

The other flag worth pointing out is the /tree flag.  This will print out a dependency tree for the given scripts.  This can be an interesting exercise – try running it on some of your tools.  I expect you’ll see some cross dependencies that you weren’t expecting.  It’d be kinda neat to do some big fat visualization graph of this…  I did think about this – in fact I figured if I bothered doing it, I’d just use maya’s hypergraph.  Build some nodes to reflect the scripts and connect em up.  If anyone ends up doing this – let me know!

Anyway, there are a few other flags – just run the tool without args to see the available flags.  Enjoy!

Share

This post is public domain

This entry was posted on Tuesday, July 12th, 2011 at 21:36 and is filed under main. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

  • http://www.jonasavrin.com Jonas Avrin

    I just wanna say, damn! Great stuff. *applause* I’d love to try it out soon!

  • Anonymous

    thanks Jonas!  try it out, let us know how it works.  Its been a great tool to me for refactoring and re-organising my code.  It’d be even MORE awesome if I could give it a particular class or function to track…  But python makes that essentially impossible.