5

Does anybody know of a tool to handle module dependencies + deployment in Python?

Details: By handle, I mean:

  • list,
  • keep track of and
  • bundle up a zip/installable file for me.
  • Make it trivial to redeploy on another system (ie: includes all modules at the correct version in a deploy file, and does not have to go somewhere to get them *).
  • Alerts me if I am about to do something which changes the environment.
  • It must follow module dependencies all the way, not just one level deep.
  • Plus some stuff I probably haven't thought of.

  • I'm not talking about Virtualenv, Fabric, pip freeze** and (I don't think) Paver.

This evening I tried to count the modules that Pylons depends on. After a detour into Snakefood and Graphviz, the answer is A LOT. 100+ (and Snakefood did not get them all).

As I'm getting more and more into Python, handling this problem manually is starting to take up more of my time than I would like, and it's unreliable.

If it matters, I use Python 2.7 on Windows 7.

* I know this will introduce some artifacts.  
** Combining virtualenv and pip freeze goes some way to solving this, but it's still not what I am looking for. 
Dirk
  • 3,073
  • 4
  • 31
  • 36

2 Answers2

5

Setuptools plus pypi is made for that. The setuptools is an enhanced distutils, with which you can specify dependencies. For example, in the setup function:

install_requires = ['simplejson>=2.0,==dev'],

Will pull in that dependency when you use easy_install.

Keith
  • 42,110
  • 11
  • 57
  • 76
  • What I am looking for is not something that will pull in dependencies when they are listed, but something that will package them for me, list them etc. Also, it does not always work - installs sometimes fail, and for Windows you sometimes need the msi. Still, you are right that setuptools is worth another look. – Dirk May 23 '11 at 15:20
  • @dirk Ah, right. That is a bit of a problem on Windows. Most open-source platforms have a means to build from source and don't have a problem with install time dependency management. – Keith May 23 '11 at 18:05
2

Since you are on windows take a look at py2exe. Something of interest from the py2exe FAQ:

How does py2exe decide which modules you need?
To determine which modules should go in the final .exe file, py2exe 
does a recursive search of the script that you are packaging to find 
its dependencies and, in turn, all of their dependencies.

sateesh
  • 27,947
  • 7
  • 36
  • 45
  • Very interesting. I wonder if there is a way to get the output not as an exe. – Dirk May 23 '11 at 15:21
  • Doesn't distutils http://docs.python.org/distutils/index.html serve your need ? You can build on top of what distutils provides to add the checks you need. – sateesh May 23 '11 at 17:02
  • Partly, but not completely. I found this in the py2exe docs though: python -m py2exe.mf -d path/to/my_file.py – Dirk May 23 '11 at 17:37