开发者

How to get version of python dependencies/modules, including external applications called via subprocess.Popen?

I have a set of python scripts that I run frequently on different machines that depend on a few external libraries as well as some other applications spawned via subprocess.Popen.

As expected depending on the version of the installed modules and applications the output varies. To address this I would like to keep tra开发者_开发百科ck of which versions were in use at runtime.

In order to do this I've considered the following steps:

  1. Using modulefinder to collect dependencies.
  2. Try to call module.__version__, module.get_version() or other common ways to store version information on each collected module.
  3. Collect all calls to subprocess.Popen and try to get a version number by parsing the output with different arguments such as -version, -v, -?, -h, ...

Steps 2 and 3 could be greatly improved by the use of distribution specific (Debian in my case) tools such as dpkg to get versions of installed packages. The downside is that it becomes not only OS but also distribution specific, however I do realize that the initial approach is extremely inefficient and error-prone, if functional at all.

So my question is if there is any package out there to address this or if anyone has a better suggestion on how to implement it?


Two years passed and some new tools came into play.

To take care of point 1 and 2 there is now pip freeze specially when coupled with virtualenv.

For external applications I had to resource to the package manager (apt-file, dpkg, qlist, emerge,... depending on the system) on the system which included all the expected pitfalls.

I would still like to make a reference to Ross' answer as it produced the desired result. The disadvantage (from my point of view) is that it collected a lot more dependencies than strictly required.


Instead of directly investigating your dependencies in python, and if you are running in Linux/Unix, you can wrapper your program with memoize.py. memoize.py uses strace, or "system trace", to watch all system read and write commands that your program generates and then stores these dependencies to a file. memoize.py may also be use as a library, so you can use its functions internally within your program and get the dependencies in a python data structure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜