figure out whether python module is installed or in develop mode programmatically
Question
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.
Solution
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
...
OTHER TIPS
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)?
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.