views:

114

answers:

3

I tend to develop my apps in 'setup.py develop' -mode. I'd want the configuration to switch automagically on production mode when the program gets 'setup.py install'ed.

This can be done by poor hacks, like checking whether installation directory contains 'setup.py', but I wonder whether pkg_resources can do this for me somehow.

+4  A: 

Isn't it easier, and cleaner, to just set an environment variable on your development machine, and test for os.environ['development_mode'] (or a setting of your choice)?

Chris B.
+1: simpler is better.
S.Lott
Perhaps. Though it seems it wasn't neither tricky to get this info through pkg_resources.
Cheery
No, but it's still generally a bad idea to base behavior on the manner of installation. If you want to debug a particular piece of code which only runs outside of development mode, you have to edit the code or reinstall the package. With the environment setting, you just set the variable.
Chris B.
+5  A: 

Indeed, pkg_resources will do that:

dist = pkg_resources.get_distribution('your-app')
if dist.precedence == pkg_resources.DEVELOP_DIST:
    # package is in development mode
    ...
dF
You learn something new every day. :)
Christian Witts
A: 

Another option is to use virtualenv. Then your development environment could be identical to your production environment. Setuptools is a pretty heavy thing to depend on, in my opinion.

Ali A